문제

I have a pictureBoxes that are being created at run time and I would like to be able to click on that box and go to a webpage after the program completes. How can I create a click event for something like this?

This is what I am thinking:

    PictureBox PB = new PictureBox();
                    PB.Name = "PB" + i.ToString();
                    PB.Location = new Point(51 * i, 331);
                    PB.Size = new Size(50, 50);
                    PB.ImageLocation = Sub1;
                    Controls.Add(PB);

    PB.Click +=new EventHandler(PB_Click); 


    protected void PB_Click(object sender, EventArgs e) 

{

MessageBox.Show("You clicked the mouse over the PictureBox"); 

}

Is this on the right track?

도움이 되었습니까?

해결책 2

enter image description hereAfter fooling around a little I figured it out and thought I would post my solution, maybe someone else could benefit. I decided to take the easy route and just open up the link using webrowser control on the form.

![private void FrmWeb_Btn_Click(object sender, EventArgs e)
        {


            PictureBox PB = new PictureBox();

            PB.ImageLocation =  "https://si0.twimg.com/profile_images/378800000038434114/f676cbea6f8500c9c15529e1d5e548c1_reasonably_small.jpeg";
            PB.Size = new Size(100, 100);
            Controls.Add(PB);

            PB.Click +=new EventHandler(PB_Click); 


        }

        protected void PB_Click(object sender, EventArgs e)
        {

            webBrowser1.Navigate("http://twit.tv/");

        }][2]

다른 팁

If you want open Internet explorer and navigate to the desired address automatically, use this:

Process.Start("iexplore.exe", "http://www.google.com");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top