Click here to Skip to main content
15,917,709 members
Home / Discussions / Graphics
   

Graphics

 
GeneralRe: drawing in a rectangle? Pin
Harvey Saayman6-Mar-08 22:57
Harvey Saayman6-Mar-08 22:57 
GeneralRe: drawing in a rectangle? Pin
Luc Pattyn7-Mar-08 0:07
sitebuilderLuc Pattyn7-Mar-08 0:07 
GeneralRe: drawing in a rectangle? Pin
Harvey Saayman7-Mar-08 0:54
Harvey Saayman7-Mar-08 0:54 
Generalthis.CreateGraphics() Issue Pin
Harvey Saayman5-Mar-08 21:32
Harvey Saayman5-Mar-08 21:32 
GeneralRe: this.CreateGraphics() Issue Pin
Tim Craig5-Mar-08 22:33
Tim Craig5-Mar-08 22:33 
GeneralRe: this.CreateGraphics() Issue Pin
Mark Salsbery6-Mar-08 6:06
Mark Salsbery6-Mar-08 6:06 
GeneralRe: this.CreateGraphics() Issue Pin
Harvey Saayman6-Mar-08 19:45
Harvey Saayman6-Mar-08 19:45 
GeneralRe: this.CreateGraphics() Issue Pin
Luc Pattyn6-Mar-08 7:01
sitebuilderLuc Pattyn6-Mar-08 7:01 
Hi,

here are my guidelines for painting in general:

there are several steps to draw something so it becomes visible on the screen:

1.
decide upon what object you want to draw; it normally is a Control (e.g. a Panel) or a
Form itself. I prefer to add a Panel to a Form, then draw on the Panel.

2.
create some variables (Rectangle, struct, class, whatever) that hold the parameters of
your drawing. For a rectangle that could be top and left coordinate, and width+height,
or just a Rectangle. etc.

3.
create a Paint handler for that Panel, and do all your drawing in there, using the
Graphics class and your variables.

4.
when you want to change things, modify the variables and call Panel.Invalidate() or
one of its overloads (for selective invalidation).
5.
If you want to animate things, perform the move (step 4) inside the Tick handler
of a Windows.Forms.Timer

BTW: if you need to create some objects (Fonts, Pens, Brushes, ...) either keep them
alive in class members (hence create them only once); or create them inside the Paint
handler and don't forget to call Dispose() on them.

Remark: you very rarely need CreateGraphics; OnPaint offers a Graphics object for free.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.


GeneralRe: this.CreateGraphics() Issue Pin
Harvey Saayman6-Mar-08 19:48
Harvey Saayman6-Mar-08 19:48 
GeneralRe: this.CreateGraphics() Issue Pin
Christian Graus6-Mar-08 20:49
protectorChristian Graus6-Mar-08 20:49 
GeneralRe: this.CreateGraphics() Issue Pin
Harvey Saayman6-Mar-08 20:55
Harvey Saayman6-Mar-08 20:55 
GeneralRe: this.CreateGraphics() Issue Pin
Christian Graus6-Mar-08 21:29
protectorChristian Graus6-Mar-08 21:29 
GeneralRe: this.CreateGraphics() Issue Pin
Harvey Saayman6-Mar-08 21:43
Harvey Saayman6-Mar-08 21:43 
GeneralPush mode/Pull mode Pin
Sugantha5-Mar-08 19:55
Sugantha5-Mar-08 19:55 
GeneralRe: Push mode/Pull mode Pin
Mark Salsbery6-Mar-08 5:59
Mark Salsbery6-Mar-08 5:59 
Generalrendering video Pin
jossion4-Mar-08 19:16
jossion4-Mar-08 19:16 
GeneralRe: rendering video Pin
Mark Salsbery4-Mar-08 19:46
Mark Salsbery4-Mar-08 19:46 
GeneralRe: rendering video Pin
jossion4-Mar-08 22:52
jossion4-Mar-08 22:52 
GeneralRe: rendering video [modified] Pin
Mark Salsbery5-Mar-08 5:59
Mark Salsbery5-Mar-08 5:59 
GeneralRe: rendering video Pin
jossion5-Mar-08 16:19
jossion5-Mar-08 16:19 
GeneralRe: rendering video Pin
Mark Salsbery5-Mar-08 16:50
Mark Salsbery5-Mar-08 16:50 
GeneralRe: rendering video Pin
jossion23-Feb-09 21:41
jossion23-Feb-09 21:41 
GeneralRe: rendering video Pin
Mark Salsbery24-Feb-09 5:39
Mark Salsbery24-Feb-09 5:39 
GeneralRe: rendering video Pin
jossion24-Feb-09 16:49
jossion24-Feb-09 16:49 
QuestionScreen Capture over Terminal Server Pin
intonet4-Mar-08 3:29
intonet4-Mar-08 3:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.