How to refer to status bar panels thru object syntax?

D

Dean Slindee

Is there any way to refer to the .text property of a status bar panel thru
object syntax,

like below (the inner "for" does not work):



Public Function FormStatusBarPaint(ByVal frm As Form) As Integer

Dim obj As New Control

Dim str As String

Dim pnl As StatusBar.StatusBarPanelCollection

For Each obj In frm.Controls

str = obj.GetType.ToString

Select Case str

Case "System.Windows.Forms.StatusBar"

For Each pnl In obj.Controls

pnl(0).Text = "Edit"

pnl(1).Text = "Ready for update"

pnl(2).Text = Today.ToShortDateString

Next

End Select

Next

End Function

Thanks,

Dean Slindee
 
C

Chris Dunaway

On Mon, 24 Nov 2003 12:26:06 -0600, Dean Slindee wrote:

See Notes below
Is there any way to refer to the .text property of a status bar panel thru
object syntax,


Public Function FormStatusBarPaint(ByVal frm As Form) As Integer

Dim obj As New Control

Dim str As String
Dim pnl As StatusBarPanel

For Each obj In frm.Controls

str = obj.GetType.ToString

Select Case str

Case "System.Windows.Forms.StatusBar"
You have to cast the obj variable to be a statusbar:

For Each pnl In CType(obj,StatusBar).Panels
pnl.Text = "Edit"
 
P

Peter Huang

Dean,

I agree with Chris.
Or you can modify your code as follows.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim obj As Control
Dim str As String
Dim pnl As StatusBar.StatusBarPanelCollection
For Each obj In Me.Controls
str = obj.GetType.ToString
Select Case str
Case "System.Windows.Forms.StatusBar"
pnl = CType(obj, StatusBar).Panels
pnl(0).Text = "Edit"
pnl(1).Text = "Ready for update"
pnl(2).Text = Today.ToShortDateString
End Select
Next
End Sub

If you have any conern on this question, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top