Global Parameters?


G

Guest

Visual Studio 2003 / C#

My application has 1 main form. On this form is a treeview object down the
left hand edge and a status bar along the bottom. That is all. The tree
view acts as my menu controller, and when the users click an item, I generate
instances of various UserControls I have for each of the menu items, and add
an instance to the Main form in the right hand area. Some of these
UserControls are just single page objects with fields and buttons etc on
them. Some are a UserControl which for example has a datagrid on page 1,
then another UserControl on page 2 to represent the selected data in this
datagrid on page 1.

I want to be able to publish messages and text to the status bar on my main
form at any point from anywhere in my application. I can achieve this by
passing the "this" value around between objects, then maybe use reflection to
call a method in my main form. But this seems a little lame to me. In
previous languages I have worked with, there has been a Global Parameters
methodology, where I could for example set and get a global property for
"this", then call my setMessage function using this, without the need to pass
it around my objects. Is this possible in .Net? A top level always
available set of parameters?

Thanks
 
Ad

Advertisements

W

W.G. Ryan MVP

Steve - if you mark a property as public static, you can access it from
anywhere in the application. Is this the sort of functionality you were
looking for? If not, I may have misunderstood the goal so please forgive
me.
 
G

Guest

Possibly, I'm not too sure what you mean though. Do I setup a public static
property in my MainMenu form to set the text property on my StatusBar? Can I
then set this property from other objects in my project?

Thanks

Steve
 
Ad

Advertisements

G

Guest

Yes, that worked fine. I declared the statusbar panels as private static,
and created a public static method which recieves a string, and sets the
panel text to this string. Then wherever I want to set a message in the
status bar I just call the MainMenu.SetSystemMessage method.

Thanks a lot

Steve
 

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