Help a friend write a tool that is made with. NET 2.0 windows form. The enable and disable of the menu bar, toolbar, And button on the interface do not know any good methods. I have created one myself, and I do not know whether it is appropriate or not. I hope you can give me some advice.
There are five buttons on the toolbar and one button on the interface. For example, the refresh and add buttons are enable at the beginning, and the others are disable. enable or disable as needed.
I wrote the code like this:
[Flags]
Enum buttonstate
...{
// Bit mode
Refreshbutton = 0x0001,
Searchbutton = 0x0002,
Addbutton = 0x0004,
Delbutton = 0x0008,
Updatebutton = 0x0010,
Sourceimagebutton = 0x0020
}
Private buttonstate flags = new buttonstate ();
Public void setbuttonstates (INT flags)
...{
This. Flags = (buttonstate) enum. parse (typeof (buttonstate), flags. tostring ());
Refreshtoolstripbutton. Enabled = convert. toboolean (this. Flags & buttonstate. refreshbutton );
Refreshtoolstripmenuitem. Enabled = refreshtoolstripbutton. enabled;
Refreshtoolstripmenuitem1.enabled = refreshtoolstripbutton. enabled;
Searchtoolstripbutton. Enabled = convert. toboolean (this. Flags & buttonstate. searchbutton );
Searchtoolstripmenuitem. Enabled = searchtoolstripbutton. enabled;
Searchtoolstripmenuitem1.enabled = searchtoolstripbutton. enabled;
Addtoolstripbutton. Enabled = convert. toboolean (this. Flags & buttonstate. addbutton );
Addtoolstripmenuitem. Enabled = addtoolstripbutton. enabled;
Addtoolstripmenuitem1.enabled = addtoolstripbutton. enabled;
Deletetoolstripbutton. Enabled = convert. toboolean (this. Flags & buttonstate. delbutton );
Deletetoolstripmenuitem. Enabled = deletetoolstripbutton. enabled;
Deletetoolstripmenuitem1.enabled = deletetoolstripbutton. enabled;
Updatemedilstripbutton. Enabled = convert. toboolean (this. Flags & buttonstate. updatebutton );
Updatemedilstripmenuitem. Enabled = updatemedilstripbutton. enabled;
Updatemedilstripmenuitem1.enabled = updatemedilstripbutton. enabled;
Sourceimagebutton. Enabled = convert. toboolean (this. Flags & buttonstate. sourceimagebutton );
}
When you need to change the status, call setbuttonstate to enable/disable the space according to whether the bit of the parameter is 0 or 1. Do you think this is a good method? Or you may have a better method. Thank you!