A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Creating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.
Drawing with C#A tutorial with examples of how to draw different things on a form using OnPaint. |
On Tuesday, May 25th 2004 at 03:18 AM By Andrew Pociu (View Profile) ![]() ![]() ![]() ![]() (Rated 4.4 with 74 votes) |
||
|
In this tutorial We're going to play a little by drawing with C#.
RectanglesTry this code:
The above code produces the following: ![]() The easiest way to learn is by examples and exercises. Therefore search for different results and try to accomplish something else by modifying the pieces of code or creating your own. |
|||
Digg It!
Del.icio.us
Reddit
StumbleIt
Newsvine
Furl
BlinkList
|
|||
|
|||
Current CommentsSimple Tutorial, but very helpful. Thank you.
Thanks for this informative tute.
More helpful than other tutorials where you can't see the purpose of the tutorials because of its complexity
Took me 40 minutes to find a tutorial on how to draw straight onto a form that I coudl either get to or understand, this does both brilliant.
Simple and and easy. Good job!
Informative.. thanks. Provided what I was looking for.
Very good. Even a beginner like me could understand this
A very very beginner. Where does the OnPaint go?
Inside the class of your main form (Form1 for example). It will override the existing OnPaint.
Thank You
great tutorial. straight forward like all cide should be.
That was a FABULOUS TUTORIAL
It easily poked into my garbage box(MIND).
;o
Hi,
This is really very useful for beginners like me in graphics.
Thanku
simple but much more informative
great tutorial! But I need something more complicated:(. I want to make a program that looks like Paint! I want to draw rectangles, lines and other shapes with mouse. Can anybody help me?
Nice straightforward tutorial.. I noticed little bug,, the last for loop in the entire code needs a curly bracket ( } ) to close it,, correct me if am wrong :)
great work Andrei
Shokran, Gracias, Thanks
Ehab
very good example code...
I can\'t get any of this to run.
I get the error message:
The type of namespace name \'PaintEventArgs\' could not be found (are you missing a using directive or an assembly reference?
The usual frustration I have is that lots of details are given on stuff that would be easy to figure out, and no mention of the ESSENTIAL information without which one can do nothing. Where can one go to REALLY learn this stuff?
PaintEventArgs is in System.Windows.Forms. As long as you have an using statement for that (and since it's a Windows Forms application, you should) everything should work. What version of .NET are you trying to compile this into and what is the project type?
Hello,
I changed little the code in the way to show it as a graph paper, as shown below, and added A.minscroll property in the form right to w.800, and setting i
sorry, add background color white in the properties, too. :)
I noticed when drawing on say for example a panel control, the scrollbars will not display when the content exceeds the viewable drawing area. How do you overcome this?
Hey ominimny, I think you can use g.TranslateTransform(_page.AutoScrollPosition.X, _page.AutoScrollPosition.Y);
...but I can't be sure since I can't even get scroll bars to show up when I paint music staff lines on my panel control.
Ok...I got it and thought I would share with the community.
Issue: Draw lines using graphics. Lines exceed the viewable area but scrollbars do not display.
Setup: using System.Windows.Forms.TabPage to draw on. My Form creates a control that allows me to set parameters of an object I call Staff (used to create musical staff lines). Once these parameters are defined for the staff object, the control does a call back (using a delegate) to the main form that created this control, informing it that the CreateStaff button was clicked. This delegate will call a method to Invalidate the TapPage control which causes it to paint. The paint method calls a draw method on the composition object which executes the DrawStaff ie: Graphics g = PaintEventArgs.Graphics;
Challenge: Many...but, the one specific to this thread is the scrollbar. First have AutoScroll = true and AutoScrollMinSize will be set in code at run time. Now, as I draw new staff lines I increment this AutoScrollMinSize value like this: DrawCanvas.AutoScrollMinSize = new Size(var1,var2);
var1 and var2 increase as I add more staff lines. Now, scrolling made everything disapear so I added g.TranslateTransform(DrawCanvas.AutoScrollPosition.X, DrawCanvas.AutoScrollPosition.Y);
Now everything works fine. If you want the code just email me because its to much to put here.
Keys to remember:
Graphics TranslateTransform
Paint method and using the PaintEventArgs
AutoScroll = true and DrawCanvas.AutoScrollMinSize = new Size(var1,var2);
Good tutorial but I'd like to know how to draw an object of a class I have created on the form and then move it.
E.g. say I have a class called Ball and I'd like to draw an object of this class on the form and then move it horixontally. Where can I find how to do this??
Hi,
I am umasankar padhan greatful for this line designing.
My request is i want to Draw aline from croners of the Windows Form using c# (gui) or (cui).So; You will give me this report and reference of codes through my Email.
Can you show how to draw with the mouse onto a surface in the browser in C#?
Pls help,
I would like to create a object called "POINT" and let the user to manipulate with it.
It means: implement event
i want to draw two arrows using paint.
i have 2 button
when i click first button one arrow is vissibe other is invisible
when i click second button other arrow is vissibe first is invisible
Can you show how to draw with the mouse onto a surface in the browser in C#?
I'm programming in ASP.NET.
Thanks!
protected override void OnPaint(PaintEventArgs e)
{
// Get the graphics object
Graphics gfx = paintEvnt.Graphics;***
// Create a new pen that we shall use for drawing the line
Pen myPen = new Pen(Color.Black);
// Loop and create a new line 10 pixels below the last one
for (int i = 20; i < 250; i = i 10)
{
gfx.DrawLine(myPen, 20, i, 270, i);
}
***Where the three stars are paintEvnt is red underligned and it dose not exist because i have not declaired it...i think, im not sure, im new to C# and everything else works apart from that. if i have to declair it, how is it like a vairiable e.g:
int[] kablamao = new int;
kablamao = new int [3];
kablamao[0] = 666;
:P
I need to be able to do something like this in a browser.
Can you explain how this might work there?
Thanks for all this!! What the fuck is wrong with MSDN? Almost all the info there seems useless.
drawing waveform
drawing waveform
i get to compile the code without any errors but i dont get any output, can someone pls HELP me its important. I am using Visual c# 2005. plsssss
protected override void OnPaint(PaintEventArgs e)
{
// Get the graphics object
Graphics gfx = paintEvnt.Graphics;***
// Create a new pen that we shall use for drawing the line
Pen myPen = new Pen(Color.Black);
// Loop and create a new line 10 pixels below the last one
for (int i = 20; i < 250; i = i 10)
{
gfx.DrawLine(myPen, 20, i, 270, i);
}
***Where the three stars are paintEvnt is red underligned and it dose not exist because i have not declaired it...i think, im not sure, im new to C# and everything else works apart from that. if i have to declair it, how is it like a vairiable e.g:
int[] kablamao = new int;
kablamao = new int [3];
kablamao[0] = 666;
------------------------------------------------
The object paintEvnt is the argument passed to the OnPaint event handler, but you have it named e in the definition. Rename it, like so:
protected override void OnPaint(PaintEventArgs paintEvnt)
{
// Get the graphics object
Graphics gfx = paintEvnt.Graphics;
Good tutorial. How would you make this happen when you pressed a button on the form for example? Rather than when the form is created?
Cheers
Thank you,it's very usefull for me
hi i need to draw graph in c# on run time.
Can you explain how this might work there?
hi, how can run with button ? I tried but i couldn^t call function
Hi...how do I change the pen style?
I tried this
Pen p=new Pen(Color.Red);
p.DashStyle=DashStyle.Dot;
But I am getting an error:The name DashStyle does not exist in the current context.
Hi Nev:
Solution is:
using System.Drawing.Drawing2D;
Easy stuff
I did exactly as the tutorial said, it compiled fine, and my form is still blank.
Brilliant Stuff in here .. terse and to the point !!
Thanks man.
A difficult subject explained in an easy tutorial. Thanks.
I believe you want to include the base method when overriding methods.
protected override void OnPaint(PaintEventArgs paintEvnt)
{
...
base.OnPaint(paintEvnt)
}
In this example you would not need it because you are handling everything that is painted yourself but it is still good practice to include it. Is there some reason for not including it that I am missing?
I need coding for drawing a star in visual c#.
great work
Hi, I really like it, please can you sent source code to me, or post here.
Thank you
how to make panit and panel to import images. so
image save ... help me
wtf, i couldnt make anyhtign work, so i jsut copied the code in exactly how he had it and i just got error message spam, why...
I am using visual basic 2010 C#
thanks man you helped me very much
bless you and bless your faithful job
What should I do to stop receive notification
to my e-mail, about this tutorial?
Hi. Thanks for the tutorial. I found it fun to do and it was a good destressor when my other programming study was not going so well. It was clear and easy to understand
THANKYOU VERY VERY VERY MUTCH
THANKYOU VERY VERY VERY MUTCH
thank u for providing me information on List View.
I want to know how i can display data in datalist in Newsletter layout and Thank you so much, this is easy to understand and fun to continue along with. I am a migrating VB.NET/C# Developer looking for an insight into VC .NET. I've found the VC tutorials on many sites to be confusing, and the navigation around the sites to be near impossible to use! Thanks once again.
thank u for providing me information on List View.
I want to know how i can display data in datalist in Newsletter layout and Thank you so much, this is easy to understand and fun to continue along with. I am a migrating VB.NET/C# Developer looking for an insight into VC .NET. I've found the VC tutorials on many sites to be confusing, and the navigation around the sites to be near impossible to use! Thanks once again.
Once you have recreated the problem and captured these steps, you can save them to a file and send it to your support person, who can then open it up and view
Once you have recreated the problem and captured these steps, you can save them to a file and send it to your support person, who can then open it up and view
I am glad for writing to let you be aware of of the wonderful discovery my princess obtained visiting the blog. She mastered a lot of pieces, which include how it is like to possess an awesome helping mindset to have many more just fully understand certain multifaceted matters. You undoubtedly exceeded our desires. Thank you for producing the priceless, safe, edifying as well as unique tips on the topic to Sandra.
I don’t even know how I ended up here, but I thought this post was good. I do not know who you are but definitely you're going to a famous blogger if you are not already ;) Cheers!
You could certainly see your enthusiasm within the paintings you write. The sector hopes for more passionate writers such as you who aren't afraid to say how they believe. All the time follow your heart.
Thanks for all this!! What the fuck is wrong with MSDN? Almost all the info there seems useless.
even know how I ended up here, but I thought this post was good. I do not know who you are but definitely you're going to a famous blogger if you are not already ;) Cheers!
Thanks for all this!! What the fuck is wrong with MSDN? Almost all the info there seems useless.
Almost all the info there seems useless.
how i can draw many sommets
how i can draw many sommets
how i can draw many sommets
how i can draw many sommets
how i can draw many sommets
how i can draw many sommets
how i can draw many sommets
Because of its complexity this tutorial is very helpful. I made this one in my programming subject, using codes to create a line or anything. This is a brilliant stuff! Visiting your blogs will help me in advance for my lesson.
Thanks for the great buttons.resume writing services reviews First-class job. http://www.resumewritingservicesreviews.net
Thanks for the great buttons.resume writing services reviews First-class job. http://www.resumewritingservicesreviews.net
Thanks for the great buttons.resume writing services reviews First-class job. http://www.resumewritingservicesreviews.net
Thanks for the great buttons.resume writing services reviews First-class job. http://www.resumewritingservicesreviews.net
very nice
I made this one in my programming subject, using codes to create a line or anything.
I strictly recommend not to hold off until you get enough cash to order different goods! You should just get the loans or financial loan and feel comfortable
You should just get the loans or financial loan and feel comfortable
You should just get the loans or financial loan and feel comfortable
Ive read anything comparable to this prior to. So nice to uncover somebody with several original applying
comparable to this prior to. So nice to uncover somebody with several original applying
You should just get the loans or financial loan and feel comfortable
Related Tutorials
Related Source Code
C# Job SearchFrom the creators of Geekpedia, a revolutionary new coupon website!
BargainEZ has coupons codes, printable coupons, bargains and it is the leading source of Passbook coupons for iPhone and iPod touch devices.