Home > Net >  Ask questions about the drawing
Ask questions about the drawing

Time:09-26

Hello, everyone, I am a c # beginners, a DrawLine problems now,

1. I don't have any problem if the DrawLine directly, mainly as follows:
Foreach (var lines in marchingSquares. ContourData)
{
Foreach (var line in lines. The Value)
{
Int cur_startY=the Convert. ToInt32 (line. The startPoint. Y * length);
Int cur_startX=the Convert. ToInt32 (image. The Height - line. The startPoint. * X length);
Int cur_endY=the Convert. ToInt32 (line. The endPoint. Y * length);
Int cur_endX=the Convert. ToInt32 (image. The Height - line. The endPoint. * X length);
G.D rawLine (pen, cur_startY cur_startX, cur_endY, cur_endX);

}
}
2. But now in order to achieve the line editable, defines a control, the control of the drawLine, mainly as follows:
ListForeach (var lines in marchingSquares. ContourData)
{
Foreach (var line in lines. The Value)
{
Int cur_startY=the Convert. ToInt32 (line. The startPoint. Y * length);
Int cur_startX=the Convert. ToInt32 (image. The Height - line. The startPoint. * X length);
Int cur_endY=the Convert. ToInt32 (line. The endPoint. Y * length);
Int cur_endX=the Convert. ToInt32 (image. The Height - line. The endPoint. * X length);

LineExtList. Add (new Line_EXT (cur_startY cur_startX, cur_endY, cur_endX));
}
}
MouseDragCurveImpl=new MouseDragCurve (g, pen, lineExtList);
MouseDragCurveImpl. Location=new Point (0, 0);
MouseDragCurveImpl. The Dock=System. Windows. Forms. DockStyle. The Fill;
Enclosing contourMap. Controls. The Add (mouseDragCurveImpl);

LineExtList saved all the beginning and end of the line segment, MouseDragCurve class are defined as follows:
The class MouseDragCurve: Control
{
//client rectangle
A Rectangle clientRect;

//flag
Bool mouseDown=false;
Private Graphics g;
Private Pen Pen;
List# region Inits
Public MouseDragCurve (Graphics g, Pen Pen, List{
This. G=g;
This. Pen=pen;
Enclosing lineExtList=lineExtList;
Enclosing BackColor=Color. White;
Enclosing DoubleBuffered=true;//double buffer, avoid flashing
}


Void drawCurve ()
{

for(int i=0; i {
G.D rawLine (pen, lineExtList [I] startY, lineExtList [I] startX, lineExtList [I] endY, lineExtList [I] endX);
}
}


Protected override void OnPaint (PaintEventArgs e)
{
DrawCurve ();
}

After debugging OnPaint, drawCurve call arrived, why didn't figure display, please advise, thank you, be obliged!

CodePudding user response:

https://github.com/wangdeshui/paint.net
Have a look, can solve the problem of winform drawing

  •  Tags:  
  • C#
  • Related