List Box click event : ListBox « GUI Windows Form « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » GUI Windows Form » ListBoxScreenshots 
List Box click event
List Box click event

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form
{
  private System.Windows.Forms.Label lblSaturation;
  private System.Windows.Forms.Label lblHue;
  private System.Windows.Forms.Label lblBrightness;
  private System.Windows.Forms.Label Label1;
  private System.Windows.Forms.ListBox lstColors;

  public Form1()
  {
    InitializeComponent();
    string[] colorNames  = System.Enum.GetNames(typeof(KnownColor));
    lstColors.Items.AddRange(colorNames);
  }

  private void lstColors_SelectedIndexChanged(object sender, EventArgs e)
  {
    KnownColor selectedColor = (KnownColor)System.Enum.Parse(typeof(KnownColor), lstColors.Text);

    this.BackColor = System.Drawing.Color.FromKnownColor(selectedColor);

    lblBrightness.Text = "Brightness = " this.BackColor.GetBrightness().ToString();
    lblHue.Text = "Hue = " this.BackColor.GetHue().ToString();
    lblSaturation.Text = "Saturation = " this.BackColor.GetSaturation().ToString();
  }

  private void InitializeComponent()
  {
    this.lblSaturation = new System.Windows.Forms.Label();
    this.lblHue = new System.Windows.Forms.Label();
    this.lblBrightness = new System.Windows.Forms.Label();
    this.Label1 = new System.Windows.Forms.Label();
    this.lstColors = new System.Windows.Forms.ListBox();
    this.SuspendLayout();
    // 
    // lblSaturation
    // 
    this.lblSaturation.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
    this.lblSaturation.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    this.lblSaturation.FlatStyle = System.Windows.Forms.FlatStyle.System;
    this.lblSaturation.Location = new System.Drawing.Point(26857);
    this.lblSaturation.Name = "lblSaturation";
    this.lblSaturation.Size = new System.Drawing.Size(13620);
    this.lblSaturation.TabIndex = 4;
    this.lblSaturation.Text = " Saturation";
    // 
    // lblHue
    // 
    this.lblHue.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
    this.lblHue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    this.lblHue.FlatStyle = System.Windows.Forms.FlatStyle.System;
    this.lblHue.Location = new System.Drawing.Point(26833);
    this.lblHue.Name = "lblHue";
    this.lblHue.Size = new System.Drawing.Size(13620);
    this.lblHue.TabIndex = 3;
    this.lblHue.Text = " Hue";
    // 
    // lblBrightness
    // 
    this.lblBrightness.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
    this.lblBrightness.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    this.lblBrightness.FlatStyle = System.Windows.Forms.FlatStyle.System;
    this.lblBrightness.Location = new System.Drawing.Point(2689);
    this.lblBrightness.Name = "lblBrightness";
    this.lblBrightness.Size = new System.Drawing.Size(13620);
    this.lblBrightness.TabIndex = 2;
    this.lblBrightness.Text = " Brightness";
    // 
    // Label1
    // 
    this.Label1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
    this.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    this.Label1.FlatStyle = System.Windows.Forms.FlatStyle.System;
    this.Label1.Location = new System.Drawing.Point(129);
    this.Label1.Name = "Label1";
    this.Label1.Size = new System.Drawing.Size(20020);
    this.Label1.TabIndex = 0;
    this.Label1.Text = " Choose a Background Color:";
    // 
    // lstColors
    // 
    this.lstColors.FormattingEnabled = true;
    this.lstColors.Location = new System.Drawing.Point(1237);
    this.lstColors.Name = "lstColors";
    this.lstColors.Size = new System.Drawing.Size(200238);
    this.lstColors.TabIndex = 1;
    this.lstColors.SelectedIndexChanged += new System.EventHandler(this.lstColors_SelectedIndexChanged);
    // 
    // Form1
    // 
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(430284);
    this.Controls.Add(this.lblSaturation);
    this.Controls.Add(this.lblHue);
    this.Controls.Add(this.lblBrightness);
    this.Controls.Add(this.Label1);
    this.Controls.Add(this.lstColors);
    this.Font = new System.Drawing.Font("Tahoma"8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    this.Name = "Form1";
    this.Text = "Color Changer";
    this.ResumeLayout(false);

  }

  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }

}



           
       
Related examples in the same category
1.Add new item to ListBox (text from TextBox) Add new item to ListBox (text from TextBox)
2.Remove item if one is selected from ListBoxRemove item if one is selected from ListBox
3.Clear all items in a ListBoxClear all items in a ListBox
4.ListBox selected Item changed eventListBox selected Item changed event
5.Add Object to ListBoxAdd Object to ListBox
6.Set TopIndex to auto scroll ListBoxSet TopIndex to auto scroll ListBox
7.Form with list, buttonForm with list, button
8.ListBox: font and imageListBox: font and image
9.CheckedListBox Demo 2CheckedListBox Demo 2
10.ListBox Demo 2ListBox Demo 2
11.ListBox and Metafile EnumListBox and Metafile Enum
12.ListBox ObjectsListBox Objects
13.Fill XML data to ListBox
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.