CreateGraphics

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a DrawRectangle() method to draw a rectangle on my UserControl. The
OnPaint clear it. But in my reall application I cannot draw or update the
rectangle in OnPain. I have to draw or update it in my own method. What
shoudl I do?

Another question: how to draw just one pixel. The coe snippet do not work.
theGraphicsToDrawPoints.DrawRectangle(pen, xCoordinate, yCoordinate, 1, 1);
// Draw 2 by 2 sqare.
theGraphicsToDrawPoints.DrawRectangle(pen, xCoordinate, yCoordinate, 0, 0);
// Draw nothing.
theGraphicsToDrawPoints.DrawRectangle(pen, xCoordinate, yCoordinate, -1,
-1); // Draw nothing.
 
The OnPaint method is overridden to do any custom painting. It is called
whenever the surface needs to be repainted. Call your method in an override
of the OnPaint method.

--
HTH,

Kevin Spencer
Microsoft MVP

DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
Hello,
Tamirro told me the following solution.

// Create a 1 x 1 bitmap and set the color
Bitmap bitmap = new Bitmap(1, 1);
bitmap.SetPixel(0, 0, seriesColor);

// Draw bitmap on Graphics surface
theGraphicsToDrawPoints.DrawImageUnscaled(bitmap, (int)xCoordinate,
(int)yCoordinate);

I am concerned about their speed. When we just move our application from VS
2003 to VS 2005 the SetPixel and GetPixel are very slow. We have to use some
unfafe code to avoid use them. Do you know Microsoft fix the problem?
 
Back
Top