CreateGraphics

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.
 
K

Kevin Spencer

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
 
G

Guest

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top