zoukankan      html  css  js  c++  java
  • DevComponents.DotNetBar.Command使用方法

    如前文所说,DotNetBar为用户制作界面程序提供了很大的方便。同时其也提供了许多其他的工具,例如本文提到的DevComponents.DotNetBar.Command。

    DevComponents.DotNetBar.Command的思想是将界面设计与相应函数的实现分离,降低系统内部的耦合性,同时可以提高相应函数的复用性。我们可以把Command对象绑定到一个系统控件上,在控件的触发一定动作时通过Command的响应函数来实现相应操作。

    例如:

    示例一

    InitializeComponent函数

    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响应函数

    private void command1_Executed(object sender, EventArgs e)
    
    {
    
        MessageBox.Show("Just Test");
    
    } 
    
    运行效果图:
    image 
    当另外一个按钮button2的响应函数与button1相同时,只要将command1再绑定到button2上即可,这样减少了代码的重复编写,提高代码的复用性。

    示例二

    我们同样可以在button的响应函数中显式调用command来执行所需程序,代码如下。

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

    由于ButtonX类实现了ICommandSource接口,从而可以方便地绑定执行命令,同时可以在CommandParameter属性中绑定需要传入的参数,在command的响应函数中可以读取参数中绑定的数据进行更多的操作。

  • 相关阅读:
    HDU 4069 Squiggly Sudoku
    SPOJ 1771 Yet Another NQueen Problem
    POJ 3469 Dual Core CPU
    CF 118E Bertown roads
    URAL 1664 Pipeline Transportation
    POJ 3076 Sudoku
    UVA 10330 Power Transmission
    HDU 1426 Sudoku Killer
    POJ 3074 Sudoku
    HDU 3315 My Brute
  • 原文地址:https://www.cnblogs.com/glorey/p/1800254.html
Copyright © 2011-2022 走看看