Connecting Tech Pros Worldwide Forums | Help | Site Map

Invalidate() compared to Refresh()

SamSpade
Guest
 
Posts: n/a
#1: Nov 20 '05
picDocument is a picturebox

When I do picDocument.Invalidate() the box paints.

But if instead I do picDocument.Refresh() the box does not paint.

What does Refresh do. I guessed it did an Invalidate and an Update.

Can someone shed some light?





Thanks





yEaH rIgHt
Guest
 
Posts: n/a
#2: Nov 20 '05

re: Invalidate() compared to Refresh()


Refresh doesn't send a paint message to the control. It's telling the
control to redraw itself.


" SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
news:O$vEa4VNEHA.3668@TK2MSFTNGP11.phx.gbl...[color=blue]
> picDocument is a picturebox
>
> When I do picDocument.Invalidate() the box paints.
>
> But if instead I do picDocument.Refresh() the box does not paint.
>
> What does Refresh do. I guessed it did an Invalidate and an Update.
>
> Can someone shed some light?
>
>
>
>
>
> Thanks
>
>
>
>[/color]


Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#3: Nov 20 '05

re: Invalidate() compared to Refresh()


* "yEaH rIgHt" <nospam@haha> scripsit:[color=blue]
> Refresh doesn't send a paint message to the control. It's telling the
> control to redraw itself.[/color]

What's the difference?

(I know the difference, but I want to hear it ;-))

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
SamSpade
Guest
 
Posts: n/a
#4: Nov 20 '05

re: Invalidate() compared to Refresh()


[color=blue][color=green]
> > Refresh doesn't send a paint message to the control. It's telling the
> > control to redraw itself.[/color]
>
> What's the difference?
>
> (I know the difference, but I want to hear it ;-))[/color]

I don't think the >> above answers my question but let me take a stab at
answering yours.
By paint message I think he means paint event so sending a paint message
means raising the paint event.

Telling a contoll to redraw itself might means sending an Update message.

What do you think??

I know of the WindowsAPI's Invalidate and Update.
I'd guess Refresh does them both but that does not agree with what I
observed.
What I'd like to know is:
When I does picDocument.Invalidate() the box paints.
But if instead I do picDocument.Refresh() the box does not paint.



Jay B. Harlow [MVP - Outlook]
Guest
 
Posts: n/a
#5: Nov 20 '05

re: Invalidate() compared to Refresh()


SamSpade,
Control.Refresh - does a Control.Invalidate immediately followed by
Control.Update.

Control.Invalidate - invalidates a specific region of the Control (defaults
to entire client area) and causes a paint message to be sent to the control.

Control.Update - causes the Paint event to occur immediately (Windows will
normally wait until there are no other messages for the window to process,
before raising the Paint event).


Refresh can be overridden, have you overridden it to change its behavior?


The paint event of course is where all the drawing of your PictureBox
occurs. Note there is only one pending Paint event, if you call Invalidate 3
times, you will still only receive one Paint event.

Hope this helps
Jay

" SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
news:O$vEa4VNEHA.3668@TK2MSFTNGP11.phx.gbl...[color=blue]
> picDocument is a picturebox
>
> When I do picDocument.Invalidate() the box paints.
>
> But if instead I do picDocument.Refresh() the box does not paint.
>
> What does Refresh do. I guessed it did an Invalidate and an Update.
>
> Can someone shed some light?
>
>
>
>
>
> Thanks
>
>
>
>[/color]


yEaH rIgHt
Guest
 
Posts: n/a
#6: Nov 20 '05

re: Invalidate() compared to Refresh()


>By paint message I think he means paint event so sending a paint message[color=blue]
> means raising the paint event.[/color]

That's what I meant. It doesn't raise an paint event for you to use.


" SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
news:Oy2MencNEHA.3124@TK2MSFTNGP12.phx.gbl...[color=blue]
>[color=green][color=darkred]
> > > Refresh doesn't send a paint message to the control. It's telling the
> > > control to redraw itself.[/color]
> >
> > What's the difference?
> >
> > (I know the difference, but I want to hear it ;-))[/color]
>
> I don't think the >> above answers my question but let me take a stab at
> answering yours.
> By paint message I think he means paint event so sending a paint message
> means raising the paint event.
>
> Telling a contoll to redraw itself might means sending an Update message.
>
> What do you think??
>
> I know of the WindowsAPI's Invalidate and Update.
> I'd guess Refresh does them both but that does not agree with what I
> observed.
> What I'd like to know is:
> When I does picDocument.Invalidate() the box paints.
> But if instead I do picDocument.Refresh() the box does not paint.
>
>
>[/color]


yEaH rIgHt
Guest
 
Posts: n/a
#7: Nov 20 '05

re: Invalidate() compared to Refresh()


If you know the answer then why don't you tell us, master?

"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:OThaaebNEHA.1160@TK2MSFTNGP11.phx.gbl...[color=blue]
> * "yEaH rIgHt" <nospam@haha> scripsit:[color=green]
> > Refresh doesn't send a paint message to the control. It's telling the
> > control to redraw itself.[/color]
>
> What's the difference?
>
> (I know the difference, but I want to hear it ;-))
>
> --
> Herfried K. Wagner [MVP]
> <URL:http://dotnet.mvps.org/>[/color]


Jay B. Harlow [MVP - Outlook]
Guest
 
Posts: n/a
#8: Nov 20 '05

re: Invalidate() compared to Refresh()


Yeah Right,
Are you certain?

In VS.NET 2002 & VS.NET 2003 Refresh calls Invalidate & Update methods, the
Update method sends the paint message to the control.

For details see:
http://msdn.microsoft.com/library/de...dateTopic1.asp

http://msdn.microsoft.com/library/de...pdateTopic.asp

http://msdn.microsoft.com/library/de...freshTopic.asp


Or are you using Mono? Is it different in Mono? Or are you simply stating
that Refresh does not directly send the paint message, that it sends it
indirectly via the Update?

Just curious
Jay

"yEaH rIgHt" <nospam@haha> wrote in message
news:109r34ge5bhu4f5@corp.supernews.com...[color=blue]
> Refresh doesn't send a paint message to the control. It's telling the
> control to redraw itself.
>
>
> " SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
> news:O$vEa4VNEHA.3668@TK2MSFTNGP11.phx.gbl...[color=green]
> > picDocument is a picturebox
> >
> > When I do picDocument.Invalidate() the box paints.
> >
> > But if instead I do picDocument.Refresh() the box does not paint.
> >
> > What does Refresh do. I guessed it did an Invalidate and an Update.
> >
> > Can someone shed some light?
> >
> >
> >
> >
> >
> > Thanks
> >
> >
> >
> >[/color]
>
>[/color]


Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#9: Nov 20 '05

re: Invalidate() compared to Refresh()


* "yEaH rIgHt" <nospam@haha> scripsit:[color=blue]
> If you know the answer then why don't you tell us, master?[/color]

Because Jay has already done it ;-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
yEaH rIgHt
Guest
 
Posts: n/a
#10: Nov 20 '05

re: Invalidate() compared to Refresh()


Jay, you're right. I made a stupid blunder. I had a button click event with
the ReFresh method in it but I was hitting the wrong button. I guess I
shouldn't answer questions late at night. D'OH!!!


