Hi,

I have a dynamic picturebox created at run time that loads an image and I want this picturebox to be clickable and open a web page.

Here is the code that creates the picturebox in the formload section:-

void MainFormLoad(object sender, EventArgs e)
		{
			
PictureBox pb = new PictureBox();

pb.Location = new Point(100, 100);

pb.Size = new Size(75, 75);

pb.BorderStyle = BorderStyle.Fixed3D;

pb.ImageLocation = "http://www.example.com/image.jpg";

this.Controls.Add(pb);

pb.BringToFront();
		}

I have looked at various examples of this on the net but could not get anything to work.

I have tried,

pb.Click += System.Diagnostics.Process.Start("http://www.example.com");

but just get an error.

Regards..,

MT ;)

Recommended Answers

All 2 Replies

You can either make a new EventHandler or use a delegate.

This will work:

pb.Click += delegate(object s, EventArgs e2)
{
System.Diagnostics.Process.Start("http://www.example.com");
};

Thanks

That is exactly what I was looking for.

Many, many thanks..,

MT :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.