Home > Net >  Under the MouseMove event of the mouse with Graphics draw a rectangle
Under the MouseMove event of the mouse with Graphics draw a rectangle

Time:10-04

How to draw a rectangular box drawing out the solid rectangular




Public void StartGraphics (Point start Point, end)
{


Graphics g=Graphics. FromImage (PCB) Image);
Pen p=new Pen (Color. Red, 3);
Float width=end. X - start. X.
Float height=end. Y - start. Y;
G.D rawRectangle (p, start X, start, Y, width, height);
//g.D rawLine (p, start_point, new Point (end_point. X, start_point. Y));
//g.D rawLine (p, start_point, new Point (start_point. X, end_point. Y));
//g.D rawLine (p, end_point, new Point (end_point. X, start_point. Y));
//g.D rawLine (p, end_point, new Point (start_point. X, end_point. Y));

PCB. Invalidate ();


}

Private void Pcb_MouseEnter (object sender, EventArgs e)
{

PCB. The Cursor=your Cursors. The Cross;

}
Point start_point;//relative to the coordinates of PCB
Point end_point;//relative to the coordinates of PCB
Bool m_down=false;
Private void Pcb_MouseDown (object sender, MouseEventArgs e)
{

M_down=true;
Point pcb_top_point=new Point (0, PCB. Top);

Point fm_point=this. PointToClient (Control. MousePosition);
Start_point. Y=fm_point. - pcb_top_point. Y Y;//real mouse starting position is on the window the mouse position + PCB from the form. The distance of the top
Start_point. X=fm_point. X; No change//X

}

Private void Pcb_MouseUp (object sender, MouseEventArgs e)
{


Point pcb_top_point=new Point (0, PCB. Top);

Point fm_point=this. PointToClient (Control. MousePosition);
End_point. Y=fm_point. - pcb_top_point. Y Y;//real mouse starting position is on the window the mouse position + PCB from the form. The distance of the top
End_point. X=fm_point. X; No change//X

M_down=false;

}

Private void Pcb_Paint (object sender, PaintEventArgs e)
{

}

Private void Pcb_MouseMove (object sender, MouseEventArgs e)
{

If (m_down==false)//if off the left mouse button will give up halfway to draw
{
return;
}
The else
{
Point pcb_top_point=new Point (0, PCB. Top);

Point fm_point=this. PointToClient (Control. MousePosition);
End_point. Y=fm_point. - pcb_top_point. Y Y;//real mouse starting position is on the window the mouse position + PCB from the form. The distance of the top
End_point. X=fm_point. X; No change//X


StartGraphics (start_point end_point);

}

}

CodePudding user response:

DrawRectangle and FillRectangle difference

CodePudding user response:

reference 1st floor assky124 response:
the difference between DrawRectangle and FillRectangle

Not like that I know the difference between the two is the key under the MouseMove event graphics has been drawing to this

And I want to reach the purpose of the is
Can change with the mouse to drag

CodePudding user response:

Refresh the wrong!

CodePudding user response:

Onpaint method under the words and then determine the information of the mouse,
  •  Tags:  
  • C#
  • Related