当前位置: 首页>>代码示例>>C#>>正文


C# Color.LightGray属性代码示例

本文整理汇总了C#中System.Drawing.Color.LightGray属性的典型用法代码示例。如果您正苦于以下问题:C# Color.LightGray属性的具体用法?C# Color.LightGray怎么用?C# Color.LightGray使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在System.Drawing.Color的用法示例。


在下文中一共展示了Color.LightGray属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FormAddControls

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace AddControls
{
  /// <summary>
  /// Summary description for FormAddControls.
  /// </summary>
  public class FormAddControls : System.Windows.Forms.Form
  {
    private System.Windows.Forms.ListBox listBox1;
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.TextBox textBox1;
    private System.Windows.Forms.Button button2;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public FormAddControls()
    {
      //
      // 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.textBox1 = new System.Windows.Forms.TextBox();
      this.button1 = new System.Windows.Forms.Button();
      this.button2 = new System.Windows.Forms.Button();
      this.listBox1 = new System.Windows.Forms.ListBox();
      this.SuspendLayout();
      // 
      // textBox1
      // 
      this.textBox1.Location = new System.Drawing.Point(38, 200);
      this.textBox1.Name = "textBox1";
      this.textBox1.Size = new System.Drawing.Size(216, 20);
      this.textBox1.TabIndex = 1;
      this.textBox1.Text = "";
      // 
      // button1
      // 
      this.button1.Location = new System.Drawing.Point(48, 240);
      this.button1.Name = "button1";
      this.button1.Size = new System.Drawing.Size(80, 24);
      this.button1.TabIndex = 2;
      this.button1.Text = "Add Item";
      this.button1.Click += new System.EventHandler(this.button1_Click);
      this.button1.MouseEnter += new System.EventHandler(this.Buttons_OnMouseEnter);
      this.button1.MouseLeave += new System.EventHandler(this.Buttons_OnMouseLeave);
      // 
      // button2
      // 
      this.button2.Location = new System.Drawing.Point(160, 240);
      this.button2.Name = "button2";
      this.button2.Size = new System.Drawing.Size(96, 24);
      this.button2.TabIndex = 3;
      this.button2.Text = "Cancel";
      this.button2.Click += new System.EventHandler(this.button2_Click);
      this.button2.MouseEnter += new System.EventHandler(this.Buttons_OnMouseEnter);
      this.button2.MouseLeave += new System.EventHandler(this.Buttons_OnMouseLeave);
      // 
      // listBox1
      // 
      this.listBox1.Location = new System.Drawing.Point(38, 32);
      this.listBox1.Name = "listBox1";
      this.listBox1.Size = new System.Drawing.Size(216, 147);
      this.listBox1.TabIndex = 0;
      // 
      // FormAddControls
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(292, 273);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.button2,
                                      this.button1,
                                      this.textBox1,
                                      this.listBox1});
      this.Name = "FormAddControls";
      this.Text = "FormAddControls";
      this.ResumeLayout(false);

    }
    #endregion

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
      Application.Run(new FormAddControls());
    }

    private void button1_Click(object sender, System.EventArgs e)
    {
      if (textBox1.Text == "")
        return;
      string strAdd = textBox1.Text;
      if (listBox1.FindString (strAdd, -1) < 0)
      {
        listBox1.Items.Add (strAdd);
        textBox1.Text = "";
        textBox1.Focus ();
        return;
      }
      MessageBox.Show ("\"" + strAdd + "\" is already in the list box", "Duplicate");
    }

    private void button2_Click(object sender, System.EventArgs e)
    {
      Application.Exit();
    }

    private void Buttons_OnMouseEnter(object sender, System.EventArgs e)
    {
      Button btn = (Button) sender;
      btn.BackColor = Color.LightGray;
    }

    private void Buttons_OnMouseLeave(object sender, System.EventArgs e)
    {
      Button btn = (Button) sender;
      btn.BackColor = SystemColors.Control;
    }
  }
}
开发者ID:C#程序员,项目名称:System.Drawing,代码行数:165,代码来源:Color.LightGray


注:本文中的System.Drawing.Color.LightGray属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。