How to control the control status on Windows form

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.