473,395 Members | 1,452 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 2029
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: RickDee | last post by:
I really can't understand on how to use CreateGraphics. Even though I have follow what is shown in many sites, I can't get it working at all. For example. I have textbox name textbox1. I...
1
by: S Domadia | last post by:
hi, now actually i want to design custom combo in which combo's button (in which down arrow is there to perform clicking for dropdown type of combo) should be also black in color. so as it's not...
1
by: JH | last post by:
I have a tab control in my form. I am trying to create a dynamic pie chart. If I use the following code,it works fine on the main form. this.CreateGraphics().FillPie(brushtargeted,240,200,200, 200,...
1
by: takilroy | last post by:
Hi, I am trying to implement this snippet of code from the .Net help documentatiion so that I can modify the width of a textbox on one of my aspx forms. However, for some reason visual studio...
11
by: active | last post by:
picInfo is a PictureBox that I write into when the mouse moves. Below is a snip of the code. The text flashes on the screen but does not stay there. Anyone know why? Second question.-...
6
by: saunderl | last post by:
Hello Everyone, I'm trying to just play with managed VC++. I just want to draw a box on the form when it is clicked. Here is my click event handler System::Void Test_Click(System::Object^ ...
8
by: pigeonrandle | last post by:
Hi, Please pity me, i am on a dial-up connection for the first time in 5 years :( ! Does anyone know how the resulting Graphics objects differ ...? What i really mean is can someone explain it...
6
by: active | last post by:
I did the following and then wondered it's good practice. Me.CreateGraphics.DrawImage(Img, 0, 0) I'm thinking about disposing the Graphics object. A couple of lines after this I exit the sub...
4
by: vijay_3491 | last post by:
Hi, How to write a CreateGraphics method for a class similar to form.CreateGraphics()? Pls help. Thanks in Advance.
3
by: bromptonville-un | last post by:
Hello, I'm an amateur in VB6, and I just switched to VB.Net (2003) . However, I've never used graphicals functions in neither those language... (Last time I drew something was in VB6). I...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.