Referencing a Control's Name from Another Form


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Referencing a Control's Name from Another Form

  1. #1
    Join Date
    Feb 2010
    Location
    Central WV, USA
    Posts
    212

    Referencing a Control's Name from Another Form

    I use a routine to display status messages on all my forms. Currently there is a copy of this code in every formclass in my project. I'm trying to figure out a way to move it to a global module and be able to reference the label on the 'sender' form and send text to it.

    ex: FrmCallwasMadeFrom.lblStatus.text = "my message"

    But right now this code only services the form that it lives in.

    Code:
    Public Sub myStatus(ByVal Status As String, ByVal isCritical As Boolean)
            'Dispaly Status Messages
            If isCritical Then
                lblStatus.ForeColor = Color.Red
                lblStatus.Font = myStatusCritical
            Else
                lblStatus.ForeColor = Color.Black
                lblStatus.Font = myStatusNormal
            End If
            lblStatus.Text = Status.Trim
            Me.Refresh()
        End Sub
    Right now the Call looks like this
    Code:
    myStatus("Your Message Here", isCritical)
    Any ideas?

  2. #2
    Join Date
    Feb 2010
    Location
    Central WV, USA
    Posts
    212
    Ive found a way to make it work.

    Code:
    Public Sub myStatus(ByVal Status As String, ByVal isCritical As Boolean, ByRef lbl As Label)
            'Dispaly Status Messages
            If isCritical Then
                lbl.ForeColor = Color.Red
                lbl.Font = myStatusCritical
            Else
                lbl.ForeColor = Color.Black
                lbl.Font = myStatusNormal
            End If
            lbl.Text = Status.Trim
            lbl.Refresh()
        End Sub

    But I have to type the controlname everytime I call it, a little combersome but I can't find any other workarounds.

    Code:
    myStatus(" ", isCritical, lblStatus)
    Last edited by rrjii2000; 01-17-2011 at 04:46 PM.

  3. #3
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Quote Originally Posted by rrjii2000 View Post
    But I have to type the controlname everytime I call it, a little combersome but I can't find any other workarounds.
    That makes sense. You would need to do that no matter how you did it. Otherwise, how would your code know which label was supposed to display the status?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  4. #4
    Join Date
    Feb 2010
    Location
    Central WV, USA
    Posts
    212
    The idea I had was to somehow setup a 'default' value or overload for the call. Some way to code the method so that it always grabs a default value (or control in this case) when the Call is made. And you wouldn't always have to pass in values.

Similar Threads

  1. list all controls in form
    By jason213123 in forum .NET
    Replies: 5
    Last Post: 02-13-2009, 08:24 AM
  2. Replies: 2
    Last Post: 02-02-2009, 02:52 PM
  3. dynamic form controls
    By Rick Walsh in forum ASP.NET
    Replies: 1
    Last Post: 07-11-2003, 04:25 PM
  4. Resize controls when you maximise a form
    By Partha in forum VB Classic
    Replies: 1
    Last Post: 04-22-2003, 05:16 AM
  5. Accessing Controls on another form ?
    By Deasun in forum .NET
    Replies: 1
    Last Post: 03-29-2002, 02:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center