我在 Windows Mobile 6.5 上的一个项目中苦苦挣扎。我正在编写一个自定义控件,可以绘制用户单击自定义控件的位置的线条。
我面临的问题是 OnMouseDown(MouseEventArgs e) 没有返回正确的 eY(单击位置的 Y 位置)。任何人请帮忙!我在这个问题上花了几个小时,但仍然无法弄清楚出了什么问题。(我认为我走错了方向)
这是应用程序的外观:
当我尝试在 WM6.5 模拟器中运行时,OnMouseDown(MouseEventArgs e) 总是返回错误的 Y 位置(它返回 Y 位置减去一些值)。例如:我第一次单击时点击了控件的中心,但显然 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++;
}
这是我的自定义控件的源代码: 在此处下载 谢谢!