1

我在 Windows Mobile 6.5 上的一个项目中苦苦挣扎。我正在编写一个自定义控件,可以绘制用户单击自定义控件的位置的线条。

我面临的问题是 OnMouseDown(MouseEventArgs e) 没有返回正确的 eY(单击位置的 Y 位置)。任何人请帮忙!我在这个问题上花了几个小时,但仍然无法弄清楚出了什么问题。(我认为我走错了方向)

这是应用程序的外观:

我的应用程序看起来像

当我尝试在 WM6.5 模拟器中运行时,OnMouseDown(MouseEventArgs e) 总是返回错误的 Y 位置(它返回 Y 位置减去一些值)。例如:我第一次单击时点击了控件的中心,但显然 eY 不在中心。

显然 EY 不在中心

这是代码spinet:

protected override void OnPaint(PaintEventArgs pe)
    {

        Graphics g = pe.Graphics;

        Pen pen_black = new Pen(Color.Black);
        g.DrawLine(pen_black, 0, 0, this.Width, 0);
        g.DrawLine(pen_black, 0, this.Height - 1, this.Width, this.Height - 1);
        g.DrawLine(pen_black, 0, 0, 0, this.Height);
        g.DrawLine(pen_black, this.Width - 1, 0, this.Width - 1, this.Height);

        // draw center cross
        g.DrawLine(pen_black, this.Width / 2, this.Height / 2 + 10, this.Width / 2, this.Height / 2 - 10);
        g.DrawLine(pen_black, this.Width / 2 + 10, this.Height / 2, this.Width / 2 - 10, this.Height / 2);


        // draw lines between all mouse down point
        if (pointCount > 0)
        {
            Pen pen_red = new Pen(Color.Red);

            for (int i = 0; i < pointCount - 1; i++)
            {
                g.DrawLine(pen_red, lineList[i].X, lineList[i].Y, lineList[i + 1].X, lineList[i + 1].Y);
            }
        }

            base.OnPaint(pe);
    }

    protected override void OnMouseDown(MouseEventArgs e)
    {
        // Put the last point to array            
        lineList[pointCount] = new Point(e.X, e.Y);

        pointCount++;
    }

这是我的自定义控件的源代码: 在此处下载 谢谢!

4

2 回答 2

2

这可能听起来很疯狂,如果它实际上不是一个可能的解决方案,甚至可能作为评论更好:

进入您的系统设置并配置您的屏幕。

设置 > 系统选项卡 > 屏幕 > 对齐屏幕

系统设置 屏幕设置

于 2011-12-15T16:13:27.753 回答
1

Y 值很可能是屏幕坐标,而不是您正在绘制的矩形内的坐标。我认为您需要考虑任务栏的高度。

自从我使用 WM 以来已经有很长时间了,但我记得在通过 MouseEventArgs 捕获点时遇到了类似的问题。

于 2011-12-15T00:35:17.597 回答