468,296 Members | 1,252 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,296 developers. It's quick & easy.

Redraw ProgressBar in StatusBar

When I resize (Enlarge) the form while the progress bar is running the
rectangle drawing is not going to the end of the rectangle?

I got a form with one button, one statusbar with three statusbarpanel

Here is the code for help

What is wrong there?

#Region "ProgressBar"

Public Structure progresspanel

Dim x As Integer

Dim y As Integer

Dim Width As Integer

Dim Height As Integer

End Structure

Dim pb As Drawing.Drawing2D.LinearGradientBrush

Dim myProgressPanel As progresspanel

Dim g As Graphics

Dim rect As Rectangle

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim t As New Threading.Thread(AddressOf progress)

t.Start()

End Sub

Private Sub StatusBar1_DrawItem(ByVal sender As Object, ByVal sbdevent As
System.Windows.Forms.StatusBarDrawItemEventArgs) Handles StatusBar1.DrawItem

myProgressPanel.x = sbdevent.Bounds.X

myProgressPanel.y = sbdevent.Bounds.Y

myProgressPanel.Width = sbdevent.Bounds.Width

myProgressPanel.Height = sbdevent.Bounds.Height

End Sub

Private Sub StatusBar1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles StatusBar1.Resize

StatusBar1.Invalidate(rect)

End Sub

Sub progress()

Dim i, j, w As Integer

j = 10000

g = Me.StatusBar1.CreateGraphics

For i = 0 To j

w = CInt((myProgressPanel.Width / j) * i)

If w = 0 Then w = 1

rect = New Rectangle(myProgressPanel.x, myProgressPanel.y, w,
myProgressPanel.Height)

pb = New Drawing.Drawing2D.LinearGradientBrush(rect, Color.AntiqueWhite,
Color.LightBlue, Drawing.Drawing2D.LinearGradientMode.Vertical)

g.FillRectangle(pb, rect)

g.DrawString(w.ToString, New Font("Arial", 10, FontStyle.Regular,
GraphicsUnit.Point), New SolidBrush(Color.Red), myProgressPanel.x,
myProgressPanel.y)

Me.StatusBar1.Panels(0).Text = w.ToString

Next

Me.StatusBar1.Panels(0).Text = "0"

g.Flush()

End Sub

#End Region
Nov 20 '05 #1
10 4308
"Nicolas" <nl*****@hotmail.com> schrieb
When I resize (Enlarge) the form while the progress bar is running
the rectangle drawing is not going to the end of the rectangle?

I got a form with one button, one statusbar with three
statusbarpanel

Here is the code for help

What is wrong there?
[code]


I tried your code but I can not reproduce the problem. I can resize the form
(resizing the docked statusbar (resizing the panel)) during painting the
panel in the other thread and the panel is always filled completely.
--
Armin

Nov 20 '05 #2
To rreproduce the error that I got:

1) launch the application (should not be maximized) - (if launch full screen
no problem)
2) press the button to start the progress bar
3) while the progress bar is incrementing, grab the right side of the form
to strech widely the form then release the mouse before the progressbar
stop. The progress bar counter should still increment (indicating the width
of the statusbarpanel) but the drawing is not going anyfurther then his
original maximum width instead of going to the end of the panel.

Thank you for your help if you find anything


"Armin Zingler" <az*******@freenet.de> wrote in message
news:uo*************@tk2msftngp13.phx.gbl...
"Nicolas" <nl*****@hotmail.com> schrieb
When I resize (Enlarge) the form while the progress bar is running
the rectangle drawing is not going to the end of the rectangle?

I got a form with one button, one statusbar with three
statusbarpanel

Here is the code for help

What is wrong there?
[code]
I tried your code but I can not reproduce the problem. I can resize the

form (resizing the docked statusbar (resizing the panel)) during painting the
panel in the other thread and the panel is always filled completely.
--
Armin

Nov 20 '05 #3
Hi,
I know this is not of help to you but I'd like to ask you help me make a
progress bar. I need to make a pop up progress bar (on a form) that will
show progress of a file download.

Can you help me with that.

Thanks,
--
Dino Buljubasic
Software Developer
http://rivusglobal.com

"Nicolas" <nl*****@hotmail.com> wrote in message
news:eK*************@tk2msftngp13.phx.gbl...
When I resize (Enlarge) the form while the progress bar is running the
rectangle drawing is not going to the end of the rectangle?

I got a form with one button, one statusbar with three statusbarpanel

Here is the code for help

What is wrong there?

#Region "ProgressBar"

Public Structure progresspanel

Dim x As Integer

Dim y As Integer

Dim Width As Integer

Dim Height As Integer

End Structure

Dim pb As Drawing.Drawing2D.LinearGradientBrush

Dim myProgressPanel As progresspanel

Dim g As Graphics

Dim rect As Rectangle

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim t As New Threading.Thread(AddressOf progress)

t.Start()

End Sub

Private Sub StatusBar1_DrawItem(ByVal sender As Object, ByVal sbdevent As
System.Windows.Forms.StatusBarDrawItemEventArgs) Handles StatusBar1.DrawItem
myProgressPanel.x = sbdevent.Bounds.X

myProgressPanel.y = sbdevent.Bounds.Y

myProgressPanel.Width = sbdevent.Bounds.Width

myProgressPanel.Height = sbdevent.Bounds.Height

End Sub

Private Sub StatusBar1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles StatusBar1.Resize

StatusBar1.Invalidate(rect)

End Sub

Sub progress()

Dim i, j, w As Integer

j = 10000

g = Me.StatusBar1.CreateGraphics

For i = 0 To j

w = CInt((myProgressPanel.Width / j) * i)

If w = 0 Then w = 1

