Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

creating picturebox,button dynamically and load picture from click event of button

$
0
0

hai my friends

---------------------

I am creating some pictueboxes (3),buttons (3) in one function  

it is creating picture boxes,buttons ok loading picture also ok   .. I need

one event to write on click event of button to load picture from open dialogue and select file from any location

( button1 click and select should load picture to picturebox1,button2 click and select should load picture to picturebox2)

-----------------------------------------------------------------------------------------------------------------------------------------

privatevoidcreatecontrol(intcontrolcount)

        {

    PictureBox[] pctnames = newPictureBox[controlcount];  

Button[] btnname =newButton[controlcount]; 

for(intu = 0; u < pctnames.Count(); u++) 

 

            {

                pctnames[u] =

newPictureBox();

   

                btnname[u] =

newButton();

            }

 

intPCT = 0;

           

foreach(PictureBoxpctinpctnames)

            {

stringname ="image"+ PCT.ToString();

                pct.Name = name;

                pct.Location =

newPoint(600, (50) + PCT * 250);

                pct.Size =

newSize(200, 200);

                pct.ImageLocation =

"C:\\image"+ PCT +".jpg";

               

this.Controls.Add(pct);

                PCT++;

            }

           

intTXT = 0;

           

foreach(Buttonbtninbtnname)

            {

               

stringname ="btn"+ TXT.ToString();

                btn.Name = name;

                btn.Location =

newPoint(500, (50) + TXT * 250);

               

stringabc = name;

                btn.Click +=

newSystem.EventHandler(this.btnclick);

  

this.Controls.Add(btn);

                TXT++;

            }

        }

---------------------

it is creating btn0,btn1,btn3 , image0,image1,iamge3 etc

I need to write one event correspondingly to load picture from each button

-------------------------------------------

privatevoidbtnclick(objectsender,EventArgse)

        {

           

OpenFileDialogdlg =newOpenFileDialog();

             dlg.Title =

"Open bitmap or jpeg.";

            dlg.Filter =

"jpg files (*.jpg);*.JPG;*.* | bmp files (*.bmp); *.bmp";

           

if(dlg.ShowDialog() ==DialogResult.OK)

            {

               

//code here


            }

        }

-----------------------------------------

can anybody ahelp me   or gime me some code to create button,picrebox dynamicaaly and load picture from click event of button

regards

hotnthought


Viewing all articles
Browse latest Browse all 31927

Trending Articles