我有一个带有StatusBar的Form。在StatusBar上有ToolStripStatusLabel1和ToolStripProgressBar1。 Normaly,ToolStripProgressBar不可见 但是当我开始文件复制时,ToolStripStatusLabel1因为不可见而ToolStripProgressBar因为可见。
像这样:ToolStripStatusLabel1.Visible = False
ToolStripProgressBar1.Visible = True
问题是,在这种情况下,我不能让ProgressBar占用StatusBar的所有空间,而不是增加它的宽度,也不要将它的Dock属性设置为.Fill。
ToolStripStatusLabel1.Visible = False
ToolStripStatusLabel1.Width = 0
ToolStripProgressBar1.Dock = DockStyle.Fill
在描述的情况下,是否可以让ToolStripProgressBar1获取完整的StatusBar宽度?
答案 0 :(得分:1)
ToolStripProgressBar非常有限,无法做到你想要的。
另一种方法是使常规 ProgressBar取代整个StatusStrip:
Public Class Form1
Private PB As New ProgressBar
Private ShowProgress As Boolean = False
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ShowProgressBar(True)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ShowProgressBar(False)
End Sub
Private Sub ShowProgressBar(ByVal Visible As Boolean)
ShowProgress = Visible
If ShowProgress Then
Dim rc As Rectangle = StatusStrip1.RectangleToScreen(StatusStrip1.ClientRectangle)
PB.Bounds = Me.RectangleToClient(rc)
PB.Anchor = AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Bottom
Me.Controls.Add(PB)
PB.BringToFront()
Else
Me.Controls.Remove(PB)
End If
End Sub
End Class