rect = New Rectangle(myProgressPanel.x, myProgressPanel.y, w,
myProgressPanel.Height)

pb = New Drawing.Drawing2D.LinearGradientBrush(rect, Color.AntiqueWhite,
Color.LightBlue, Drawing.Drawing2D.LinearGradientMode.Vertical)

g.FillRectangle(pb, rect)

g.DrawString(w.ToString, New Font("Arial", 10, FontStyle.Regular,
GraphicsUnit.Point), New SolidBrush(Color.Red), myProgressPanel.x,
myProgressPanel.y)

Me.StatusBar1.Panels(0).Text = w.ToString

Next

Me.StatusBar1.Panels(0).Text = "0"

g.Flush()

End Sub

#End Region

Nov 20 '05 #4
"Nicolas" <nl*****@hotmail.com> schrieb
To rreproduce the error that I got:

1) launch the application (should not be maximized) - (if launch full
screen no problem)
2) press the button to start the progress bar
3) while the progress bar is incrementing, grab the right side of the
form to strech widely the form then release the mouse before the
progressbar stop. The progress bar counter should still increment
(indicating the width of the statusbarpanel) but the drawing is not
going anyfurther then his original maximum width instead of going to
the end of the panel.


That's what I've already done, but it was not reproducable. Now I did it
again, and, you are right, I can reproduce it. Well, when the graphics
object is created the width is smaller. If you resize the panel in the
meantime, you probably have to destroy the graphics object and create a
new one.
--
Armin

Nov 20 '05 #5
Thank you, I think it work with this approach
Private Sub StatusBar1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles StatusBar1.Resize

g = Nothing

StatusBar1.Invalidate(rect)

g = Me.StatusBar1.CreateGraphics

End Sub

"Armin Zingler" <az*******@freenet.de> wrote in message
news:u%****************@TK2MSFTNGP11.phx.gbl...
"Nicolas" <nl*****@hotmail.com> schrieb
To rreproduce the error that I got:

1) launch the application (should not be maximized) - (if launch full
screen no problem)
2) press the button to start the progress bar
3) while the progress bar is incrementing, grab the right side of the
form to strech widely the form then release the mouse before the
progressbar stop. The progress bar counter should still increment
(indicating the width of the statusbarpanel) but the drawing is not
going anyfurther then his original maximum width instead of going to
the end of the panel.


That's what I've already done, but it was not reproducable. Now I did it
again, and, you are right, I can reproduce it. Well, when the graphics
object is created the width is smaller. If you resize the panel in the
meantime, you probably have to destroy the graphics object and create a
new one.
--
Armin

Nov 20 '05 #6
"Nicolas" <nl*****@hotmail.com> schrieb
Thank you, I think it work with this approach
Private Sub StatusBar1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles StatusBar1.Resize
Before setting the referenct to Nothing:

g.Dispose
g = Nothing

StatusBar1.Invalidate(rect)

g = Me.StatusBar1.CreateGraphics

End Sub


--
Armin

Nov 20 '05 #7
Sorry Armin,

I don't get it. I don't use status bar and I don't use a graphic object.

Can you explain to me little bit more how to use what you just posted.

I appreciate your help

--
Dino Buljubasic
Software Developer
http://rivusglobal.com

"Armin Zingler" <az*******@freenet.de> wrote in message
news:ej****************@TK2MSFTNGP09.phx.gbl...
"Nicolas" <nl*****@hotmail.com> schrieb
Thank you, I think it work with this approach
Private Sub StatusBar1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles StatusBar1.Resize


Before setting the referenct to Nothing:

g.Dispose
g = Nothing

StatusBar1.Invalidate(rect)

g = Me.StatusBar1.CreateGraphics

End Sub


--
Armin

Nov 20 '05 #8
"Dino M. Buljubasic" <di*************@rivusglobal.com> schrieb
Sorry Armin,

I don't get it. I don't use status bar and I don't use a graphic
object.

Can you explain to me little bit more how to use what you just
posted.


??

I only added "g.dispose" to Nicolas' code because the Dispose method of
disposable objects should be called before setting the reference to Nothing.
--
Armin

Nov 20 '05 #9
Thanks, work great now

"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"Dino M. Buljubasic" <di*************@rivusglobal.com> schrieb
Sorry Armin,

I don't get it. I don't use status bar and I don't use a graphic
object.

Can you explain to me little bit more how to use what you just
posted.
??

I only added "g.dispose" to Nicolas' code because the Dispose method of
disposable objects should be called before setting the reference to

Nothing.

--
Armin

Nov 20 '05 #10
Actually this is better with a little check before isNothing() otherwise it
doesn't "g" at this point to dispose it. the resize event is call event
before I got it setup..
Private Sub StatusBar1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles StatusBar1.Resize

If Not IsNothing(g) Then

g.Dispose()

g = Nothing

StatusBar1.Invalidate(rect)

g = Me.StatusBar1.CreateGraphics

End If

End Sub

"Armin Zingler" <az*******@freenet.de> wrote in message
news:ej****************@TK2MSFTNGP09.phx.gbl...
"Nicolas" <nl*****@hotmail.com> schrieb
Thank you, I think it work with this approach
Private Sub StatusBar1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles StatusBar1.Resize


Before setting the referenct to Nothing:

g.Dispose
g = Nothing

StatusBar1.Invalidate(rect)

g = Me.StatusBar1.CreateGraphics

End Sub


--
Armin

Nov 20 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Peter | last post: by
18 posts views Thread by Andrew Poulos | last post: by
2 posts views Thread by Bernie Yaeger | last post: by
reply views Thread by Jim Hubbard | last post: by
2 posts views Thread by =?Utf-8?B?QWFyb24=?= | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.