"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
news:eQAkezcNEHA.1388@TK2MSFTNGP09.phx.gbl...[color=blue]
> Yeah Right,
> Are you certain?
>
> In VS.NET 2002 & VS.NET 2003 Refresh calls Invalidate & Update methods,[/color]
the[color=blue]
> Update method sends the paint message to the control.
>
> For details see:
>[/color]
http://msdn.microsoft.com/library/de...dateTopic1.asp[color=blue]
>
>[/color]
http://msdn.microsoft.com/library/de...pdateTopic.asp[color=blue]
>
>[/color]
http://msdn.microsoft.com/library/de...freshTopic.asp[color=blue]
>
>
> Or are you using Mono? Is it different in Mono? Or are you simply stating
> that Refresh does not directly send the paint message, that it sends it
> indirectly via the Update?
>
> Just curious
> Jay
>
> "yEaH rIgHt" <nospam@haha> wrote in message
> news:109r34ge5bhu4f5@corp.supernews.com...[color=green]
> > Refresh doesn't send a paint message to the control. It's telling the
> > control to redraw itself.
> >
> >
> > " SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
> > news:O$vEa4VNEHA.3668@TK2MSFTNGP11.phx.gbl...[color=darkred]
> > > picDocument is a picturebox
> > >
> > > When I do picDocument.Invalidate() the box paints.
> > >
> > > But if instead I do picDocument.Refresh() the box does not paint.
> > >
> > > What does Refresh do. I guessed it did an Invalidate and an Update.
> > >
> > > Can someone shed some light?
> > >
> > >
> > >
> > >
> > >
> > > Thanks
> > >
> > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Jay B. Harlow [MVP - Outlook]
Guest
 
Posts: n/a
#11: Nov 20 '05

re: Invalidate() compared to Refresh()


Yes, I know what you mean about answering questions late at night...

Jay

"yEaH rIgHt" <nospam@haha> wrote in message
news:109seks9ffild86@corp.supernews.com...[color=blue]
> Jay, you're right. I made a stupid blunder. I had a button click event[/color]
with[color=blue]
> the ReFresh method in it but I was hitting the wrong button. I guess I
> shouldn't answer questions late at night. D'OH!!!
>
>
> "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
> news:eQAkezcNEHA.1388@TK2MSFTNGP09.phx.gbl...[color=green]
> > Yeah Right,
> > Are you certain?
> >[/color][/color]
<<snip>>


SamSpade
Guest
 
Posts: n/a
#12: Nov 20 '05

re: Invalidate() compared to Refresh()


Thanks for the info.


I had two statements, The Invalidate one and the Refresh one.
I'd comment one of them out and run.
Tried it a few times and it always painted with the Invalidate and never
with the Refresh.
So I wanted to be sure they worked as I thought.
Now that I know for sure I'll keep looking to see what else is happening to
confuse the issue.
It won't be the first time some seemly paradox got resolved.

Thanks again


"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
news:uzl1iucNEHA.1208@TK2MSFTNGP10.phx.gbl...[color=blue]
> SamSpade,
> Control.Refresh - does a Control.Invalidate immediately followed by
> Control.Update.
>
> Control.Invalidate - invalidates a specific region of the Control[/color]
(defaults[color=blue]
> to entire client area) and causes a paint message to be sent to the[/color]
control.[color=blue]
>
> Control.Update - causes the Paint event to occur immediately (Windows will
> normally wait until there are no other messages for the window to process,
> before raising the Paint event).
>
>
> Refresh can be overridden, have you overridden it to change its behavior?
>
>
> The paint event of course is where all the drawing of your PictureBox
> occurs. Note there is only one pending Paint event, if you call Invalidate[/color]
3[color=blue]
> times, you will still only receive one Paint event.
>
> Hope this helps
> Jay
>
> " SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
> news:O$vEa4VNEHA.3668@TK2MSFTNGP11.phx.gbl...[color=green]
> > picDocument is a picturebox
> >
> > When I do picDocument.Invalidate() the box paints.
> >
> > But if instead I do picDocument.Refresh() the box does not paint.
> >
> > What does Refresh do. I guessed it did an Invalidate and an Update.
> >
> > Can someone shed some light?
> >
> >
> >
> >
> >
> > Thanks
> >
> >
> >
> >[/color]
>
>[/color]


Jay B. Harlow [MVP - Outlook]
Guest
 
Posts: n/a
#13: Nov 20 '05

re: Invalidate() compared to Refresh()


SamSpade,
How are you "painting" on the PictureBox?

Does the following from the GDI+ FAQ help?
http://www.bobpowell.net/pictureboxhowto.htm

The GDI+ FAQ itself can be found at:
http://www.bobpowell.net/faqmain.htm

Rather then attempt to paint on a PictureBox, which is really designed to
display image files. I normally create a custom control that inherits
directly from Control or UserControl and do the painting in its Paint event
(OnPaint method really).

Are you flat out running your code or are you trying to single step it? Are
you on dual monitors so the debugger does not cause a repaint before the
Refresh itself causes the repaint?

Can you post a short 15-20 line program that fully demonstrates the problem
you are having?

Hope this helps
Jay


" SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
news:e8y651dNEHA.3052@TK2MSFTNGP12.phx.gbl...[color=blue]
> Thanks for the info.
>
>
> I had two statements, The Invalidate one and the Refresh one.
> I'd comment one of them out and run.
> Tried it a few times and it always painted with the Invalidate and never
> with the Refresh.
> So I wanted to be sure they worked as I thought.
> Now that I know for sure I'll keep looking to see what else is happening[/color]
to[color=blue]
> confuse the issue.
> It won't be the first time some seemly paradox got resolved.
>
> Thanks again
>
>
> "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
> news:uzl1iucNEHA.1208@TK2MSFTNGP10.phx.gbl...[color=green]
> > SamSpade,
> > Control.Refresh - does a Control.Invalidate immediately followed by
> > Control.Update.
> >
> > Control.Invalidate - invalidates a specific region of the Control[/color]
> (defaults[color=green]
> > to entire client area) and causes a paint message to be sent to the[/color]
> control.[color=green]
> >
> > Control.Update - causes the Paint event to occur immediately (Windows[/color][/color]
will[color=blue][color=green]
> > normally wait until there are no other messages for the window to[/color][/color]
process,[color=blue][color=green]
> > before raising the Paint event).
> >
> >
> > Refresh can be overridden, have you overridden it to change its[/color][/color]
behavior?[color=blue][color=green]
> >
> >
> > The paint event of course is where all the drawing of your PictureBox
> > occurs. Note there is only one pending Paint event, if you call[/color][/color]
Invalidate[color=blue]
> 3[color=green]
> > times, you will still only receive one Paint event.
> >
> > Hope this helps
> > Jay
> >
> > " SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
> > news:O$vEa4VNEHA.3668@TK2MSFTNGP11.phx.gbl...[color=darkred]
> > > picDocument is a picturebox
> > >
> > > When I do picDocument.Invalidate() the box paints.
> > >
> > > But if instead I do picDocument.Refresh() the box does not paint.
> > >
> > > What does Refresh do. I guessed it did an Invalidate and an Update.
> > >
> > > Can someone shed some light?
> > >
> > >
> > >
> > >
> > >
> > > Thanks
> > >
> > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


SamSpade
Guest
 
Posts: n/a
#14: Nov 20 '05

