469,934 Members | 1,879 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

CreateGraphics

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.

Aug 13 '07 #1
4 1878
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

"Haiping" <Ha*****@discussions.microsoft.comwrote in message
news:F0**********************************@microsof t.com...
>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.

Aug 14 '07 #2
Hi Kevin,

Yes, I have to use this way. It works!

Thank you,
Haiping
Aug 14 '07 #3
How to draw just one pixel?

Thank you,
Aug 14 '07 #4
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?

Aug 14 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by RickDee | last post: by
1 post views Thread by JH | last post: by
1 post views Thread by takilroy | last post: by
11 posts views Thread by active | last post: by
6 posts views Thread by saunderl | last post: by
4 posts views Thread by vijay_3491 | last post: by
3 posts views Thread by bromptonville-un | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.