通過我的代碼生成以下圖像中,如何檢查鼠標點擊而刀尖是C#
我想要的工具提示中顯示每個顏色值,而我的光標就可以了,當我點擊一個特定的放置在圖像上我想要一條虛線出現在圖像上。
RefBar.MouseMove += new MouseEventHandler(RefBar_MouseMove);
RefBar.MouseClick += new MouseEventHandler(RefBar_Click);
private void RefBar_MouseMove(object sender, MouseEventArgs e)
{
if (gotMapFirstTime == true)
{
Point LocalMousePosition = RefBar.PointToClient(System.Windows.Forms.Cursor.Position);
MousePointDisplay.SetToolTip(RefBar, WaferMap.getParamValueFromMousePointerXY(LocalMousePosition.X, LocalMousePosition.Y, 1, true).ToString());
}
}
private void RefBar_Click(object sender, EventArgs e)
{
byte[] bytes2;
Image image;
MouseEventArgs me = (MouseEventArgs)e;
Point coordinates = me.Location;
WaferMap.RefBarDashLines.Add(coordinates.Y);
int[] rfd = WaferMap.RefBarDashLines.ToArray();
if (rfd.Length > 2)
{
RefBar.Image.Dispose();
bytes2 = WaferMap.CreateMapReferenceBar(40, 580, 0, 0, 1);
WaferMap.RefBarDashLines = new List<int>();
WaferMap.UpperTrackBarLimit = 0.0;
WaferMap.LowerTrackBarLimit = 0.0;
pictureBox2.Image.Dispose();
bytes2 = WaferMap.CreateGridImage(120, 120, 9, 9, 5);
image = Image.FromFile(WaferMapImage);
pictureBox2.Image = image;
}
else if(rfd.Length == 2)
{
RefBar.Image.Dispose();
bytes2 = WaferMap.CreateMapReferenceBarByClick(40, 580, 0, 0, 1);
pictureBox2.Image.Dispose();
bytes2 = WaferMap.CreateGridImageFilteredByTrackBar(120, 120, 9, 9, 5);
image = Image.FromFile(WaferMapImage);
pictureBox2.Image = image;
}
else
{
RefBar.Image.Dispose();
bytes2 = WaferMap.CreateMapReferenceBarByClick(40, 580, 0, 0, 1);
}
image = Image.FromFile(ReferenceBarImage);
RefBar.Image = image;
MapLowerLimit.Text = coordinates.X.ToString() + " " + coordinates.Y.ToString();
}
類晶片圖,我們有這樣的:
public static double getParamValueFromMousePointerXY(int x, int y, int boxSize, bool isRefBarOrHistogram)
{
double returnVal = 0.0;
Point UL;
Point BR;
int cellX;
int invertY;
int cellY;
if (isRefBarOrHistogram)
{
invertY = -1*(y - RefBarLength);
return get_YCell_to_ParamValue(invertY, RefBarLength);
}
else
{
foreach (die dd in dieList)
{
cellX = dd.col;
cellY = dd.row;
UL = new Point(boxSize * (cellX + 2), boxSize * (cellY + 4));
BR = new Point((boxSize * (cellX + 2)) + boxSize, (boxSize * (cellY + 4)) + boxSize);
if ((UL.X < x && x <= BR.X) && (UL.Y < y && y <= BR.Y))
{
return dd.ParamValue;
}
}
}
return returnVal;
}
public struct die
{
public int row;
public int col;
public int site;
public string param;
public double ParamValue;
}
如果工具提示功能被註釋掉,鼠標點擊事件的代碼可以工作,但是當爲鼠標移動功能調用工具提示功能時,代碼在多次單擊鼠標點擊事件時不檢測或檢測到,我該如何糾正這個?
你在'SetToolTip'方法中做了更長時間的計算嗎? Click處理程序中的所有內容均在UI線程中執行。在此期間,不能執行其他UI操作。這可能會導致點擊無法識別。雖然沒有看到方法,但很難說。解決方案是加速該方法或在後臺執行其中的一部分。 – Sefe
我編輯了代碼供您參考,我無法粘貼整個代碼,因爲它是一個非常大的應用程序,我只想知道如何調用RefBar_Click函數,同時工具提示處於RefBar_MouseMove函數 – Adhil
tooltip命令非常快,並且無論光標位於圖像上,我都能得到正確的值 – Adhil