re: Invalidate() compared to Refresh()


Jay, You have given me much to think about. Before I answer your questions
I wonder about my basic design (which really came from a VB6 UserControl)
and want to thank you up front!

I have a UserControl which contains a Picturebox. I thus get picturebox that
scrolls. also if the control is larger than the box, the box is centered and
has a colored area around it.

If I drew directly on the Usercontrol how would I get scrollbars to appear.
Wouldn't the control just clip?

==================


To make the picturebox persistent I do not draw on it but rather draw on a
bitmap using a Graphics object obtained as follows:

Public Function PicCreateGraphics() As Graphics
'Client should dispose this
PicCreateGraphics = Graphics.FromImage(mDocumentImage)
End Function

and do:
Private Sub picDocument_Paint(ByVal sender As Object, ByVal e As--snip
e.Graphics.DrawImage(mDocumentImage, 0, 0)
-snip

Now I wonder if I couldn't just use the Picturebox's Image instead of an
additional bitmap.
Can't I draw on the Picturebox's Image like I now draw on the bitmap?
And to get presistance do:
e.Graphics.DrawImage(mMyPicturebox.Image, 0, 0)
=======================

The only nonControl thing I use from the PictureBox is the Image.
The following is an example (picDocument is the Picturebox):
Public Sub PSet(ByVal x As Integer, ByVal y As Integer, ByVal NewColor As
Color)
CType(picDocument.Image, Drawing.Bitmap).SetPixel(PixelToUnitX(x),
PixelToUnitY(y), NewColor)
End Sub
Haven't used this yet but how would I do this if I used a Control instead
of a Picturebox?
====
I read some of the stuff at the bobpowell site and will read more. Thanks
for showing me that.





"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
news:%23U4%239NfNEHA.640@TK2MSFTNGP12.phx.gbl...[color=blue]
> SamSpade,
> How are you "painting" on the PictureBox?
>
> Does the following from the GDI+ FAQ help?
> http://www.bobpowell.net/pictureboxhowto.htm
>
> The GDI+ FAQ itself can be found at:
> http://www.bobpowell.net/faqmain.htm
>
> Rather then attempt to paint on a PictureBox, which is really designed to
> display image files. I normally create a custom control that inherits
> directly from Control or UserControl and do the painting in its Paint[/color]
event[color=blue]
> (OnPaint method really).
>
> Are you flat out running your code or are you trying to single step it?[/color]
Are[color=blue]
> you on dual monitors so the debugger does not cause a repaint before the
> Refresh itself causes the repaint?[/color]

Single stepping with single montior - never gave this a thought!
[color=blue]
>
> Can you post a short 15-20 line program that fully demonstrates the[/color]
problem[color=blue]
> you are having?[/color]

I looked and think it would have to be quite long.
[color=blue]
>
> Hope this helps[/color]

Much
[color=blue]
> Jay
>
>
> " SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
> news:e8y651dNEHA.3052@TK2MSFTNGP12.phx.gbl...[color=green]
> > Thanks for the info.
> >
> >
> > I had two statements, The Invalidate one and the Refresh one.
> > I'd comment one of them out and run.
> > Tried it a few times and it always painted with the Invalidate and never
> > with the Refresh.
> > So I wanted to be sure they worked as I thought.
> > Now that I know for sure I'll keep looking to see what else is happening[/color]
> to[color=green]
> > confuse the issue.
> > It won't be the first time some seemly paradox got resolved.
> >
> > Thanks again
> >
> >
> > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in[/color][/color]
message[color=blue][color=green]
> > news:uzl1iucNEHA.1208@TK2MSFTNGP10.phx.gbl...[color=darkred]
> > > SamSpade,
> > > Control.Refresh - does a Control.Invalidate immediately followed by
> > > Control.Update.
> > >
> > > Control.Invalidate - invalidates a specific region of the Control[/color]
> > (defaults[color=darkred]
> > > to entire client area) and causes a paint message to be sent to the[/color]
> > control.[color=darkred]
> > >
> > > Control.Update - causes the Paint event to occur immediately (Windows[/color][/color]
> will[color=green][color=darkred]
> > > normally wait until there are no other messages for the window to[/color][/color]
> process,[color=green][color=darkred]
> > > before raising the Paint event).
> > >
> > >
> > > Refresh can be overridden, have you overridden it to change its[/color][/color]
> behavior?[color=green][color=darkred]
> > >
> > >
> > > The paint event of course is where all the drawing of your PictureBox
> > > occurs. Note there is only one pending Paint event, if you call[/color][/color]
> Invalidate[color=green]
> > 3[color=darkred]
> > > times, you will still only receive one Paint event.
> > >
> > > Hope this helps
> > > Jay
> > >
> > > " SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
> > > news:O$vEa4VNEHA.3668@TK2MSFTNGP11.phx.gbl...
> > > > picDocument is a picturebox
> > > >
> > > > When I do picDocument.Invalidate() the box paints.
> > > >
> > > > But if instead I do picDocument.Refresh() the box does not paint.
> > > >
> > > > What does Refresh do. I guessed it did an Invalidate and an Update.
> > > >
> > > > Can someone shed some light?
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Thanks
> > > >
> > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Jay B. Harlow [MVP - Outlook]
Guest
 
Posts: n/a
#15: Nov 20 '05

re: Invalidate() compared to Refresh()


SamSpade,
If you are drawing on an Image, then you are painting this image on the
PictureBox you should be OK. this is a form of double buffering...

UserControl inherits from ScrollableControl. Which means you can make the
"drawing" surface larger then the "display" surface.

I don't have a simple example right now. Basically setting
ScrollableControl.AutoScroll to true and setting
ScrollableControl.AutoScrollMinSize to the size of your "drawing" surface
will cause the UserControl to scroll your "drawing" surface. You can then
simply draw using the Graphics object passed in the Paint event, of course
this will not support "PSet", I would use a 1x1 bitmap or a Line 1 pixel
long if I really needed "PSet".

I normally check the clipping area of the Graphics object so I only paint
the part of the control, that is visible & that needs to be redrawn, rather
then redraw the entire "drawing" surface.

If you are using a PictureBox, why paint the Image, why not just set the
PictureBox.Image property to the image you are painting?

Hope this helps
Jay


" SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
news:%23lWdELnNEHA.3452@TK2MSFTNGP10.phx.gbl...[color=blue]
> Jay, You have given me much to think about. Before I answer your[/color]
questions[color=blue]
> I wonder about my basic design (which really came from a VB6 UserControl)
> and want to thank you up front!
>
> I have a UserControl which contains a Picturebox. I thus get picturebox[/color]
that[color=blue]
> scrolls. also if the control is larger than the box, the box is centered[/color]
and[color=blue]
> has a colored area around it.
>
> If I drew directly on the Usercontrol how would I get scrollbars to[/color]
appear.[color=blue]
> Wouldn't the control just clip?
>
> ==================
>
>
> To make the picturebox persistent I do not draw on it but rather draw on a
> bitmap using a Graphics object obtained as follows:
>
> Public Function PicCreateGraphics() As Graphics
> 'Client should dispose this
> PicCreateGraphics = Graphics.FromImage(mDocumentImage)
> End Function
>
> and do:
> Private Sub picDocument_Paint(ByVal sender As Object, ByVal e As--snip
> e.Graphics.DrawImage(mDocumentImage, 0, 0)
> -snip
>
> Now I wonder if I couldn't just use the Picturebox's Image instead of an
> additional bitmap.
> Can't I draw on the Picturebox's Image like I now draw on the bitmap?
> And to get presistance do:
> e.Graphics.DrawImage(mMyPicturebox.Image, 0, 0)
> =======================
>
> The only nonControl thing I use from the PictureBox is the Image.
> The following is an example (picDocument is the Picturebox):
> Public Sub PSet(ByVal x As Integer, ByVal y As Integer, ByVal NewColor As
> Color)
> CType(picDocument.Image, Drawing.Bitmap).SetPixel(PixelToUnitX(x),
> PixelToUnitY(y), NewColor)
> End Sub
> Haven't used this yet but how would I do this if I used a Control instead
> of a Picturebox?
> ====
> I read some of the stuff at the bobpowell site and will read more. Thanks
> for showing me that.
>
>
>
>
>
> "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
> news:%23U4%239NfNEHA.640@TK2MSFTNGP12.phx.gbl...[color=green]
> > SamSpade,
> > How are you "painting" on the PictureBox?
> >
> > Does the following from the GDI+ FAQ help?
> > http://www.bobpowell.net/pictureboxhowto.htm
> >
> > The GDI+ FAQ itself can be found at:
> > http://www.bobpowell.net/faqmain.htm
> >
> > Rather then attempt to paint on a PictureBox, which is really designed[/color][/color]
to[color=blue][color=green]
> > display image files. I normally create a custom control that inherits
> > directly from Control or UserControl and do the painting in its Paint[/color]
> event[color=green]
> > (OnPaint method really).
> >
> > Are you flat out running your code or are you trying to single step it?[/color]
> Are[color=green]
> > you on dual monitors so the debugger does not cause a repaint before the
> > Refresh itself causes the repaint?[/color]
>
> Single stepping with single montior - never gave this a thought!
>[color=green]
> >
> > Can you post a short 15-20 line program that fully demonstrates the[/color]
> problem[color=green]
> > you are having?[/color]
>
> I looked and think it would have to be quite long.
>[color=green]
> >
> > Hope this helps[/color]
>
> Much
>[color=green]
> > Jay
> >
> >
> > " SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
> > news:e8y651dNEHA.3052@TK2MSFTNGP12.phx.gbl...[color=darkred]
> > > Thanks for the info.
> > >
> > >
> > > I had two statements, The Invalidate one and the Refresh one.
> > > I'd comment one of them out and run.
> > > Tried it a few times and it always painted with the Invalidate and[/color][/color][/color]
never[color=blue][color=green][color=darkred]
> > > with the Refresh.
> > > So I wanted to be sure they worked as I thought.
> > > Now that I know for sure I'll keep looking to see what else is[/color][/color][/color]
happening[color=blue][color=green]
> > to[color=darkred]
> > > confuse the issue.
> > > It won't be the first time some seemly paradox got resolved.
> > >
> > > Thanks again
> > >
> > >
> > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in[/color][/color]
> message[color=green][color=darkred]
> > > news:uzl1iucNEHA.1208@TK2MSFTNGP10.phx.gbl...
> > > > SamSpade,
> > > > Control.Refresh - does a Control.Invalidate immediately followed by
> > > > Control.Update.
> > > >
> > > > Control.Invalidate - invalidates a specific region of the Control
> > > (defaults
> > > > to entire client area) and causes a paint message to be sent to the
> > > control.
> > > >
> > > > Control.Update - causes the Paint event to occur immediately[/color][/color][/color]
(Windows[color=blue][color=green]
> > will[color=darkred]
> > > > normally wait until there are no other messages for the window to[/color]
> > process,[color=darkred]
> > > > before raising the Paint event).
> > > >
> > > >
> > > > Refresh can be overridden, have you overridden it to change its[/color]
> > behavior?[color=darkred]
> > > >
> > > >
> > > > The paint event of course is where all the drawing of your[/color][/color][/color]
PictureBox[color=blue][color=green][color=darkred]
> > > > occurs. Note there is only one pending Paint event, if you call[/color]
> > Invalidate[color=darkred]
> > > 3
> > > > times, you will still only receive one Paint event.
> > > >
> > > > Hope this helps
> > > > Jay
> > > >
> > > > " SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
> > > > news:O$vEa4VNEHA.3668@TK2MSFTNGP11.phx.gbl...
> > > > > picDocument is a picturebox
> > > > >
> > > > > When I do picDocument.Invalidate() the box paints.
> > > > >
> > > > > But if instead I do picDocument.Refresh() the box does not paint.
> > > > >
> > > > > What does Refresh do. I guessed it did an Invalidate and an[/color][/color][/color]
Update.[color=blue][color=green][color=darkred]
> > > > >
> > > > > Can someone shed some light?
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Thanks
> > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


SamSpade
Guest
 
Posts: n/a
#16: Nov 20 '05

re: Invalidate() compared to Refresh()


Thanks for taking so much time to help. I don't have a lot of insight into
this but I will after I try what you suggested. If I understand I do not
need the PictureBox on the usercontrol - instead I can simply control the
UserControls "drawing" surface.

But how should I get persistence. Should I still draw on a Bitmap and in
Paint used DrawImage to place it on the drawing surface?

Thanks again


"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
news:e3DLXppNEHA.556@tk2msftngp13.phx.gbl...[color=blue]
> SamSpade,
> If you are drawing on an Image, then you are painting this image on the
> PictureBox you should be OK. this is a form of double buffering...
>
> UserControl inherits from ScrollableControl. Which means you can make the
> "drawing" surface larger then the "display" surface.
>
> I don't have a simple example right now. Basically setting
> ScrollableControl.AutoScroll to true and setting
> ScrollableControl.AutoScrollMinSize to the size of your "drawing" surface
> will cause the UserControl to scroll your "drawing" surface. You can then
> simply draw using the Graphics object passed in the Paint event, of course
> this will not support "PSet", I would use a 1x1 bitmap or a Line 1 pixel
> long if I really needed "PSet".
>
> I normally check the clipping area of the Graphics object so I only paint
> the part of the control, that is visible & that needs to be redrawn,[/color]
rather[color=blue]
> then redraw the entire "drawing" surface.
>
> If you are using a PictureBox, why paint the Image, why not just set the
> PictureBox.Image property to the image you are painting?
>
> Hope this helps
> Jay
>
>
> " SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
> news:%23lWdELnNEHA.3452@TK2MSFTNGP10.phx.gbl...[color=green]
> > Jay, You have given me much to think about. Before I answer your[/color]
> questions[color=green]
> > I wonder about my basic design (which really came from a VB6[/color][/color]
UserControl)[color=blue][color=green]
> > and want to thank you up front!
> >
> > I have a UserControl which contains a Picturebox. I thus get picturebox[/color]
> that[color=green]
> > scrolls. also if the control is larger than the box, the box is centered[/color]
> and[color=green]
> > has a colored area around it.
> >
> > If I drew directly on the Usercontrol how would I get scrollbars to[/color]
> appear.[color=green]
> > Wouldn't the control just clip?
> >
> > ==================
> >
> >
> > To make the picturebox persistent I do not draw on it but rather draw on[/color][/color]
a[color=blue][color=green]
> > bitmap using a Graphics object obtained as follows:
> >
> > Public Function PicCreateGraphics() As Graphics
> > 'Client should dispose this
> > PicCreateGraphics = Graphics.FromImage(mDocumentImage)
> > End Function
> >
> > and do:
> > Private Sub picDocument_Paint(ByVal sender As Object, ByVal e As--snip
> > e.Graphics.DrawImage(mDocumentImage, 0, 0)
> > -snip
> >
> > Now I wonder if I couldn't just use the Picturebox's Image instead of an
> > additional bitmap.
> > Can't I draw on the Picturebox's Image like I now draw on the bitmap?
> > And to get presistance do:
> > e.Graphics.DrawImage(mMyPicturebox.Image, 0, 0)
> > =======================
> >
> > The only nonControl thing I use from the PictureBox is the Image.
> > The following is an example (picDocument is the Picturebox):
> > Public Sub PSet(ByVal x As Integer, ByVal y As Integer, ByVal NewColor[/color][/color]
As[color=blue][color=green]
> > Color)
> > CType(picDocument.Image, Drawing.Bitmap).SetPixel(PixelToUnitX(x),
> > PixelToUnitY(y), NewColor)
> > End Sub
> > Haven't used this yet but how would I do this if I used a Control[/color][/color]
instead[color=blue][color=green]
> > of a Picturebox?
> > ====
> > I read some of the stuff at the bobpowell site and will read more.[/color][/color]
Thanks[color=blue][color=green]
> > for showing me that.
> >
> >
> >
> >
> >
> > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in[/color][/color]
message[color=blue][color=green]
> > news:%23U4%239NfNEHA.640@TK2MSFTNGP12.phx.gbl...[color=darkred]
> > > SamSpade,
> > > How are you "painting" on the PictureBox?
> > >
> > > Does the following from the GDI+ FAQ help?
> > > http://www.bobpowell.net/pictureboxhowto.htm
> > >
> > > The GDI+ FAQ itself can be found at:
> > > http://www.bobpowell.net/faqmain.htm
> > >
> > > Rather then attempt to paint on a PictureBox, which is really designed[/color][/color]
> to[color=green][color=darkred]
> > > display image files. I normally create a custom control that inherits
> > > directly from Control or UserControl and do the painting in its Paint[/color]
> > event[color=darkred]
> > > (OnPaint method really).
> > >
> > > Are you flat out running your code or are you trying to single step[/color][/color][/color]
it?[color=blue][color=green]
> > Are[color=darkred]
> > > you on dual monitors so the debugger does not cause a repaint before[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > Refresh itself causes the repaint?[/color]
> >
> > Single stepping with single montior - never gave this a thought!
> >[color=darkred]
> > >
> > > Can you post a short 15-20 line program that fully demonstrates the[/color]
> > problem[color=darkred]
> > > you are having?[/color]
> >
> > I looked and think it would have to be quite long.
> >[color=darkred]
> > >
> > > Hope this helps[/color]
> >
> > Much
> >[color=darkred]
> > > Jay
> > >
> > >
> > > " SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
> > > news:e8y651dNEHA.3052@TK2MSFTNGP12.phx.gbl...
> > > > Thanks for the info.
> > > >
> > > >
> > > > I had two statements, The Invalidate one and the Refresh one.
> > > > I'd comment one of them out and run.
> > > > Tried it a few times and it always painted with the Invalidate and[/color][/color]
> never[color=green][color=darkred]
> > > > with the Refresh.
> > > > So I wanted to be sure they worked as I thought.
> > > > Now that I know for sure I'll keep looking to see what else is[/color][/color]
> happening[color=green][color=darkred]
> > > to
> > > > confuse the issue.
> > > > It won't be the first time some seemly paradox got resolved.
> > > >
> > > > Thanks again
> > > >
> > > >
> > > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in[/color]
> > message[color=darkred]
> > > > news:uzl1iucNEHA.1208@TK2MSFTNGP10.phx.gbl...
> > > > > SamSpade,
> > > > > Control.Refresh - does a Control.Invalidate immediately followed[/color][/color][/color]
by[color=blue][color=green][color=darkred]
> > > > > Control.Update.
> > > > >
> > > > > Control.Invalidate - invalidates a specific region of the Control
> > > > (defaults
> > > > > to entire client area) and causes a paint message to be sent to[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > > control.
> > > > >
> > > > > Control.Update - causes the Paint event to occur immediately[/color][/color]
> (Windows[color=green][color=darkred]
> > > will
> > > > > normally wait until there are no other messages for the window to
> > > process,
> > > > > before raising the Paint event).
> > > > >
> > > > >
> > > > > Refresh can be overridden, have you overridden it to change its
> > > behavior?
> > > > >
> > > > >
> > > > > The paint event of course is where all the drawing of your[/color][/color]
> PictureBox[color=green][color=darkred]
> > > > > occurs. Note there is only one pending Paint event, if you call
> > > Invalidate
> > > > 3
> > > > > times, you will still only receive one Paint event.
> > > > >
> > > > > Hope this helps
> > > > > Jay
> > > > >
> > > > > " SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
> > > > > news:O$vEa4VNEHA.3668@TK2MSFTNGP11.phx.gbl...
> > > > > > picDocument is a picturebox
> > > > > >
> > > > > > When I do picDocument.Invalidate() the box paints.
> > > > > >
> > > > > > But if instead I do picDocument.Refresh() the box does not[/color][/color][/color]
paint.[color=blue][color=green][color=darkred]
> > > > > >
> > > > > > What does Refresh do. I guessed it did an Invalidate and an[/color][/color]
> Update.[color=green][color=darkred]
> > > > > >
> > > > > > Can someone shed some light?
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Thanks
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Jay B. Harlow [MVP - Outlook]
Guest
 
Posts: n/a
#17: Nov 20 '05

re: Invalidate() compared to Refresh()


SamSpade,
If you need persistence in the form of an image file, then yes it might be
easier to draw on the image first, then use DrawImage in the Paint event.

Which actually simplifies the example ;-)

In your user control's constructor you should use the following:
' Stop the flicker
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.UpdateStyles()

In your user control you can add the following:

Private m_image As Image

Public Property Image() As Image
Get
Return m_image
End Get
Set(ByVal value As Image)
m_image = value
If value Is Nothing Then
Me.AutoScrollMinSize = Size.Empty
Else
Me.AutoScrollMinSize = m_image.Size
End If
End Set
End Property

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
If Image Is Nothing Then Exit Sub
e.Graphics.DrawImage(m_image, 0, 0)
End Sub

In my main form I have

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
MyBase.OnLoad(e)
Dim image As New Bitmap(600, 600)
Dim gr As Graphics = Graphics.FromImage(image)
Dim pageUnit As GraphicsUnit = gr.PageUnit
Dim bounds As RectangleF = image.GetBounds(pageUnit)
gr.FillRectangle(Brushes.White, bounds)
For x As Integer = 0 To 600 Step 25
For y As Integer = 0 To 600 Step 25
gr.DrawLine(Pens.Blue, x, 0, x, y)
gr.DrawLine(Pens.Blue, 0, y, x, y)
Next
Next
gr.Dispose()
Me.SamSpadeControl1.Image = image
End Sub

However! I am missing something as scrolling the image is not repainting it
nicely. I don't see what I am missing from my larger sample, as I thought I
fixed my control from doing that ;-)

Hope this helps
Jay


" SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
news:u$9sl$pNEHA.640@TK2MSFTNGP12.phx.gbl...[color=blue]
> Thanks for taking so much time to help. I don't have a lot of insight into
> this but I will after I try what you suggested. If I understand I do not
> need the PictureBox on the usercontrol - instead I can simply control the
> UserControls "drawing" surface.
>
> But how should I get persistence. Should I still draw on a Bitmap and in
> Paint used DrawImage to place it on the drawing surface?
>
> Thanks again
>
>
> "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
> news:e3DLXppNEHA.556@tk2msftngp13.phx.gbl...[color=green]
> > SamSpade,
> > If you are drawing on an Image, then you are painting this image on the
> > PictureBox you should be OK. this is a form of double buffering...
> >
> > UserControl inherits from ScrollableControl. Which means you can make[/color][/color]
the[color=blue][color=green]
> > "drawing" surface larger then the "display" surface.
> >
> > I don't have a simple example right now. Basically setting
> > ScrollableControl.AutoScroll to true and setting
> > ScrollableControl.AutoScrollMinSize to the size of your "drawing"[/color][/color]
surface[color=blue][color=green]
> > will cause the UserControl to scroll your "drawing" surface. You can[/color][/color]
then[color=blue][color=green]
> > simply draw using the Graphics object passed in the Paint event, of[/color][/color]
course[color=blue][color=green]
> > this will not support "PSet", I would use a 1x1 bitmap or a Line 1 pixel
> > long if I really needed "PSet".
> >
> > I normally check the clipping area of the Graphics object so I only[/color][/color]
paint[color=blue][color=green]
> > the part of the control, that is visible & that needs to be redrawn,[/color]
> rather[color=green]
> > then redraw the entire "drawing" surface.
> >
> > If you are using a PictureBox, why paint the Image, why not just set the
> > PictureBox.Image property to the image you are painting?
> >
> > Hope this helps
> > Jay
> >
> >
> > " SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
> > news:%23lWdELnNEHA.3452@TK2MSFTNGP10.phx.gbl...[color=darkred]
> > > Jay, You have given me much to think about. Before I answer your[/color]
> > questions[color=darkred]
> > > I wonder about my basic design (which really came from a VB6[/color][/color]
> UserControl)[color=green][color=darkred]
> > > and want to thank you up front!
> > >
> > > I have a UserControl which contains a Picturebox. I thus get[/color][/color][/color]
picturebox[color=blue][color=green]
> > that[color=darkred]
> > > scrolls. also if the control is larger than the box, the box is[/color][/color][/color]
centered[color=blue][color=green]
> > and[color=darkred]
> > > has a colored area around it.
> > >
> > > If I drew directly on the Usercontrol how would I get scrollbars to[/color]
> > appear.[color=darkred]
> > > Wouldn't the control just clip?
> > >
> > > ==================
> > >
> > >
> > > To make the picturebox persistent I do not draw on it but rather draw[/color][/color][/color]
on[color=blue]
> a[color=green][color=darkred]
> > > bitmap using a Graphics object obtained as follows:
> > >
> > > Public Function PicCreateGraphics() As Graphics
> > > 'Client should dispose this
> > > PicCreateGraphics = Graphics.FromImage(mDocumentImage)
> > > End Function
> > >
> > > and do:
> > > Private Sub picDocument_Paint(ByVal sender As Object, ByVal e As--snip
> > > e.Graphics.DrawImage(mDocumentImage, 0, 0)
> > > -snip
> > >
> > > Now I wonder if I couldn't just use the Picturebox's Image instead of[/color][/color][/color]
an[color=blue][color=green][color=darkred]
> > > additional bitmap.
> > > Can't I draw on the Picturebox's Image like I now draw on the bitmap?
> > > And to get presistance do:
> > > e.Graphics.DrawImage(mMyPicturebox.Image, 0, 0)
> > > =======================
> > >
> > > The only nonControl thing I use from the PictureBox is the Image.
> > > The following is an example (picDocument is the Picturebox):
> > > Public Sub PSet(ByVal x As Integer, ByVal y As Integer, ByVal NewColor[/color][/color]
> As[color=green][color=darkred]
> > > Color)
> > > CType(picDocument.Image, Drawing.Bitmap).SetPixel(PixelToUnitX(x),
> > > PixelToUnitY(y), NewColor)
> > > End Sub
> > > Haven't used this yet but how would I do this if I used a Control[/color][/color]
> instead[color=green][color=darkred]
> > > of a Picturebox?
> > > ====
> > > I read some of the stuff at the bobpowell site and will read more.[/color][/color]
> Thanks[color=green][color=darkred]
> > > for showing me that.
> > >
> > >
> > >
> > >
> > >
> > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in[/color][/color]
> message[color=green][color=darkred]
> > > news:%23U4%239NfNEHA.640@TK2MSFTNGP12.phx.gbl...
> > > > SamSpade,
> > > > How are you "painting" on the PictureBox?
> > > >
> > > > Does the following from the GDI+ FAQ help?
> > > > http://www.bobpowell.net/pictureboxhowto.htm
> > > >
> > > > The GDI+ FAQ itself can be found at:
> > > > http://www.bobpowell.net/faqmain.htm
> > > >
> > > > Rather then attempt to paint on a PictureBox, which is really[/color][/color][/color]
designed[color=blue][color=green]
> > to[color=darkred]
> > > > display image files. I normally create a custom control that[/color][/color][/color]
inherits[color=blue][color=green][color=darkred]
> > > > directly from Control or UserControl and do the painting in its[/color][/color][/color]
Paint[color=blue][color=green][color=darkred]
> > > event
> > > > (OnPaint method really).
> > > >
> > > > Are you flat out running your code or are you trying to single step[/color][/color]
> it?[color=green][color=darkred]
> > > Are
> > > > you on dual monitors so the debugger does not cause a repaint before[/color][/color]
> the[color=green][color=darkred]
> > > > Refresh itself causes the repaint?
> > >
> > > Single stepping with single montior - never gave this a thought!
> > >
> > > >
> > > > Can you post a short 15-20 line program that fully demonstrates the
> > > problem
> > > > you are having?
> > >
> > > I looked and think it would have to be quite long.
> > >
> > > >
> > > > Hope this helps
> > >
> > > Much
> > >
> > > > Jay
> > > >
> > > >
> > > > " SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
> > > > news:e8y651dNEHA.3052@TK2MSFTNGP12.phx.gbl...
> > > > > Thanks for the info.
> > > > >
> > > > >
> > > > > I had two statements, The Invalidate one and the Refresh one.
> > > > > I'd comment one of them out and run.
> > > > > Tried it a few times and it always painted with the Invalidate and[/color]
> > never[color=darkred]
> > > > > with the Refresh.
> > > > > So I wanted to be sure they worked as I thought.
> > > > > Now that I know for sure I'll keep looking to see what else is[/color]
> > happening[color=darkred]
> > > > to
> > > > > confuse the issue.
> > > > > It won't be the first time some seemly paradox got resolved.
> > > > >
> > > > > Thanks again
> > > > >
> > > > >
> > > > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in
> > > message
> > > > > news:uzl1iucNEHA.1208@TK2MSFTNGP10.phx.gbl...
> > > > > > SamSpade,
> > > > > > Control.Refresh - does a Control.Invalidate immediately followed[/color][/color]
> by[color=green][color=darkred]
> > > > > > Control.Update.
> > > > > >
> > > > > > Control.Invalidate - invalidates a specific region of the[/color][/color][/color]
Control[color=blue][color=green][color=darkred]
> > > > > (defaults
> > > > > > to entire client area) and causes a paint message to be sent to[/color][/color]
> the[color=green][color=darkred]
> > > > > control.
> > > > > >
> > > > > > Control.Update - causes the Paint event to occur immediately[/color]
> > (Windows[color=darkred]
> > > > will
> > > > > > normally wait until there are no other messages for the window[/color][/color][/color]
to[color=blue][color=green][color=darkred]
> > > > process,
> > > > > > before raising the Paint event).
> > > > > >
> > > > > >
> > > > > > Refresh can be overridden, have you overridden it to change its
> > > > behavior?
> > > > > >
> > > > > >
> > > > > > The paint event of course is where all the drawing of your[/color]
> > PictureBox[color=darkred]
> > > > > > occurs. Note there is only one pending Paint event, if you call
> > > > Invalidate
> > > > > 3
> > > > > > times, you will still only receive one Paint event.
> > > > > >
> > > > > > Hope this helps
> > > > > > Jay
> > > > > >
> > > > > > " SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
> > > > > > news:O$vEa4VNEHA.3668@TK2MSFTNGP11.phx.gbl...
> > > > > > > picDocument is a picturebox
> > > > > > >
> > > > > > > When I do picDocument.Invalidate() the box paints.
> > > > > > >
> > > > > > > But if instead I do picDocument.Refresh() the box does not[/color][/color]
> paint.[color=green][color=darkred]
> > > > > > >
> > > > > > > What does Refresh do. I guessed it did an Invalidate and an[/color]
> > Update.[color=darkred]
> > > > > > >
> > > > > > > Can someone shed some light?
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Thanks
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


SamSpade
Guest
 
Posts: n/a
#18: Nov 20 '05

re: Invalidate() compared to Refresh()


Thanks a lot. You won't hear from me for a while because I need to study
all you've given me. Much of it is new to me.


"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
news:O6SDqUqNEHA.3668@TK2MSFTNGP11.phx.gbl...[color=blue]
> SamSpade,
> If you need persistence in the form of an image file, then yes it might be
> easier to draw on the image first, then use DrawImage in the Paint event.
>
> Which actually simplifies the example ;-)
>
> In your user control's constructor you should use the following:
> ' Stop the flicker
> Me.SetStyle(ControlStyles.UserPaint, True)
> Me.SetStyle(ControlStyles.DoubleBuffer, True)
> Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
> Me.SetStyle(ControlStyles.ResizeRedraw, True)
> Me.UpdateStyles()
>
> In your user control you can add the following:
>
> Private m_image As Image
>
> Public Property Image() As Image
> Get
> Return m_image
> End Get
> Set(ByVal value As Image)
> m_image = value
> If value Is Nothing Then
> Me.AutoScrollMinSize = Size.Empty
> Else
> Me.AutoScrollMinSize = m_image.Size
> End If
> End Set
> End Property
>
> Protected Overrides Sub OnPaint(ByVal e As
> System.Windows.Forms.PaintEventArgs)
> MyBase.OnPaint(e)
> If Image Is Nothing Then Exit Sub
> e.Graphics.DrawImage(m_image, 0, 0)
> End Sub
>
> In my main form I have
>
> Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
> MyBase.OnLoad(e)
> Dim image As New Bitmap(600, 600)
> Dim gr As Graphics = Graphics.FromImage(image)
> Dim pageUnit As GraphicsUnit = gr.PageUnit
> Dim bounds As RectangleF = image.GetBounds(pageUnit)
> gr.FillRectangle(Brushes.White, bounds)
> For x As Integer = 0 To 600 Step 25
> For y As Integer = 0 To 600 Step 25
> gr.DrawLine(Pens.Blue, x, 0, x, y)
> gr.DrawLine(Pens.Blue, 0, y, x, y)
> Next
> Next
> gr.Dispose()
> Me.SamSpadeControl1.Image = image
> End Sub
>
> However! I am missing something as scrolling the image is not repainting[/color]
it[color=blue]
> nicely. I don't see what I am missing from my larger sample, as I thought[/color]
I[color=blue]
> fixed my control from doing that ;-)
>
> Hope this helps
> Jay
>
>
> " SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
> news:u$9sl$pNEHA.640@TK2MSFTNGP12.phx.gbl...[color=green]
> > Thanks for taking so much time to help. I don't have a lot of insight[/color][/color]
into[color=blue][color=green]
> > this but I will after I try what you suggested. If I understand I do[/color][/color]
not[color=blue][color=green]
> > need the PictureBox on the usercontrol - instead I can simply control[/color][/color]
the[color=blue][color=green]
> > UserControls "drawing" surface.
> >
> > But how should I get persistence. Should I still draw on a Bitmap and in
> > Paint used DrawImage to place it on the drawing surface?
> >
> > Thanks again
> >
> >
> > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in[/color][/color]
message[color=blue][color=green]
> > news:e3DLXppNEHA.556@tk2msftngp13.phx.gbl...[color=darkred]
> > > SamSpade,
> > > If you are drawing on an Image, then you are painting this image on[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > PictureBox you should be OK. this is a form of double buffering...
> > >
> > > UserControl inherits from ScrollableControl. Which means you can make[/color][/color]
> the[color=green][color=darkred]
> > > "drawing" surface larger then the "display" surface.
> > >
> > > I don't have a simple example right now. Basically setting
> > > ScrollableControl.AutoScroll to true and setting
> > > ScrollableControl.AutoScrollMinSize to the size of your "drawing"[/color][/color]
> surface[color=green][color=darkred]
> > > will cause the UserControl to scroll your "drawing" surface. You can[/color][/color]
> then[color=green][color=darkred]
> > > simply draw using the Graphics object passed in the Paint event, of[/color][/color]
> course[color=green][color=darkred]
> > > this will not support "PSet", I would use a 1x1 bitmap or a Line 1[/color][/color][/color]
pixel[color=blue][color=green][color=darkred]
> > > long if I really needed "PSet".
> > >
> > > I normally check the clipping area of the Graphics object so I only[/color][/color]
> paint[color=green][color=darkred]
> > > the part of the control, that is visible & that needs to be redrawn,[/color]
> > rather[color=darkred]
> > > then redraw the entire "drawing" surface.
> > >
> > > If you are using a PictureBox, why paint the Image, why not just set[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > PictureBox.Image property to the image you are painting?
> > >
> > > Hope this helps
> > > Jay
> > >
> > >
> > > " SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
> > > news:%23lWdELnNEHA.3452@TK2MSFTNGP10.phx.gbl...
> > > > Jay, You have given me much to think about. Before I answer your
> > > questions
> > > > I wonder about my basic design (which really came from a VB6[/color]
> > UserControl)[color=darkred]
> > > > and want to thank you up front!
> > > >
> > > > I have a UserControl which contains a Picturebox. I thus get[/color][/color]
> picturebox[color=green][color=darkred]
> > > that
> > > > scrolls. also if the control is larger than the box, the box is[/color][/color]
> centered[color=green][color=darkred]
> > > and
> > > > has a colored area around it.
> > > >
> > > > If I drew directly on the Usercontrol how would I get scrollbars to
> > > appear.
> > > > Wouldn't the control just clip?
> > > >
> > > > ==================
> > > >
> > > >
> > > > To make the picturebox persistent I do not draw on it but rather[/color][/color][/color]
draw[color=blue]
> on[color=green]
> > a[color=darkred]
> > > > bitmap using a Graphics object obtained as follows:
> > > >
> > > > Public Function PicCreateGraphics() As Graphics
> > > > 'Client should dispose this
> > > > PicCreateGraphics = Graphics.FromImage(mDocumentImage)
> > > > End Function
> > > >
> > > > and do:
> > > > Private Sub picDocument_Paint(ByVal sender As Object, ByVal e[/color][/color][/color]
As--snip[color=blue][color=green][color=darkred]
> > > > e.Graphics.DrawImage(mDocumentImage, 0, 0)
> > > > -snip
> > > >
> > > > Now I wonder if I couldn't just use the Picturebox's Image instead[/color][/color][/color]
of[color=blue]
> an[color=green][color=darkred]
> > > > additional bitmap.
> > > > Can't I draw on the Picturebox's Image like I now draw on the[/color][/color][/color]
bitmap?[color=blue][color=green][color=darkred]
> > > > And to get presistance do:
> > > > e.Graphics.DrawImage(mMyPicturebox.Image, 0, 0)
> > > > =======================
> > > >
> > > > The only nonControl thing I use from the PictureBox is the Image.
> > > > The following is an example (picDocument is the Picturebox):
> > > > Public Sub PSet(ByVal x As Integer, ByVal y As Integer, ByVal[/color][/color][/color]
NewColor[color=blue][color=green]
> > As[color=darkred]
> > > > Color)
> > > > CType(picDocument.Image,[/color][/color][/color]
Drawing.Bitmap).SetPixel(PixelToUnitX(x),[color=blue][color=green][color=darkred]
> > > > PixelToUnitY(y), NewColor)
> > > > End Sub
> > > > Haven't used this yet but how would I do this if I used a Control[/color]
> > instead[color=darkred]
> > > > of a Picturebox?
> > > > ====
> > > > I read some of the stuff at the bobpowell site and will read more.[/color]
> > Thanks[color=darkred]
> > > > for showing me that.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in[/color]
> > message[color=darkred]
> > > > news:%23U4%239NfNEHA.640@TK2MSFTNGP12.phx.gbl...
> > > > > SamSpade,
> > > > > How are you "painting" on the PictureBox?
> > > > >
> > > > > Does the following from the GDI+ FAQ help?
> > > > > http://www.bobpowell.net/pictureboxhowto.htm
> > > > >
> > > > > The GDI+ FAQ itself can be found at:
> > > > > http://www.bobpowell.net/faqmain.htm
> > > > >
> > > > > Rather then attempt to paint on a PictureBox, which is really[/color][/color]
> designed[color=green][color=darkred]
> > > to
> > > > > display image files. I normally create a custom control that[/color][/color]
> inherits[color=green][color=darkred]
> > > > > directly from Control or UserControl and do the painting in its[/color][/color]
> Paint[color=green][color=darkred]
> > > > event
> > > > > (OnPaint method really).
> > > > >
> > > > > Are you flat out running your code or are you trying to single[/color][/color][/color]
step[color=blue][color=green]
> > it?[color=darkred]
> > > > Are
> > > > > you on dual monitors so the debugger does not cause a repaint[/color][/color][/color]
before[color=blue][color=green]
> > the[color=darkred]
> > > > > Refresh itself causes the repaint?
> > > >
> > > > Single stepping with single montior - never gave this a thought!
> > > >
> > > > >
> > > > > Can you post a short 15-20 line program that fully demonstrates[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > > problem
> > > > > you are having?
> > > >
> > > > I looked and think it would have to be quite long.
> > > >
> > > > >
> > > > > Hope this helps
> > > >
> > > > Much
> > > >
> > > > > Jay
> > > > >
> > > > >
> > > > > " SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
> > > > > news:e8y651dNEHA.3052@TK2MSFTNGP12.phx.gbl...
> > > > > > Thanks for the info.
> > > > > >
> > > > > >
> > > > > > I had two statements, The Invalidate one and the Refresh one.
> > > > > > I'd comment one of them out and run.
> > > > > > Tried it a few times and it always painted with the Invalidate[/color][/color][/color]
and[color=blue][color=green][color=darkred]
> > > never
> > > > > > with the Refresh.
> > > > > > So I wanted to be sure they worked as I thought.
> > > > > > Now that I know for sure I'll keep looking to see what else is
> > > happening
> > > > > to
> > > > > > confuse the issue.
> > > > > > It won't be the first time some seemly paradox got resolved.
> > > > > >
> > > > > > Thanks again
> > > > > >
> > > > > >
> > > > > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote[/color][/color][/color]
in[color=blue][color=green][color=darkred]
> > > > message
> > > > > > news:uzl1iucNEHA.1208@TK2MSFTNGP10.phx.gbl...
> > > > > > > SamSpade,
> > > > > > > Control.Refresh - does a Control.Invalidate immediately[/color][/color][/color]
followed[color=blue][color=green]
> > by[color=darkred]
> > > > > > > Control.Update.
> > > > > > >
> > > > > > > Control.Invalidate - invalidates a specific region of the[/color][/color]
> Control[color=green][color=darkred]
> > > > > > (defaults
> > > > > > > to entire client area) and causes a paint message to be sent[/color][/color][/color]
to[color=blue][color=green]
> > the[color=darkred]
> > > > > > control.
> > > > > > >
> > > > > > > Control.Update - causes the Paint event to occur immediately
> > > (Windows
> > > > > will
> > > > > > > normally wait until there are no other messages for the window[/color][/color]
> to[color=green][color=darkred]
> > > > > process,
> > > > > > > before raising the Paint event).
> > > > > > >
> > > > > > >
> > > > > > > Refresh can be overridden, have you overridden it to change[/color][/color][/color]
its[color=blue][color=green][color=darkred]
> > > > > behavior?
> > > > > > >
> > > > > > >
> > > > > > > The paint event of course is where all the drawing of your
> > > PictureBox
> > > > > > > occurs. Note there is only one pending Paint event, if you[/color][/color][/color]
call[color=blue][color=green][color=darkred]
> > > > > Invalidate
> > > > > > 3
> > > > > > > times, you will still only receive one Paint event.
> > > > > > >
> > > > > > > Hope this helps
> > > > > > > Jay
> > > > > > >
> > > > > > > " SamSpade" <stillprogramming@REMOVEaol.com> wrote in message
> > > > > > > news:O$vEa4VNEHA.3668@TK2MSFTNGP11.phx.gbl...
> > > > > > > > picDocument is a picturebox
> > > > > > > >
> > > > > > > > When I do picDocument.Invalidate() the box paints.
> > > > > > > >
> > > > > > > > But if instead I do picDocument.Refresh() the box does not[/color]
> > paint.[color=darkred]
> > > > > > > >
> > > > > > > > What does Refresh do. I guessed it did an Invalidate and an
> > > Update.
> > > > > > > >
> > > > > > > > Can someone shed some light?
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Thanks
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Closed Thread


Similar Visual Basic .NET bytes