c#,在panel1控件内添加pictureBox控件,请问点击pictureBox怎么取得针对panel1控件的坐标?
在panel1控件内添加pictureBox控件,鼠标在panel1控件内点击能获取到点击坐标值,点击panel1控件内的pictureBox却得到的是针对picture...
在panel1控件内添加pictureBox控件,鼠标在panel1控件内点击能获取到点击坐标值,点击panel1控件内的pictureBox却得到的是针对pictureBox的坐标,请问点击pictureBox怎么取得针对panel1控件的坐标?并在以点击为中心画个圆圈做标记,代码怎么写?谢谢,请高手指教!
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int x;
int y;
private void panel1_MouseClick(object sender, MouseEventArgs e)
{
Point p = e.Location;
x = e.X;
y = e.Y;
displaycoord();
}
public void displaycoord()
{
MessageBox.Show("x坐标:" + x + " y坐标:" + y);
} 展开
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int x;
int y;
private void panel1_MouseClick(object sender, MouseEventArgs e)
{
Point p = e.Location;
x = e.X;
y = e.Y;
displaycoord();
}
public void displaycoord()
{
MessageBox.Show("x坐标:" + x + " y坐标:" + y);
} 展开
展开全部
private void Form4_Load(object sender, EventArgs e) { //遍历panel1里的控件 foreach (Control c in panel1.Controls) { if (c is PictureBox) { PictureBox pic = c as PictureBox; pic.Click += new EventHandler(pic_Click);//添加点击事件 } } } void pic_Click(object sender, EventArgs e) { panel2.Controls.Clear();//清空panel2中的控件 PictureBox pic = sender as PictureBox; PictureBox pic2 = new PictureBox (); pic2.Image = pic.Image; pic2.SizeMode = pic.SizeMode; panel2.Controls.Add(pic2);//向panel2添加新建的PictureBox }
追问
问题没有解决
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询