[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

correct "mental model" of graphics of a control ?

Bill Woodruff

10/28/2004 12:48:00 PM

For a while I had a "mental model" that for controls (say, a panel) that the
Graphics object you would get inside the Paint event by doing :

Graphics panelPaintGraphics = e.Graphics;

// do something ....

Was probably a pointer to an object that might be moved around in memory, that
it was "automagically" disposed when the Paint event was exited.

Thus, I assumed that you had to get the pointer "fresh" every time to do the
drawing business you wanted to do. But a friend here suggested just creating a
Graphics object off the control using 'CreateGraphics :

Graphics panelGraphics = thePanel.CreateGraphics();

And, to my surprise, I found that was re-usable across many Paint events.

I would appreciate any insights you may have into the behavior of Forms,
UserControls, etc. compared to Panels in this regard.

The specific project I am working on involves bit-blitting from a very large
source image, and I have it working fairly well to a panel surface, but am
curious is it might be better to be blitting to a form surface, or a usercontrol
surface.

thanks, Bill

"wisdom is when no one doubts your own hypotheses more than you do, honesty is
when no one is more willing to revise your incorrect hypotheses than you are,
and humanity is when you abandon your hypotheses and face the beauty and
complexity of life with an open, vulnerable, and sincere heart."



3 Answers

Bob Powell

10/28/2004 1:17:00 PM

0

Don't do it. There is pain involved. See the GDI+ FAQ for why.

It doen't matter where you blit to. it's all the same mechanism. It
certainly won't be the same graphics object though.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdipl...

The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tips...
Bob's Blog: http://bobpowelldotnet.blogspot.co...






"Bill Woodruff" <billw at dotscience dot com> wrote in message
news:OCJAhxOvEHA.3080@TK2MSFTNGP12.phx.gbl...
> For a while I had a "mental model" that for controls (say, a panel) that
the
> Graphics object you would get inside the Paint event by doing :
>
> Graphics panelPaintGraphics = e.Graphics;
>
> // do something ....
>
> Was probably a pointer to an object that might be moved around in memory,
that
> it was "automagically" disposed when the Paint event was exited.
>
> Thus, I assumed that you had to get the pointer "fresh" every time to do
the
> drawing business you wanted to do. But a friend here suggested just
creating a
> Graphics object off the control using 'CreateGraphics :
>
> Graphics panelGraphics = thePanel.CreateGraphics();
>
> And, to my surprise, I found that was re-usable across many Paint events.
>
> I would appreciate any insights you may have into the behavior of Forms,
> UserControls, etc. compared to Panels in this regard.
>
> The specific project I am working on involves bit-blitting from a very
large
> source image, and I have it working fairly well to a panel surface, but am
> curious is it might be better to be blitting to a form surface, or a
usercontrol
> surface.
>
> thanks, Bill
>
> "wisdom is when no one doubts your own hypotheses more than you do,
honesty is
> when no one is more willing to revise your incorrect hypotheses than you
are,
> and humanity is when you abandon your hypotheses and face the beauty and
> complexity of life with an open, vulnerable, and sincere heart."
>
>
>


Bill Woodruff

10/28/2004 4:21:00 PM

0

Bob Powell [MVP] wrote: >> Don't do it. There is pain involved. See the GDI+ FAQ
for why.

Bob, Thanks for your response. I have read your GDI+FAQ many times. In fact it
was partially based on your advice about the PictureBox that I went looking for
another way to show an image which has led to the current solution where I am
able to move around a 5500x9900 PNG image pretty fast with the mouse (consuming
only 300 megs or so of memory internally) in a panel functioning as a
"viewport."

When you say "don't do it" : which of my blunders were you referring to :)

best, Bill



Bob Powell

10/28/2004 8:36:00 PM

0

Don't mess about with CreateGraphics. There is an article that explains
where and when to use this method.

The PictureBox object is ok, as long as you just use it to display pictures
and don't try to coerce it into any sort of editing object or graphics
placeholder. The panel solution or, if you're up for it, a custom solution
based on ScrollableControl is ideal.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdipl...

The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tips...
Bob's Blog: http://bobpowelldotnet.blogspot.co...






"Bill Woodruff" <billw at dotscience dot com> wrote in message
news:OEleuoQvEHA.3200@TK2MSFTNGP14.phx.gbl...
> Bob Powell [MVP] wrote: >> Don't do it. There is pain involved. See the
GDI+ FAQ
> for why.
>
> Bob, Thanks for your response. I have read your GDI+FAQ many times. In
fact it
> was partially based on your advice about the PictureBox that I went
looking for
> another way to show an image which has led to the current solution where I
am
> able to move around a 5500x9900 PNG image pretty fast with the mouse
(consuming
> only 300 megs or so of memory internally) in a panel functioning as a
> "viewport."
>
> When you say "don't do it" : which of my blunders were you referring to :)
>
> best, Bill
>
>
>