我想在picbox控件中,当鼠标点击某个位置时,添加label控件在该位置处。我的代码是: Point pos;
Label newLabel;
private static bool isAdd = false; //判断是否添加label
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (isAdd == true)
{
pos = Cursor.Position;
newLabel = new Label();
newLabel.Size = new System.Drawing.Size(11, 12);
newLabel.Name = "tt";
newLabel.BackColor = Color.Blue;
int px = pos.X;
int py = pos.Y;
newLabel.Location = new Point(px, py);
pictureBox1.Controls.Add(newLabel);
isAdd = false;
}
}实际运行中,控件添加在了离鼠标点击的位置很远的下方位置,请问是什么原因,有解决的办法不?
Label newLabel;
private static bool isAdd = false; //判断是否添加label
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (isAdd == true)
{
pos = Cursor.Position;
newLabel = new Label();
newLabel.Size = new System.Drawing.Size(11, 12);
newLabel.Name = "tt";
newLabel.BackColor = Color.Blue;
int px = pos.X;
int py = pos.Y;
newLabel.Location = new Point(px, py);
pictureBox1.Controls.Add(newLabel);
isAdd = false;
}
}实际运行中,控件添加在了离鼠标点击的位置很远的下方位置,请问是什么原因,有解决的办法不?
解决方案 »
- 急急急 c# 调用硬盘录像机上的视频,怎么调用?
- 如何实现listbox字符串截取字符串放入datagridview
- 求助!关于QQ2010密码框的输入
- LocationChanged未将对象引用设置到对象实例。
- C#:用Socket实现发送4个字节包头的短信,包体为XML格式
- remoting里面C# 与as3的数据类型对应
- c#用GDI+画曲线,请教
- 请问如何在Dataset中“添加”新的行,而不是覆盖?
- C# MDI的子窗体上不能使用组件
- 急! Framework升级后,visual c# 不能启动???
- Font newFont = Font.FromHdc()
- C#正则表达式查找替换问题
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
Label newLabel = new Label();
newLabel.Location = e.Location; pictureBox1.Controls.Add(newLabel);
}