473,779 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Invalidate() compared to Refresh()

picDocument is a picturebox

When I do picDocument.Inv alidate() the box paints.

But if instead I do picDocument.Ref resh() 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 8541
Yes, I know what you mean about answering questions late at night...

Jay

"yEaH rIgHt" <nospam@haha> wrote in message
news:10******** *****@corp.supe rnews.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******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP10.phx.gbl...
SamSpade,
Control.Refresh - does a Control.Invalid ate immediately followed by
Control.Update.

Control.Invalid ate - 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.co m> wrote in message
news:O$******** ******@TK2MSFTN GP11.phx.gbl...
picDocument is a picturebox

When I do picDocument.Inv alidate() the box paints.

But if instead I do picDocument.Ref resh() 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.co m> wrote in message
news:e8******** ******@TK2MSFTN GP12.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******** ******@TK2MSFTN GP10.phx.gbl...
SamSpade,
Control.Refresh - does a Control.Invalid ate immediately followed by
Control.Update.

Control.Invalid ate - 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.co m> wrote in message
news:O$******** ******@TK2MSFTN GP11.phx.gbl...
picDocument is a picturebox

When I do picDocument.Inv alidate() the box paints.

But if instead I do picDocument.Ref resh() 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 PicCreateGraphi cs() As Graphics
'Client should dispose this
PicCreateGraphi cs = Graphics.FromIm age(mDocumentIm age)
End Function

