我在Windows Mobile 6.5上的項目中掙扎。我正在編寫一個自定義控件,可以繪製用戶點擊自定義控件的位置。C#customcontrol OnMouseDown - 總是出錯Y位置
我面臨的問題是OnMouseDown(MouseEventArgs e)沒有返回正確的e.Y(Y位置的點擊位置)。任何人都請幫忙!我在這個問題上花了幾個小時,但仍然無法弄清楚什麼是錯的。 (我覺得我是在錯誤的方向)
這裏是應用程序的樣子:
當我試圖在WM6.5模擬器運行時,onmousedown事件(MouseEventArgs E)總是返回錯誤的Y位置(它返回Y位置減去一些值)。例如:我點擊控制中心進行第一次點擊,但顯然e.Y不在中心。
下面是代碼尖晶石:
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。爲什麼那個標籤? – 2011-12-14 17:23:54