Accessing the status bar

B

BillG

In my winforms app, I have a MainForm which has a panel on it called
ContentPanel. ContentPanel holds a User Control which consists of a grid of
records depending on whether it is customers, invoices etc. From within the
user control which is sitting in the panel on the MainForm how can I access
the status bar?


Bill
 
J

Jeff Gaines

In my winforms app, I have a MainForm which has a panel on it called
ContentPanel. ContentPanel holds a User Control which consists of a grid
of
records depending on whether it is customers, invoices etc. From within
the
user control which is sitting in the panel on the MainForm how can I access
the status bar?

You want to show a message in the Status Bar on the main form?

I would put the following in the code of the control:

public delegate void MessageSenderEventHandler(object sender, string
Message, bool Error);
public event MessageSenderEventHandler MessageSender;

private void FireMessageSender(string Message, bool Error)
{
if (MessageSender != null)
{
MessageSender(this, Message, Error);
}
}

Then subscribe to it in the main form, i.e. when you initialise/load the
form (this is an example for a control of mine called jExplorerPanel1 -
you need to use the name of the instance of your control):

jExplorerPanel1.MessageSender += new
JGFiler.JExplorerPanel.MessageSenderEventHandler(jExplorerPanel1_MessageSender);

Judicious use of the tab key as you write the above will mean VS writes
the following function for you:

void jExplorerPanel1_MessageSender(object sender, string Message, bool
Error)
{
// Put in here what you want to happen when the event is fired
tslblMessage.Text = Message;
if(Error)
make a beep;
}

Now when you want to put a message in the Status Bar from your control you
call:
FireMessageSender("This is the message", true);
or
FireMessageSender("This is the message", false);

depending whether you want to indicate an error condition or not.

I have never quite understood what it is called what but I think it sets
up a delegate in the control, the form subscribes to the event and the
control fires the event when needed. It would be good if somebody could
correct my terminology :)
 

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