Home > Net >  Draw a line of c #
Draw a line of c #

Time:11-11

VS used to own chart controls, there is no vertical bar cursor, later want to do your own, without chart control, made a PICTUREBOX, then use the

Graphics g=pictureBox1. CreateGraphics ();
Pen blackPen=new Pen (Color Black, 2);//create the brush

Int x=0;
Int y=0;

for(int i=1; i<1000; I++)
{
G.D rawLine (blackPen, new Point (I - 1, (int) (0.5 * (I - 1))), new Point (I, (int) (0.5 * (I))));
}

Draw 1000 points, 300 milliseconds,
But the use of control CHART, as well as draw 1000 points, take only 10 milliseconds, the great god, can explain?

CodePudding user response:

Render to memory the image, and then control,

 
Var g=pictureBox1. CreateGraphics ();

Bitmap Bitmap=new Bitmap (pictureBox1. Width, pictureBox1. Height);
Var gb=Graphics FromImage (bitmap);
Gb. Clear (Color. White);
Pen blackPen=new Pen (Color Black, 2);
For (int I=0; I & lt; 1000; I++)
{
Gb. DrawLine (blackPen, new Point (I * 4, 0), new Point (I * 4, 300));
}
G.D rawImage (bitmap, new PointF (0, 0));

CodePudding user response:

Really fast, the test of 25 milliseconds, but still can't compare with CHART, it is only 10 milliseconds, thanks to the second floor
  •  Tags:  
  • C#
  • Related