After a fair amount more work, I’m now happy with what I’ve produced, it’ll help me enormously, I hope, when I am doing blog posts. That’s what I’ve done it for.
As an update from the last post what I’ve done is :-
Added a tooltip – so when you hover over an image it shows you the full filename
Added a double click ability – by default this will copy the name of the file to the clipboard
Added a menu option to swap the double click ability – instead of the filename it’ll copy the actual image from the picture box to the clipboard (so you can paste it into a suitable app)
In more detail
Inside the AddPictureBox function I now have :-
PictureBox pbox1 = new PictureBox();
pbox1.Location = new Point(xcoord, ycoord);
pbox1.Size = new System.Drawing.Size(imagewidth, imageheight);
pbox1.ImageLocation = file;
pbox1.SizeMode = PictureBoxSizeMode.StretchImage;
pbox1.BorderStyle = BorderStyle.FixedSingle;
pbox1.DoubleClick += new System.EventHandler(this.pbox1Double_Click);
// Above we added our own double click event handler for this picture box
toolTip1.SetToolTip(pbox1, file); // when we hover over we get the filename
This works by just dragging and dropping a tooltip control from the toolbox on to the form. Above, the line toolTip1.SetToolTip(pbox1, file) sets the tooltip for this control to be the filename.
Also in the above function you can see I added an event handler to the doubleclick event which calls this.pbox1Double_Click, which is this :
private void pbox1Double_Click(object sender, System.EventArgs e)
// Add the filename of the picture to the clipboard
PictureBox pboxtemp = (PictureBox)sender;
That’s the bit of code which copies either the filename or the image to the clipboard.
Change DoubleClick Behaviour:
I declare CopyName at the top of the class as a boolean, and the default value is true. So by default, double clicking on image will copy the filename.
I’ve added a new menu item which does the following on the click event:
var mi = (ToolStripMenuItem)sender;
if (mi.Checked == true)
CopyName = true;
CopyName = false;
Interestingly the actual ticking and unticking is handled by the control automatically. I spent ages trying to flip the state of the item on the menu line, to discover it does it for you !
I updated things and have a Change Directory, and a Refresh menu item.
Change Directory allows you to switch to a different folder
private void changePathToolStripMenuItem_Click(object sender, EventArgs e)
// Need to bring up a folder choose dialog, and set PathToScan afterwards
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
// Set the help text description for the FolderBrowserDialog.
"Select the directory that you want to use as the default.";
// Do not allow the user to create new files via the FolderBrowserDialog.
this.folderBrowserDialog1.ShowNewFolderButton = false;
this.folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer;
DialogResult result = folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK)
PathToScan = folderBrowserDialog1.SelectedPath;
Refresh clears just the picturebox controls off the form – otherwise all the menus disappear too!:
private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
//Remove all the current picturebox controls
for (int i = this.Controls.Count - 1; i >= 0; i--)
var t = this.Controls[i];
if (t.GetType().ToString() == "System.Windows.Forms.PictureBox")
There are still some things that I’d like to do to the app, but for now, this is getting parked as a SUCCESS.
Look out for the next project, which will cover hidden messages – and a surprise.
Time Spent So Far : 180 minutes