07-14-2011، 09:57 AM
فکر کنم تا الان بیشتر سوالهاتو جواب دادم اونهای هم که جواب ندادم وقت نکردم به زودی جوای میدم :P
به این روش میگن Create Control at Runtime
خوب event هم تو سورس زیر یه مثال برات گذاشته شده تا راحت بفهمی :-)
We are going to create a link control and an image control one next to each other. First we have to set which control we are going to create, so in the form class area place:
Now when you want to create the link and picturebox call this
You created a handler for the click event of the link button so you could now could this in:
If you wanted to create a list of controls you could use the panel control and set the autoscroll property to true so everytime another control is added with a larger top value the scrollbar would appear giving the user the impression of a list control. You can add controls to a panel control simply by putting
به این روش میگن Create Control at Runtime
خوب event هم تو سورس زیر یه مثال برات گذاشته شده تا راحت بفهمی :-)
We are going to create a link control and an image control one next to each other. First we have to set which control we are going to create, so in the form class area place:
کد:
private PictureBox PicBox;
private LinkLabel Blue;
کد:
//CREATES AN EVENT HANDLER FOR THE LINK
EventHandler handler = new EventHandler(LinkLabel_Click);
//BUILD CONTROL LINK
Blue = new LinkLabel();
Blue.Text = "Link Control";
Blue.Location = new Point(30, 20);
Blue.Size = new Size(150, 20);
Blue.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline;
Blue.Click +=handler;
//CREATES AN NEW PICTUREBOX AND FILLS IT WITH A ICON
PicBox = new PictureBox();
PicBox.Image = Image.FromFile(@"c:\pic.ico");
PicBox.Top = 20;
PicBox.Width = 16;
PicBox.Height = 16;
PicBox.Left = 10;
//ADD CONTROLS
Controls.Add(PicBox);
Controls.Add(Blue);
کد:
private void LinkLabel_Click(object sender, EventArgs e)
{
//SPLITS THE DATA SO U CAN GET THE TEXT , U COULD PARSE IT THROUGH A CASE STATMENT FOR DIFFERENT SELECTIONS
string Data = Convert.ToString(sender);
string [] Split = Data.Split(new Char [] {':'});
MessageBox.Show("Link Clicked :" + Convert.ToString(Split[1]));
}
کد:
panel1.Controls.Add(PicBox);
panel1.Controls.Add(Blue);
گروه دور همی پارسی کدرز
https://t.me/joinchat/GxVRww3ykLynHFsdCvb7eg
https://t.me/joinchat/GxVRww3ykLynHFsdCvb7eg