splitContainer1_Panel1
splitContainer2_Panel1
splitContainer1_Panel2
I want to be able to draw 2 lines - 1 vertical and 1 horizontal in this panel - making a crosshair.
I have tried using a new cursor like this:
Expand|Select|Wrap|Line Numbers
- private void splitContainer2_Panel1_MouseMove(object sender, MouseEventArgs e)
- {
- textBoxCoordenadas.Text = ("X = " + e.X.ToString() + "m ; Y = " + e.Y.ToString() + "m");
- if (CrossHaircheckBox1.Checked == true)
- {
- splitContainer3.Panel1.Cursor = crossCursor(e);
- }
- else
- {
- splitContainer3.Panel1.Cursor = Cursors.Arrow;
- }
- Thw function that defines the cursor is the following:
- private Cursor crossCursor(MouseEventArgs e)
- {
- //buscar a posição do cursor
- //Panel panel = new System.Windows.Forms.Panel();
- //Point point = panel.PointToClient(Cursor.Position);
- //vai buscar o tamanho da picturebox
- int[] tamanho =
- int x = splitContainer1.Panel1.ClientSize.Height;
- int y = splitContainer1.Panel1.ClientSize.Height
- //inicio da caneta tipo com a cor preta
- Pen pen = new Pen(Color.Black);
- //Inicia a box de desenho
- var pic = new Bitmap(x, y);
- Graphics gr = Graphics.FromImage(pic);
- //Desenha o crosshair (linhas principais)
- var pathX = new GraphicsPath();
- var pathY = new GraphicsPath();
- pathX.AddLine(0, y / 2, x, y / 2);
- pathY.AddLine(x / 2, 0, x / 2, y);
- gr.DrawPath(pen, pathX);
- gr.DrawPath(pen, pathY);
- //Desenha o crosshair (quadrado central)
- int tc = 5;//tamanho do crosshair
- var pathX2 = new GraphicsPath();
- pathX2.AddLine(x / 2 - tc, y / 2 + tc, x / 2 + tc, y / 2 + tc);
- pathX2.AddLine(x / 2 + tc, y / 2 + tc, x / 2 + tc, y / 2 - tc);
- pathX2.AddLine(x / 2 + tc, y / 2 - tc, x / 2 - tc, y / 2 - tc);
- pathX2.AddLine(x / 2 - tc, y / 2 - tc, x / 2 - tc, y / 2 + tc);
- gr.DrawPath(pen, pathX2);
- //aplica o bitmap e cria a imagem (pointer)
- IntPtr ptr = pic.GetHicon();
- var c = new Cursor(ptr);
- return c;
- }
1 - The cursor doesnt update the lines so that when i move my mouse the lines dont end at the panel limits;
2 - The cursos removes performance. The way i mesure this is by printing the mouse coord to a textbox and i can see it's very slow.
Thoughts anyone?