Click here to Skip to main content
15,895,011 members
Articles / Programming Languages / C#

Behavioral Patterns: Implementing the Command Pattern in C#

Rate me:
Please Sign up or sign in to vote.
3.38/5 (16 votes)
23 Aug 2007CPOL2 min read 68.2K   478   58  
Writing the Command Pattern with C# (real example).
namespace CommandTest
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.panel1 = new System.Windows.Forms.Panel();
            this.panel2 = new System.Windows.Forms.Panel();
            this.lsvCustomListView = new CommandTest.CustomControls.CustomListView();
            this.lsbCustomListbox = new CommandTest.CustomControls.CustomListBox();
            this.lblCustomLabel = new CommandTest.CustomControls.CustomLabel();
            this.SuspendLayout();
            // 
            // panel1
            // 
            this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.panel1.Location = new System.Drawing.Point(13, 35);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(279, 4);
            this.panel1.TabIndex = 1;
            // 
            // panel2
            // 
            this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.panel2.Location = new System.Drawing.Point(13, 94);
            this.panel2.Name = "panel2";
            this.panel2.Size = new System.Drawing.Size(279, 4);
            this.panel2.TabIndex = 2;
            // 
            // lsvCustomListView
            // 
            this.lsvCustomListView.FullRowSelect = true;
            this.lsvCustomListView.GridLines = true;
            this.lsvCustomListView.Location = new System.Drawing.Point(12, 104);
            this.lsvCustomListView.Name = "lsvCustomListView";
            this.lsvCustomListView.Size = new System.Drawing.Size(279, 59);
            this.lsvCustomListView.TabIndex = 3;
            this.lsvCustomListView.UseCompatibleStateImageBehavior = false;
            this.lsvCustomListView.View = System.Windows.Forms.View.Details;
            // 
            // lsbCustomListbox
            // 
            this.lsbCustomListbox.FormattingEnabled = true;
            this.lsbCustomListbox.Location = new System.Drawing.Point(12, 45);
            this.lsbCustomListbox.Name = "lsbCustomListbox";
            this.lsbCustomListbox.Size = new System.Drawing.Size(280, 43);
            this.lsbCustomListbox.TabIndex = 2;
            // 
            // lblCustomLabel
            // 
            this.lblCustomLabel.AutoSize = true;
            this.lblCustomLabel.Location = new System.Drawing.Point(10, 14);
            this.lblCustomLabel.Margin = new System.Windows.Forms.Padding(3, 0, 3, 5);
            this.lblCustomLabel.Name = "lblCustomLabel";
            this.lblCustomLabel.Size = new System.Drawing.Size(84, 13);
            this.lblCustomLabel.TabIndex = 0;
            this.lblCustomLabel.Text = "[lblCustomLabel]";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(304, 177);
            this.Controls.Add(this.lsvCustomListView);
            this.Controls.Add(this.panel2);
            this.Controls.Add(this.lsbCustomListbox);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.lblCustomLabel);
            this.Name = "Form1";
            this.Text = "Test";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private CommandTest.CustomControls.CustomLabel lblCustomLabel;
        private System.Windows.Forms.Panel panel1;
        private CommandTest.CustomControls.CustomListBox lsbCustomListbox;
        private System.Windows.Forms.Panel panel2;
        private CommandTest.CustomControls.CustomListView lsvCustomListView;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions