• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

Can't reference a control added to a form?

I have a Public SubProcedure in which I pass a Form, a StatusStrip and a String variable. What I'm trying to do is attach the StatusStrip to the Form and it won't let me. Here is my code below.

        Public Sub ProcessMessages(ByVal frm As Form, ByVal sbr As StatusStrip, ByVal strMsg As String)
        Try
            frm.Controls.Add(sbr)

            If gblnMessageTimer = True Then
                frm.sbr.items(0).text = strMsg
            Else
                MessageBox.Show(strMsg, "User Notification", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            End If

        Catch ex As Exception
            strErr = "modMain/ProcessMessages() - " & ex.Message
        End Try
    End Sub
Screenshot.jpg
0
BlakeMcKenna
Asked:
BlakeMcKenna
1 Solution
 
Ken ButtersCommented:
the statusstrip is being added to the collection of controls, not to the form.
however, it looks like you already have addressability to the status strip...

try replacing this: frm.sbr.items(0).text = strMsg
with this : sbr.items(0).text = strMsg
0
 
lluddenCommented:
When you add a control to a form at runtime, it doesn't create the reference to the pointer like you are using.  You have to reference it through the controls collection.

If you to access it with something like:

frm.Controls(shr.name).text
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Tackle projects and never again get stuck behind a technical roadblock.
Join Now