/// <summary> |
/// 动态添加图像控件 |
/// </summary> |
private void AddPicControl() |
{ |
PictureBox pic = new PictureBox(); |
//设置图像相关属性及事件 |
pic.Name = string .Format( "pic{0}" , this .pnlTest.Controls.Count); //Name属性 |
pic.Width = 200; //Size-Width |
pic.Height = 200; //Size-Height |
pic.BorderStyle = BorderStyle.FixedSingle; //边框样式:单线边 |
pic.SizeMode = PictureBoxSizeMode.Zoom; //设置图像SizeMode=Zoom |
pic.Cursor = Cursors.Hand; //鼠标悬浮样式:小手 |
pic.Click += this .picBox_Click; //事件:单击控件 |
pic.DoubleClick += this .picBox_DoubleClick; //事件:双击控件 |
this .AddCheckBoxControlIntoPicBox(pic); //添加复选框 |
pic.ContextMenuStrip = this .cmsTest; //绑定右键菜单 |
//向容器中添加一个图像控件 |
this .pnlTest.Controls.Add(pic); |
} |
/// <summary> |
/// 在图像控件中添加CheckBox控件 |
/// </summary> |
private void AddCheckBoxControlIntoPicBox(PictureBox p_PicBox) |
{ |
CheckBox chkBox = new CheckBox(); |
chkBox.Name = string .Format( "chkBoxOf{0}" , p_PicBox.Name); |
chkBox.Text = string .Empty; |
chkBox.AutoSize = true ; //若不设置此属性,会出现比较多的白色边框,比较难看 |
chkBox.Location = new System.Drawing.Point(-1, -1); //相对位置:左上角 |
p_PicBox.Controls.Add(chkBox); |
} |
by: 发表于:2018-01-24 09:45:29 顶(0) | 踩(0) 回复
??
回复评论