⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 diy.cs

📁 C#编程100例源码,有好多例子呀,希望对学习C#的朋友有用,这是第二个包!20个
💻 CS
字号:
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;

public class DIY : Form
{
    private Button btncont = new Button();
    private TextBox TBox = new TextBox();
    private int count = 0; //用于计数的全局变量
    
    //
    // 构造函数
    //
    DIY()
    {
        InitializeComponent(); 
    }
    
    //
    // 初始化各组件
    //
    private void InitializeComponent() 
    { 
        //
        // btncont
        //
        btncont.Text = "点点看";
        EventHandler handler = new EventHandler(btncontClick);
        btncont.Click += handler;

        //
        // TBox
        //        
        TBox.Location = new Point(0, 80);
        TBox.Size = new Size(150, 50);
        TBox.TabIndex = 1;
       
        // 
        // Form1
        // 
        this.ClientSize = new System.Drawing.Size(230, 170);
        this.Name = "Form1";
        this.Text = "Do It Yourself";
        this.ResumeLayout(false);
        this.Controls.Add(btncont);
        this.Controls.Add(TBox);
    }
    
    //
    // 按钮的click事件
    //
    private void btncontClick (object sender, EventArgs e)
    {
        count++;
        TBox.Text = "你已经点击了" + count + "次按钮";
        this.BackColor = Color.IndianRed;
        TBox.BackColor=Color.Cyan;    
    }
    
    //
    // 主函数
    //
    public static void Main(string[] args) 
    {
        Application.Run(new DIY());
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -