473,225 Members | 1,234 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 4470
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Peter | last post by:
I want to draw some lines on a widget. This works ok, but when I want to redraw, the old lines are still there. How do I clear or refresh the widget, so I can draw a new set of lines? Code...
18
by: Andrew Poulos | last post by:
If I manage to call the following bit of javascript in IE and MZ w = window.open("", "s", 'status=no,resizable=no,width=450,height=450'); I get a window that is not resizable and without a...
9
by: Christian Blackburn | last post by:
Hi Gang, I've had this happen with a couple of controls now, but my patience has worn thin. Can somebody tell me why I can read/write to most objects on my form from my module, but not when...
2
by: Bernie Yaeger | last post by:
I know I've seen questions like this before, but I don't recall the answer - I would like to place a progressbar in a panel of a statusbar control. How can I do this both using the IDE or by code?...
11
by: Lars Netzel | last post by:
In my MDI parent form I choose to open a Child thru a MenuClick... I want a progressabar to show up and progress allthru the loading of the new Child Form.. and then when it's done I want the...
0
by: Jim Hubbard | last post by:
When you add a StatusStrip to a WinForm and add a Progressbar to the StatusStrip, setting the Progressbar alignment to "Right" does not move the Progressbar to the right on the Statusbar. Is...
1
by: Robert Dufour | last post by:
On a winform have StatusBar1, StausBar1Panel1 and StatusBar1Pannel2, How do I put a progressbar In StatusBar1Pannel2? Thanks for any help, Bob
2
by: =?Utf-8?B?QWFyb24=?= | last post by:
Since some controls such as the DataGridView take a long time to update themselves when performing certain tasks, I have added a StatusStrip with a ProgressBar on it. While I am updating the...
4
by: Thomas | last post by:
Hello, I don't know if such question was already posted but I didn't find anything through different posts. I have the Main MDI window with a StatusBar. Inside my StatusBar there is a...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.