1

我在Windows Mobile 6.5上的項目中掙扎。我正在編寫一個自定義控件,可以繪製用戶點擊自定義控件的位置。C#customcontrol OnMouseDown - 總是出錯Y位置

我面臨的問題是OnMouseDown(MouseEventArgs e)沒有返回正確的e.Y(Y位置的點擊位置)。任何人都請幫忙!我在這個問題上花了幾個小時,但仍然無法弄清楚什麼是錯的。 (我覺得我是在錯誤的方向)

這裏是應用程序的樣子:

My application looks like

當我試圖在WM6.5模擬器運行時,onmousedown事件(MouseEventArgs E)總是返回錯誤的Y位置(它返回Y位置減去一些值)。例如:我點擊控制中心進行第一次點擊,但顯然e.Y不在中心。

obviously the e.Y is not at center

下面是代碼尖晶石:

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 謝謝!

+0

我敢肯定這無關使用ColdFusion。爲什麼那個標籤? – 2011-12-14 17:23:54

回答

2

這聽起來很瘋狂,甚至可能是一個更好的意見,如果它實際上不是一個可行的解決方案:

進入您的系統設置和配置您的屏幕。

設置>系統標籤>屏幕>對齊屏幕

System SettingsScreen Settings

+0

我覺得除此之外我什麼也做不了。實際上,我發現與真實設備相同的問題。 – 2011-12-16 04:25:54

1

Y值最有可能是屏幕座標,而不是您正在繪製的矩形內的座標。我認爲您需要考慮任務欄高度。

自從我與WM合作已經很長時間了,但我記得在通過MouseEventArgs捕獲點時遇到了類似的問題。

+0

感謝您的回覆,我已設置this.WindowState = System.Windows.Forms.FormWindowState.Maximized爲了隱藏任務欄。但e.Y仍然不正確。 – 2011-12-15 04:02:25