Click here to Skip to main content
15,884,177 members
Articles / Programming Languages / C#

ComboBox with Read Only Behavior

Rate me:
Please Sign up or sign in to vote.
4.66/5 (24 votes)
25 Apr 2005CPOL5 min read 399.2K   5K   63  
An article about developing a ComboBox with the same read only functionality as the TextBox
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace TestReadOnlyComboBox
{
	/// <summary>
	/// Summary description for DifferentStates.
	/// </summary>
	public class DifferentStates : System.Windows.Forms.Form
	{
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.TextBox textBox1;
    private System.Windows.Forms.TextBox textBox2;
    private System.Windows.Forms.TextBox textBox3;
    private System.Windows.Forms.Label label3;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public DifferentStates()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(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.label1 = new System.Windows.Forms.Label();
      this.label2 = new System.Windows.Forms.Label();
      this.textBox1 = new System.Windows.Forms.TextBox();
      this.textBox2 = new System.Windows.Forms.TextBox();
      this.textBox3 = new System.Windows.Forms.TextBox();
      this.label3 = new System.Windows.Forms.Label();
      this.SuspendLayout();
      // 
      // label1
      // 
      this.label1.Location = new System.Drawing.Point(8, 15);
      this.label1.Name = "label1";
      this.label1.TabIndex = 0;
      this.label1.Text = "TextBox:";
      this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
      // 
      // label2
      // 
      this.label2.Location = new System.Drawing.Point(8, 47);
      this.label2.Name = "label2";
      this.label2.TabIndex = 1;
      this.label2.Text = "TextBox disabled:";
      this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
      // 
      // textBox1
      // 
      this.textBox1.Location = new System.Drawing.Point(120, 16);
      this.textBox1.Name = "textBox1";
      this.textBox1.TabIndex = 2;
      this.textBox1.Text = "\"normal\" textbox";
      // 
      // textBox2
      // 
      this.textBox2.Enabled = false;
      this.textBox2.Location = new System.Drawing.Point(120, 48);
      this.textBox2.Name = "textBox2";
      this.textBox2.TabIndex = 3;
      this.textBox2.Text = "Enabled = false";
      // 
      // textBox3
      // 
      this.textBox3.Location = new System.Drawing.Point(120, 80);
      this.textBox3.Name = "textBox3";
      this.textBox3.ReadOnly = true;
      this.textBox3.TabIndex = 4;
      this.textBox3.Text = "ReadOnly = true";
      // 
      // label3
      // 
      this.label3.Location = new System.Drawing.Point(8, 79);
      this.label3.Name = "label3";
      this.label3.TabIndex = 5;
      this.label3.Text = "TextBox readonly:";
      this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
      // 
      // DifferentStates
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(240, 115);
      this.Controls.Add(this.label3);
      this.Controls.Add(this.textBox3);
      this.Controls.Add(this.textBox2);
      this.Controls.Add(this.textBox1);
      this.Controls.Add(this.label2);
      this.Controls.Add(this.label1);
      this.Name = "DifferentStates";
      this.Text = "DifferentStates";
      this.ResumeLayout(false);

    }
		#endregion
	}
}

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
Team Leader
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions