【问题标题】:C# customcontrol OnMouseDown - always get wrong Y positionC# customcontrol OnMouseDown - 总是得到错误的 Y 位置
【发布时间】:2011-12-16 00:13:27
【问题描述】:

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

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

这是应用程序的外观:

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

这里是代码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++;
    }

这是我的自定义控件的源代码: Download here 谢谢!

【问题讨论】:

  • 我很确定这与 ColdFusion 无关。为什么是那个标签?

标签: c# compact-framework custom-controls windows-mobile-6.5 compact-framework2.0


【解决方案1】:

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

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

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

【讨论】:

  • 我想除了这个我什么都做不了。实际上,我在真机上发现了同样的问题。
【解决方案2】:

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

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

【讨论】:

  • 感谢您的回复,我已设置 this.WindowState = System.Windows.Forms.FormWindowState.Maximized 以隐藏任务栏。但 e.Y 仍然不正确。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-08-28
  • 1970-01-01
  • 2018-07-28
  • 1970-01-01
  • 2018-02-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多