472,348 Members | 1,236 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,348 software developers and data experts.

Invalidate() compared to Refresh()

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


Nov 20 '05 #1
17 8188
Refresh doesn't send a paint message to the control. It's telling the
control to redraw itself.
" SamSpade" <st**************@REMOVEaol.com> wrote in message
news:O$**************@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

Nov 20 '05 #2
* "yEaH rIgHt" <nospam@haha> scripsit:
Refresh doesn't send a paint message to the control. It's telling the
control to redraw itself.


What's the difference?

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

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
Refresh doesn't send a paint message to the control. It's telling the
control to redraw itself.


What's the difference?

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


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.

Nov 20 '05 #4
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" <st**************@REMOVEaol.com> wrote in message
news:O$**************@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

Nov 20 '05 #5
>By paint message I think he means paint event so sending a paint message
means raising the paint event.
That's what I meant. It doesn't raise an paint event for you to use.
" SamSpade" <st**************@REMOVEaol.com> wrote in message
news:Oy**************@TK2MSFTNGP12.phx.gbl...
Refresh doesn't send a paint message to the control. It's telling the
control to redraw itself.


What's the difference?

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


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.

Nov 20 '05 #6
If you know the answer then why don't you tell us, master?

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OT**************@TK2MSFTNGP11.phx.gbl...
* "yEaH rIgHt" <nospam@haha> scripsit:
Refresh doesn't send a paint message to the control. It's telling the
control to redraw itself.


What's the difference?

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

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #7
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:10*************@corp.supernews.com...
Refresh doesn't send a paint message to the control. It's telling the
control to redraw itself.
" SamSpade" <st**************@REMOVEaol.com> wrote in message
news:O$**************@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


Nov 20 '05 #8
* "yEaH rIgHt" <nospam@haha> scripsit:
If you know the answer then why don't you tell us, master?


Because Jay has already done it ;-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #9
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]" <Ja************@msn.com> wrote in message
news:eQ**************@TK2MSFTNGP09.phx.gbl...
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:10*************@corp.supernews.com...
Refresh doesn't send a paint message to the control. It's telling the
control to redraw itself.
" SamSpade" <st**************@REMOVEaol.com> wrote in message
news:O$**************@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



Nov 20 '05 #10
Yes, I know what you mean about answering questions late at night...

Jay

"yEaH rIgHt" <nospam@haha> wrote in message
news:10*************@corp.supernews.com...
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]" <Ja************@msn.com> wrote in message
news:eQ**************@TK2MSFTNGP09.phx.gbl...
Yeah Right,
Are you certain?

<<snip>>
Nov 20 '05 #11
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]" <Ja************@msn.com> wrote in message
news:uz**************@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 (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" <st**************@REMOVEaol.com> wrote in message
news:O$**************@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


Nov 20 '05 #12
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" <st**************@REMOVEaol.com> wrote in message
news:e8**************@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 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]" <Ja************@msn.com> wrote in message
news:uz**************@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 (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" <st**************@REMOVEaol.com> wrote in message
news:O$**************@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



Nov 20 '05 #13
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]" <Ja************@msn.com> wrote in message
news:%2*****************@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 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?
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" <st**************@REMOVEaol.com> wrote in message
news:e8**************@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 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]" <Ja************@msn.com> wrote in message
news:uz**************@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 (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" <st**************@REMOVEaol.com> wrote in message
news:O$**************@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
>
>
>
>



Nov 20 '05 #14
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" <st**************@REMOVEaol.com> wrote in message
news:%2****************@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 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]" <Ja************@msn.com> wrote in message
news:%2*****************@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 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?


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" <st**************@REMOVEaol.com> wrote in message
news:e8**************@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 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]" <Ja************@msn.com> wrote in message news:uz**************@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

(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" <st**************@REMOVEaol.com> wrote in message
> news:O$**************@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
> >
> >
> >
> >
>
>



Nov 20 '05 #15
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]" <Ja************@msn.com> wrote in message
news:e3*************@tk2msftngp13.phx.gbl...
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" <st**************@REMOVEaol.com> wrote in message
news:%2****************@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 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]" <Ja************@msn.com> wrote in message news:%2*****************@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 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?


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" <st**************@REMOVEaol.com> wrote in message
news:e8**************@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

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]" <Ja************@msn.com> wrote in

message
> news:uz**************@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 (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" <st**************@REMOVEaol.com> wrote in message
> > news:O$**************@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
> > >
> > >
> > >
> > >
> >
> >
>
>



Nov 20 '05 #16
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" <st**************@REMOVEaol.com> wrote in message
news:u$*************@TK2MSFTNGP12.phx.gbl...
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]" <Ja************@msn.com> wrote in message
news:e3*************@tk2msftngp13.phx.gbl...
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" <st**************@REMOVEaol.com> wrote in message
news:%2****************@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 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]" <Ja************@msn.com> wrote in message news:%2*****************@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 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?

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" <st**************@REMOVEaol.com> wrote in message
> news:e8**************@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

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]" <Ja************@msn.com> wrote in
message
> > news:uz**************@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

(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" <st**************@REMOVEaol.com> wrote in message
> > > news:O$**************@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
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 20 '05 #17
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]" <Ja************@msn.com> wrote in message
news:O6**************@TK2MSFTNGP11.phx.gbl...
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" <st**************@REMOVEaol.com> wrote in message
news:u$*************@TK2MSFTNGP12.phx.gbl...
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]" <Ja************@msn.com> wrote in message news:e3*************@tk2msftngp13.phx.gbl...
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" <st**************@REMOVEaol.com> wrote in message
news:%2****************@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

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]" <Ja************@msn.com> wrote in

message
> news:%2*****************@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

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?
>
> 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" <st**************@REMOVEaol.com> wrote in message
> > news:e8**************@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 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]" <Ja************@msn.com> wrote in > message
> > > news:uz**************@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
(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" <st**************@REMOVEaol.com> wrote in message
> > > > news:O$**************@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
> > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 20 '05 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Amy | last post by:
What's different between Controls method Refresh() and Invalidate(), Refresh() and Update()? Your help will be appreciated. Thanks.
1
by: Claus Konrad | last post by:
What's the difference between calling the first and the second (see subject). Thanks! /Claus
3
by: Marge Inoferror | last post by:
I am trying to display a number of images and have them scale when the window is resized. I have all the code to draw the window in an OnPaint()...
4
by: grayaii | last post by:
Hi, I have a simple form that handles all its paint functionality like so: this.SetStyle(ControlStyles.AllPaintingInWmPaint |...
1
by: sean | last post by:
I'm trying to create "rubber-band" rectangles by overriding the OnPaint method to place rectangles on top of all graphic controls, but when I call...
2
by: active | last post by:
Refresh says: -Forces the control to invalidate its client area and immediately redraw itself and any child controls. Not the Menu for example? ...
5
by: tshad | last post by:
I have an interface I am using to get access to some of the objects on my form: a textbox (Status) and my statusbar (StatusBar). In my class, which...
1
by: William Dauchy | last post by:
Hello, I have a button which put a value in a variable when a click happened. This variable is part of data binding, and is connected to a...
5
by: kveerareddy | last post by:
Hi experts, Technologies: Spring, AJAX, Google web tool kit Problem: Ideally when the user stops using a web page then after 30 minutes, if the...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.