How to Synch a Menu Item and Toolbar Toggle Button in C#?

Status
Not open for further replies.

Siena1383

Baseband Member
Messages
51
Say you have a menu item that you can check and uncheck. And you have a toolbar button for the same thing, that you can toggle between a pushed and not-pushed state. Of course they need to be in synch, either both checked/pushed or neither checked/pushed.

What I did was set them to the same state initially. Then I put code inside each control so that when one changes, the other changes, too. Is there a usual way to do this that's cleaner?

Also, this doesn't retain the state a user gives it after the application is closed, so that the next time the app is used, these two controls would keep whatever state was last chosen. How would that be done?

This is a curiosity question. I'm working my way through a book and don't need to do that yet. (Synching up the two controls' states wasn't required - or taught - either, just creating the toolbar toggle button.)

Thanks!
 
What I did was set them to the same state initially. Then I put code inside each control so that when one changes, the other changes, too. Is there a usual way to do this that's cleaner?
Yes, but if you're just learning the C# language, concentrate on that. This is a user interface question that will have a different answer depending on which UI library you're using (WinForms or WPF).

Also, this doesn't retain the state a user gives it after the application is closed, so that the next time the app is used, these two controls would keep whatever state was last chosen. How would that be done?
You would serialize the data to disk, and then load it back up when the application is started. You can do this yourself or make use of the .NET application configuration file (*.exe.config).
 
Status
Not open for further replies.
Back
Top Bottom