Perform painting

M

Marc Gravell

Is this a recommended way to go?
Looks about right; maybe call the base method first...
I've also seen that there's System.Drawing.*
"Graphics " is part of System.Drawing, so this is a mute question
Is there a better one?
If you want something funky, you might also look at WPF, then whole
new GUI framework in .NET 3.0

Marc
 
K

K Viltersten

I'm going to design some custom painting on a component
and the way i'm going to start off is to inherit a Form and
then override the following method.

private void onPaint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.doCoolStuffToMe();
}

Is this a recommended way to go? Is there a better one?


I've also seen that there's
System.Drawing.*
and i wonder if it's more suitable for designing my own
graphics or if extending a Forms.Form to a class called
e.g. Canvas is a smart solution.
 
K

K Viltersten

Is this a recommended way to go?
Looks about right; maybe call the base method first...

"Graphics " is part of System.Drawing, so this is a mute question

If you want something funky, you might also look at WPF, then whole
new GUI framework in .NET 3.0


Yes, i do and yes, i will.

However, was your reply a "yes", a "no" or a "boy,
can't explain it in short..."?

In Java i'm used to override a components
paintComponent (Graphics g)
but that doesn't imply it's the way to solve it in C#.
That's what i'm curious about.
 
P

Peter Duniho

[...]
In Java i'm used to override a components paintComponent (Graphics g)
but that doesn't imply it's the way to solve it in C#.
That's what i'm curious about.

For the most part, your Java techniques will apply in .NET. They aren't
exactly the same, but the general idea of always drawing in a specific
method designed for the purpose and that method being called by the system
to have you draw when needed applies in both cases. Since that's a
central part of understanding how drawing works in both environments,
you're way ahead of the game.

You had a number of questions, so I don't think Marc's reply could have a
simple "yes" or "no". If you're only asking specifically about the last
question ("is there a better one?"), then that's difficult to answer
without knowing what you're trying to do. WPF is supposed to provide in
some respects a simpler, more broadly featured drawing API, but the
pre-WPF drawing paradigm works just fine.

Overriding OnPaint() is not only acceptable, it's a good way to do drawing
assuming you don't have a specific desire to use WPF. Other than
providing a handler for the Paint event, it's the only "right way" to do
it (and in Control-inheriting classes, IMHO overriding the OnPaint()
method is generally better).

Pete
 
K

K Viltersten

Peter Duniho said:
[...]
In Java i'm used to override a components paintComponent (Graphics g)
but that doesn't imply it's the way to solve it in C#.
That's what i'm curious about.

For the most part, your Java techniques will apply in .NET. They aren't
exactly the same, but the general idea of always drawing in a specific
method designed for the purpose and that method being called by the system
to have you draw when needed applies in both cases. Since that's a
central part of understanding how drawing works in both environments,
you're way ahead of the game.

You had a number of questions, so I don't think Marc's reply could have a
simple "yes" or "no". If you're only asking specifically about the last
question ("is there a better one?"), then that's difficult to answer
without knowing what you're trying to do. WPF is supposed to provide in
some respects a simpler, more broadly featured drawing API, but the
pre-WPF drawing paradigm works just fine.

Overriding OnPaint() is not only acceptable, it's a good way to do drawing
assuming you don't have a specific desire to use WPF. Other than
providing a handler for the Paint event, it's the only "right way" to do
it (and in Control-inheriting classes, IMHO overriding the OnPaint()
method is generally better).


Thanks!

I guess i underestimated the complexity of my
question. I should have explain that i'll be
drawing some graphs.

--

Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor

amibition - lack of sense to be lazy

- "What's the difference between training and educating?"
- "Would you like your 14-years old dotter to be sexually educated or
trained?"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top