Click to See Complete Forum and Search --> : Simple graphics
Techno
Apr 7th, 2006, 07:51 PM
Hi.
What is the best way in C# to create graphics? more specifically, what are the best guidelines to say, make a rectangle on a document?
What I am trying to do is print out a page. And I am making a simple "invoice" - and of course I would like to have sub sections such as customer, recepient and so on.
So, I thought I would have these sections have rectangles, then within the rectangle to neatly line up or contain headings and so on.
how can I do this?
As well as this, does anyone know how I can put a line break or make a blank line on a PrintDocument object?
Thanks
jmcilhinney
Apr 7th, 2006, 08:27 PM
PrintDocuments don't have any concept of line breaks. A PrintDocument provides the PrintPage event to draw anything you like on the printing surface. The 'e' argument has a Graphics property that is use to do the drawing. You draw whatever you want wherever you want using its methods like DrawString, DrawRectangle, DrawImage, etc. You control every aspect of what is printed, where it is printed and how it looks. It's all done using GDI+, the same as if you were drawing on a control on-screen. Any GDI+ tutorial is relevant.
Techno
Apr 7th, 2006, 08:32 PM
Thanks, I know about the printpage events and so on - its just actually drawing to it, the graphics which I have never done and it's pretty tough!
hm. what is the best way to write a string underneath another string. say for example, I have a collection of strings, for each string, how do i say print the current string, then move to the next line and print the next string on the document page?
jmcilhinney
Apr 7th, 2006, 09:07 PM
There is no concept of moving to the next line. You draw the first string at the coordinates you want, then you draw the next string at the coordinates you want, which will presumably be the same X value but a greater Y value so it is below the first. I suppose that you could Join all the strings with line breaks to make a single string and then draw that. The vertical spacing will then be controlled by the Font. If you draw multiple single line strings then you control the vertical spacing by specifying the coordinates for each one.
Techno
Apr 7th, 2006, 09:40 PM
drats this is tough!
I have made a rectangle and drawn it
now I am trying to make the label headings inside the rectangle
but how can I position the label a few bits away from the previous label?
wossname
Apr 8th, 2006, 05:31 AM
The DrawString() method accepts a rectangle as one of its parameters, all the text you draw will be slotted neatly into that rect.
What is particularly bothering you about graphics? e.Graphics.DrawRect(...) is all you need to do.
Techno
Apr 8th, 2006, 07:58 AM
really? Well I guess I'll give that a shot. I am not really good with graphics, and co-ordinates and so on lol - I prefer to do things properly the first time and make sure that it is almost "future" prone incase if I Decide to change the positioning of an object. But thats just me!
So, you are saying if I have a rectangle, and I use drawstring, if I give it that rectangle it will neatly make the text centered?
jmcilhinney
Apr 8th, 2006, 09:50 AM
Take a look at all the methods of the Graphics class that start with "Draw" and the overload lists of those you're interested in. You can basically do whatever you want. You just have to pick the appropriate overload of the appropriate method and pass it the appropriate parameters.
Techno
Apr 8th, 2006, 10:47 AM
Well I have tried that but it does not seem to align the text to be centered:
Rectangle theCompany = new Rectangle(20, 40, 200, 240);
e.Graphics.DrawString("Some company", Font, Brushes.Black, theCompany);
Techno
Apr 8th, 2006, 11:04 AM
ok well seem to have resolved this one. use the StringFormat class, and then format the string, and give it to the DrawString method
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.