Hình mẫu :
Click vào hình ảnh để lấy hình ảnh lớn

Tên:		lb.png
Lần xem:	8
Size:		5.8 KB
ID:		5068

Source Code :

Visual C# Code:
  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7.  
  8. public class Form1 : System.Windows.Forms.Form {
  9.    private System.Windows.Forms.CheckedListBox chkListPossibleValues;
  10.    private System.Windows.Forms.ListBox lstSelected;
  11.    private System.Windows.Forms.Button btnMove;
  12.    private System.ComponentModel.Container components=null;
  13.  
  14.    public Form1() {
  15.       InitializeComponent();
  16.       this.chkListPossibleValues.Items.Add("Ten");
  17.    }
  18.  
  19.    private void InitializeComponent() {
  20.       this.lstSelected = new System.Windows.Forms.ListBox();
  21.       this.btnMove = new System.Windows.Forms.Button();
  22.       this.chkListPossibleValues = new System.Windows.Forms.CheckedListBox();
  23.       this.SuspendLayout();
  24.  
  25.       this.lstSelected.Location = new System.Drawing.Point(232, 8);
  26.       this.lstSelected.Name = "lstSelected";
  27.       this.lstSelected.Size = new System.Drawing.Size(136, 186);
  28.       this.lstSelected.TabIndex = 1;
  29.  
  30.       this.btnMove.Location = new System.Drawing.Point(152, 80);
  31.       this.btnMove.Name = "btnMove";
  32.       this.btnMove.TabIndex = 3;
  33.       this.btnMove.Text = "Move";
  34.       this.btnMove.Click += new System.EventHandler(this.btnMove_Click);
  35.  
  36.       this.chkListPossibleValues.CheckOnClick = true;
  37.       this.chkListPossibleValues.Items.AddRange(new object[] {"One", "Two", "Three",
  38.                   "Four", "Five","Six","Seven", "Eight", "Nine"});
  39.       this.chkListPossibleValues.Location = new System.Drawing.Point(8, 8);
  40.       this.chkListPossibleValues.Name = "chkListPossibleValues";
  41.       this.chkListPossibleValues.Size = new System.Drawing.Size(136, 184);
  42.       this.chkListPossibleValues.TabIndex = 0;
  43.  
  44.       this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  45.       this.ClientSize = new System.Drawing.Size(376, 205);
  46.       this.Controls.AddRange(new System.Windows.Forms.Control[] {this.btnMove,
  47.                                   this.lstSelected,  this.chkListPossibleValues});
  48.       this.Name = "Form1";
  49.       this.Text = "List Boxes";
  50.       this.ResumeLayout(false);
  51.  
  52.       }
  53.  
  54.       static void Main() {
  55.          Application.Run(new Form1());
  56.       }
  57.  
  58.       private void btnMove_Click(object sender, System.EventArgs e) {
  59.          if (this.chkListPossibleValues.CheckedItems.Count > 0) {
  60.             this.lstSelected.Items.Clear();
  61.             foreach (string item in this.chkListPossibleValues.CheckedItems) {
  62.                 this.lstSelected.Items.Add(item.ToString());
  63.             }
  64.             for (int i = 0; i < this.chkListPossibleValues.Items.Count; i++){
  65.                  this.chkListPossibleValues.SetItemChecked(i, false);
  66.             }    
  67.          }
  68.       }
  69. }