![](/img/trans.png)
[英]ASP.Net C# (Get A Color (RED) Pixel Position In An Image (PNG)) Returns Wrong X, Y Co-oridinates
[英]C# customcontrol OnMouseDown - always get wrong Y position
我在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++;
}
這是我的自定義控件的源代碼: 在此下載謝謝!
這可能聽起來很瘋狂,如果它實際上不是一個可能的解決方案,甚至可能更好地作為評論:
進入系統設置並配置屏幕。
設置>系統選項卡>屏幕>對齊屏幕
Y值很可能是屏幕坐標,而不是您正在繪制的矩形內的坐標。我認為您需要考慮任務欄的高度。
自從我使用WM以來已經很長時間了,但我記得在通過MouseEventArgs捕獲點時遇到類似的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.