Windows Develop Bookmark and Share   
 index > Windows Forms General > Changing the text in an MDIForm's StatusBar from a Module
 

Changing the text in an MDIForm's StatusBar from a Module

Hi,

I have created and MDIForm with a StatusBar on it and wish to change the text value of the first panel by calling a Sub routine on a module.... it fails with an error of Object has not been referanced message...

It works when I change the text form teh MDIForm or from a child form with

me.MDIParent.StatusBar(1).Text = "something"

DOE NOT WORK FROM A MODULE

Heeellllppp!
MigrationUser 1  Sunday, December 28, 2003 3:59 AM
You aren't giving us enough code.  The likely reason it won't work from a Module is simply scoping.  I believe when you say Module, you mean Class.  By default Me in a class won't have an MDIParent property.  The best way to extend this (assuming you will only have one form), is with a static property on your MDIForm parent class.  Something like this:

Sorry code is in C#, but can be adapted appropriately to VB .NET.


public class MyMDIForm : Form {
    private static MDIForm _current = null;
    
    public MyMDIForm() {
        _current = this; // Set current to the current
    }

    public static MyMDIForm Current {
        get { return _current; }
    }
}

/* This should be your *module* */
public class WorkerClass {
    public void DoWork() {
        MyMDIForm.Current.StatusBar(1).Text = "Something";
    }
}
MigrationUser 1  Sunday, December 28, 2003 6:29 PM
Thanks for the help

Unfortunatly this doesn't work either.

Let me try to lay it out better...

MDIForm
has a StatusBar on it (MDIForm.StatusPanel1)
has 
   ChildForm
   Module (NOT class)


When anything occurs where the message(text) in the StatusBar needs changing (from either code on the ChildForm or general code within the Module telling the user the current status of the even they are executing.

I would like to call it from a single point of entry within the Module.

At the moment I am using the following line form all over the place and I find that ver frustrating...

CType(Me.MdiParent(), MDIForm).StatusBarPanel1.Text = "Please enter a new customer."

Thanks for any additiona help you can offer.
Phill
MigrationUser 1  Saturday, January 03, 2004 2:31 PM

You can use google to search for other answers

Custom Search

More Threads

• Best Practice
• Shadow effect
• My Question about Toolbar
• potential race condition in a delegate
• System.IO.Ports SerialPort connection issues
• Re: Interface events
• how to get previous month from current date
• using GDI+ resources...
• cancelling alert window
• C#; Serial Communication and Threads