gpt4 book ai didi

c# - 如何在图像框上添加标记?

转载 作者:太空宇宙 更新时间:2023-11-03 18:55:43 25 4
gpt4 key购买 nike

public Form1()
{
InitializeComponent();
this.imgRoom.Click += new EventHandler(this.pictureBox1_Click);
}

private void pictureBox1_Click(object sender, EventArgs e)
{
var label1 = new LabelControl();
label1.Location = MousePosition;
label1.BackColor = Color.Red;
label1.Parent = imgRoom;
label1.Text = "Point";
imgRoom.Controls.Add(label1);
}

enter image description here

当我在所附屏幕上看到的地方单击时,点出现在另一个地方。如何解决这个问题呢?

最佳答案

MousePosition 在屏幕坐标中。您需要将其转换为客户端坐标。

private void pictureBox1_Click(object sender, EventArgs e)
{
var label1 = new LabelControl();
label1.Location = imgRoom.PointToClient(MousePosition); // changed here.
label1.BackColor = Color.Red;
label1.Parent = imgRoom;
label1.Text = "Point";
imgRoom.Controls.Add(label1);
}

关于c# - 如何在图像框上添加标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45977013/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com