C# 用于绘制图像的鼠标位置

C# 用于绘制图像的鼠标位置,c#,cursor,panel,draw,point,C#,Cursor,Panel,Draw,Point,这是我的项目界面的代码,但当我移动鼠标时,我无法确定鼠标的位置!当我在屏幕上画图像时,它没有画出正确的位置 public partial class Form1 : Form { int _countRouter = 0; Point[] _posiRouter = new Point[100]; readonly Image _imgRouter = Image.FromFile(@"C:\Router2.png"); public Form1() {

这是我的项目界面的代码,但当我移动鼠标时,我无法确定鼠标的位置!当我在屏幕上画图像时,它没有画出正确的位置

public partial class Form1 : Form
{
    int _countRouter = 0;
    Point[] _posiRouter = new Point[100];
    readonly Image _imgRouter = Image.FromFile(@"C:\Router2.png");
    public Form1()
    {
        InitializeComponent();
    }

    private void btnRouter_MouseUp(object sender, MouseEventArgs e)
    {
        //panelMain.Cursor = new Cursor(Cursor.Current.Handle);

        //Point x = Cursor.Position;
        Point x = new Point(e.X, e.Y);
        if ((x.X > 10 || x.X < 660) && (x.Y > 30 || x.Y < 350))
        {
            _posiRouter[_countRouter].X = x.X;// -_imgRouter.Width;
            _posiRouter[_countRouter].Y = x.Y;// -_imgRouter.Height;
            _countRouter++;
        }
        this.panelOption.Invalidate();
        this.panelMain.Invalidate();
    }

    private void panelMain_Paint(object sender, PaintEventArgs e)
    {
        Graphics g = e.Graphics;
        g.FillRectangle(Brushes.White,  
                        new Rectangle ( 0, 0, this.ClientRectangle.Width , 
                                        this.ClientRectangle.Height));

        for (int x = 0; x < _countRouter; x++)
        {
            g.DrawImage(_imgRouter, _posiRouter[x]);

        }
    }
// ... ?
}
公共部分类表单1:表单
{
int _countRouter=0;
点[]_posiRouter=新点[100];
只读图像\u imgRouter=Image.FromFile(@“C:\Router2.png”);
公共表格1()
{
初始化组件();
}
私有无效btnRouter_MouseUp(对象发送方,MouseEventArgs e)
{
//panelMain.Cursor=新光标(Cursor.Current.Handle);
//点x=光标位置;
点x=新点(e.x,e.Y);
如果((x.x>10|x.x<660)和&(x.Y>30|x.Y<350))
{
_posiRouter[\u countRouter].X=X.X;/-\u imgRouter.Width;
_posiRouter[\u countRouter].Y=x.Y;/-\u imgRouter.Height;
_countRouter++;
}
此.panelOption.Invalidate()无效;
this.panelMain.Invalidate();
}
私有void panelMain_Paint(对象发送器,PaintEventArgs e)
{
图形g=e.图形;
g、 圆角矩形(笔刷。白色,
新矩形(0,0,this.ClientRectangle.Width,
这个.ClientRectangle.Height);
对于(int x=0;x<\u countRouter;x++)
{
g、 DrawImage(_imgRouter,_posiRouter[x]);
}
}
// ... ?
}
来自:

鼠标坐标因引发的事件而异。例如,在处理Control.MouseMove事件时,鼠标坐标值相对于引发事件的控件的坐标。与拖放操作相关的某些事件具有与窗体原点或屏幕原点相关联的鼠标坐标值


看看那里,试着通过放置调试点
pointx=新点(e.x,e.Y)来找出鼠标的位置查看您得到了什么。

不确定您的要求是什么。。。绘图,单击时放置某些内容。。。请仔细阅读我的代码!:)我确实。。。还是不确定。。。你想画一条线,比如说100分吗?不!我试着把一个按钮从一个面板放到另一个面板上!但它的位置不对!:)你有更新吗?