and do:
Private Sub picDocument_Pai nt(ByVal sender As Object, ByVal e As--snip
e.Graphics.Draw Image(mDocument Image, 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.Draw Image(mMyPictur ebox.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(picDocume nt.Image, Drawing.Bitmap) .SetPixel(Pixel ToUnitX(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******** *********@TK2MS FTNGP12.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.co m> wrote in message
news:e8******** ******@TK2MSFTN GP12.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******** ******@TK2MSFTN GP10.phx.gbl...
SamSpade,
Control.Refresh - does a Control.Invalid ate immediately followed by
Control.Update.

Control.Invalid ate - 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.co m> wrote in message
news:O$******** ******@TK2MSFTN GP11.phx.gbl...
> picDocument is a picturebox
>
> When I do picDocument.Inv alidate() the box paints.
>
> But if instead I do picDocument.Ref resh() 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 ScrollableContr ol. Which means you can make the
"drawing" surface larger then the "display" surface.

I don't have a simple example right now. Basically setting
ScrollableContr ol.AutoScroll to true and setting
ScrollableContr ol.AutoScrollMi nSize 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.Imag e property to the image you are painting?

Hope this helps
Jay
" SamSpade" <st************ **@REMOVEaol.co m> wrote in message
news:%2******** ********@TK2MSF TNGP10.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 PicCreateGraphi cs() As Graphics
'Client should dispose this
PicCreateGraphi cs = Graphics.FromIm age(mDocumentIm age)
End Function

and do:
Private Sub picDocument_Pai nt(ByVal sender As Object, ByVal e As--snip
e.Graphics.Draw Image(mDocument Image, 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.Draw Image(mMyPictur ebox.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(picDocume nt.Image, Drawing.Bitmap) .SetPixel(Pixel ToUnitX(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******** *********@TK2MS FTNGP12.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.co m> wrote in message
news:e8******** ******@TK2MSFTN GP12.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******** ******@TK2MSFTN GP10.phx.gbl...
> SamSpade,
> Control.Refresh - does a Control.Invalid ate immediately followed by
> Control.Update.
>
> Control.Invalid ate - 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.co m> wrote in message
> news:O$******** ******@TK2MSFTN GP11.phx.gbl...
> > picDocument is a picturebox
> >
> > When I do picDocument.Inv alidate() the box paints.
> >
> > But if instead I do picDocument.Ref resh() 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******** *****@tk2msftng p13.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 ScrollableContr ol. Which means you can make the
"drawing" surface larger then the "display" surface.

I don't have a simple example right now. Basically setting
ScrollableContr ol.AutoScroll to true and setting
ScrollableContr ol.AutoScrollMi nSize 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.Imag e property to the image you are painting?

Hope this helps
Jay
" SamSpade" <st************ **@REMOVEaol.co m> wrote in message
news:%2******** ********@TK2MSF TNGP10.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 PicCreateGraphi cs() As Graphics
'Client should dispose this
PicCreateGraphi cs = Graphics.FromIm age(mDocumentIm age)
End Function

and do:
Private Sub picDocument_Pai nt(ByVal sender As Object, ByVal e As--snip
e.Graphics.Draw Image(mDocument Image, 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.Draw Image(mMyPictur ebox.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(picDocume nt.Image, Drawing.Bitmap) .SetPixel(Pixel ToUnitX(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******** *********@TK2MS FTNGP12.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.co m> wrote in message
news:e8******** ******@TK2MSFTN GP12.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******** ******@TK2MSFTN GP10.phx.gbl...
> > SamSpade,
> > Control.Refresh - does a Control.Invalid ate immediately followed by > > Control.Update.
> >
> > Control.Invalid ate - 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.co m> wrote in message
> > news:O$******** ******@TK2MSFTN GP11.phx.gbl...
> > > picDocument is a picturebox
> > >
> > > When I do picDocument.Inv alidate() the box paints.
> > >
> > > But if instead I do picDocument.Ref resh() 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(Con trolStyles.User Paint, True)
Me.SetStyle(Con trolStyles.Doub leBuffer, True)
Me.SetStyle(Con trolStyles.AllP aintingInWmPain t, True)
Me.SetStyle(Con trolStyles.Resi zeRedraw, 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.AutoScrollMi nSize = Size.Empty
Else
Me.AutoScrollMi nSize = m_image.Size
End If
End Set
End Property

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

In my main form I have

Protected Overrides Sub OnLoad(ByVal e As System.EventArg s)
MyBase.OnLoad(e )
Dim image As New Bitmap(600, 600)
Dim gr As Graphics = Graphics.FromIm age(image)
Dim pageUnit As GraphicsUnit = gr.PageUnit
Dim bounds As RectangleF = image.GetBounds (pageUnit)
gr.FillRectangl e(Brushes.White , bounds)
For x As Integer = 0 To 600 Step 25
For y As Integer = 0 To 600 Step 25
gr.DrawLine(Pen s.Blue, x, 0, x, y)
gr.DrawLine(Pen s.Blue, 0, y, x, y)
Next
Next
gr.Dispose()
Me.SamSpadeCont rol1.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.co m> wrote in message
news:u$******** *****@TK2MSFTNG P12.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******** *****@tk2msftng p13.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 ScrollableContr ol. Which means you can make the
"drawing" surface larger then the "display" surface.

I don't have a simple example right now. Basically setting
ScrollableContr ol.AutoScroll to true and setting
ScrollableContr ol.AutoScrollMi nSize 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.Imag e property to the image you are painting?

Hope this helps
Jay
" SamSpade" <st************ **@REMOVEaol.co m> wrote in message
news:%2******** ********@TK2MSF TNGP10.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 PicCreateGraphi cs() As Graphics
'Client should dispose this
PicCreateGraphi cs = Graphics.FromIm age(mDocumentIm age)
End Function

and do:
Private Sub picDocument_Pai nt(ByVal sender As Object, ByVal e As--snip
e.Graphics.Draw Image(mDocument Image, 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.Draw Image(mMyPictur ebox.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(picDocume nt.Image, Drawing.Bitmap) .SetPixel(Pixel ToUnitX(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******** *********@TK2MS FTNGP12.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.co m> wrote in message
> news:e8******** ******@TK2MSFTN GP12.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******** ******@TK2MSFTN GP10.phx.gbl...
> > > SamSpade,
> > > Control.Refresh - does a Control.Invalid ate immediately followed by > > > Control.Update.
> > >
> > > Control.Invalid ate - 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.co m> wrote in message
> > > news:O$******** ******@TK2MSFTN GP11.phx.gbl...
> > > > picDocument is a picturebox
> > > >
> > > > When I do picDocument.Inv alidate() the box paints.
> > > >
> > > > But if instead I do picDocument.Ref resh() 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******** ******@TK2MSFTN GP11.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(Con trolStyles.User Paint, True)
Me.SetStyle(Con trolStyles.Doub leBuffer, True)
Me.SetStyle(Con trolStyles.AllP aintingInWmPain t, True)
Me.SetStyle(Con trolStyles.Resi zeRedraw, 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.AutoScrollMi nSize = Size.Empty
Else
Me.AutoScrollMi nSize = m_image.Size
End If
End Set
End Property

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

In my main form I have

Protected Overrides Sub OnLoad(ByVal e As System.EventArg s)
MyBase.OnLoad(e )
Dim image As New Bitmap(600, 600)
Dim gr As Graphics = Graphics.FromIm age(image)
Dim pageUnit As GraphicsUnit = gr.PageUnit
Dim bounds As RectangleF = image.GetBounds (pageUnit)
gr.FillRectangl e(Brushes.White , bounds)
For x As Integer = 0 To 600 Step 25
For y As Integer = 0 To 600 Step 25
gr.DrawLine(Pen s.Blue, x, 0, x, y)
gr.DrawLine(Pen s.Blue, 0, y, x, y)
Next
Next
gr.Dispose()
Me.SamSpadeCont rol1.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.co m> wrote in message
news:u$******** *****@TK2MSFTNG P12.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******** *****@tk2msftng p13.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 ScrollableContr ol. Which means you can make the "drawing" surface larger then the "display" surface.

I don't have a simple example right now. Basically setting
ScrollableContr ol.AutoScroll to true and setting
ScrollableContr ol.AutoScrollMi nSize 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.Imag e property to the image you are painting?

Hope this helps
Jay
" SamSpade" <st************ **@REMOVEaol.co m> wrote in message
news:%2******** ********@TK2MSF TNGP10.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 PicCreateGraphi cs() As Graphics
> 'Client should dispose this
> PicCreateGraphi cs = Graphics.FromIm age(mDocumentIm age)
> End Function
>
> and do:
> Private Sub picDocument_Pai nt(ByVal sender As Object, ByVal e
As--snip > e.Graphics.Draw Image(mDocument Image, 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.Draw Image(mMyPictur ebox.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(picDocume nt.Image,
Drawing.Bitmap) .SetPixel(Pixel ToUnitX(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******** *********@TK2MS FTNGP12.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.co m> wrote in message
> > news:e8******** ******@TK2MSFTN GP12.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******** ******@TK2MSFTN GP10.phx.gbl...
> > > > SamSpade,
> > > > Control.Refresh - does a Control.Invalid ate immediately followed by
> > > > Control.Update.
> > > >
> > > > Control.Invalid ate - 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.co m> wrote in message
> > > > news:O$******** ******@TK2MSFTN GP11.phx.gbl...
> > > > > picDocument is a picturebox
> > > > >
> > > > > When I do picDocument.Inv alidate() the box paints.
> > > > >
> > > > > But if instead I do picDocument.Ref resh() 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
14133
by: Amy | last post by:
What's different between Controls method Refresh() and Invalidate(), Refresh() and Update()? Your help will be appreciated. Thanks.
1
29236
by: Claus Konrad | last post by:
What's the difference between calling the first and the second (see subject). Thanks! /Claus
3
3784
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() override. However, it only draws correctly the first time it is displayed. When I resize the window, it keeps the remnants of the first window and redraws only in "new" areas of the window. Is there a way to invalidate the entire window when OnPaint is invoked? I
4
4639
by: grayaii | last post by:
Hi, I have a simple form that handles all its paint functionality like so: this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); And the entry point to this program is like so: static void Main() {
1
3615
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 Me.Invalidate() (when the user moves the mouse), OnPaint is not getting called... Here is the relevent code: I'm trying to create a "rubber band" rectangle effect on my form. Private Sub HighlightSectionOfTrack(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles...
2
7366
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? While Invalidate() says: -Invalidates the entire surface of the control and causes the control to be redrawn. Does "the entire surface" mean more then the client area?
5
2425
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 is actually in another class from my form I have the following: public interface IStatusDisplay { string Status { get; set; } string StatusBar { get; set; } }
1
1300
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 textbox. In the method which receive the click button I finished by calling the invalidate method of the textbox. But nothing happens (I mean, the textbox isnt update) until I click on another radio button somewhere in the UI. What should I do to update the textbox immediately?
5
5844
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 user is trying to access any ting then the session gets expired. But In my case one pages continually refreshes for every 30 seconds, hence not giving scope to session timeout even when the user stops using it. Questions: Is there any way to stop resetting of time in some specific cases, for...
0
9632
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10302
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10136
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.