Devcomponents. dotnetbar. command usage

Source: Internet
Author: User

As mentioned above, dotnetbar provides great convenience for users to create interface programs. It also provides many other tools, such as devcomponents. dotnetbar. Command mentioned in this article.

The idea of devcomponents. dotnetbar. Command is to separate the interface design from the implementation of the corresponding functions to reduce coupling within the system and improve the reusability of the corresponding functions. We can bind the command object to a system control. When the control triggers a certain action, we can use the command response function to implement the corresponding operation.

For example:

Example 1

Initializecomponent Function

 

private void InitializeComponent()
{
    this.buttonX1 = new DevComponents.DotNetBar.ButtonX();
    this.command1 = new DevComponents.DotNetBar.Command();
    this.SuspendLayout();
    // 
    // buttonX1
    // 
    this.buttonX1.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;
    this.buttonX1.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
    this.buttonX1.Command = this.command1;
    this.buttonX1.Location = new System.Drawing.Point(367, 51);
    this.buttonX1.Name = "buttonX1";
    this.buttonX1.Text = "buttonX1";
    // 
    // command1
    // 
    this.command1.Executed += new System.EventHandler(this.command1_Executed);
    // 
    // Form1
    // 
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(549, 363);
    this.Controls.Add(this.buttonX1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false);
}

Command1 Response Function

private void command1_Executed(object sender, EventArgs e)
{
    MessageBox.Show("Just Test");
} 
Run:
 
When the response function of another button button2 is the same as that of button1, you only need to bind command1 to button2. This reduces code duplication and improves code reusability.
Example 2

We can also explicitly call command in the response function of the button to execute the required program. The Code is as follows.

private void buttonX1_Click(object sender, EventArgs e)
{
    command1.Execute();
}

Because the buttonx class implements the icommandsource interface, you can easily bind execution commands and bind parameters to be passed in the commandparameter attribute, in the response function of the command, you can read the data bound to the parameter for more operations.

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.