简体   繁体   English

C#customcontrol OnMouseDown - Y位置总是出错

[英]C# customcontrol OnMouseDown - always get wrong Y position

I am struggling in a project on Windows Mobile 6.5. 我在Windows Mobile 6.5上的项目中苦苦挣扎。 I am writing a custom-controls that can plot lines of where the user has clicked on the custom-controls. 我正在编写一个自定义控件,可以绘制用户点击自定义控件的位置。

I am facing a problem that the OnMouseDown(MouseEventArgs e) is not returning correct eY (Y position of clicked location). 我遇到了一个问题,即OnMouseDown(MouseEventArgs e)无法返回正确的eY(单击位置的Y位置)。 Anyone please help! 有人请帮忙! I have spent few hours on this issue, but still cannot figure what's wrong. 我在这个问题上花了几个小时,但仍然无法弄清楚是什么问题。 (I think I am in the wrong direction) (我认为我走错了方向)

Here is what the application looks like: 这是应用程序的外观:

我的申请看起来像

When I tried to run in a WM6.5 emulator, the OnMouseDown(MouseEventArgs e) always return wrong Y position (It returns Y location minus some values). 当我尝试在WM6.5仿真器中运行时,OnMouseDown(MouseEventArgs e)总是返回错误的Y位置(它返回Y位置减去某些值)。 For example: I clicked on the center of the control for the first click, but obviously the eY is not at the center. 例如:我单击控件的中心是第一次单击,但是显然eY不在中心。

显然,e.Y不在中心位置

Here is the code spinet: 这是代码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++;
    }

Here is the source code of my custom-controls: Download here Thanks! 这是我的自定义控件的源代码: 在此下载谢谢!

This may sound crazy, and might even be better as a comment if it were not actually a possible solution: 这可能听起来很疯狂,如果它实际上不是一个可能的解决方案,甚至可能更好地作为评论:

Go into your system settings and configure your screen. 进入系统设置并配置屏幕。

Settings > System Tab > Screen > Align Screen 设置>系统选项卡>屏幕>对齐屏幕

系统设置屏幕设置

The Y value is most likely the screen coordinates, not the coordinates within the rectangle you are drawing in. I think you'll need to take into account the taskbar height. Y值很可能是屏幕坐标,而不是您正在绘制的矩形内的坐标。我认为您需要考虑任务栏的高度。

It's been a long time since I worked with WM, but I remember having similar issues when capturing points via MouseEventArgs. 自从我使用WM以来已经很长时间了,但我记得在通过MouseEventArgs捕获点时遇到类似的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM