Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

c#控件

作者:龙之灬殇   发布日期:2025-03-12   浏览:274

using System;
using System.Windows.Forms;

namespace CSharpControlsExample
{
    public class ExampleForm : Form
    {
        public ExampleForm()
        {
            // 创建一个按钮控件
            Button button = new Button
            {
                Text = "点击我",
                Location = new System.Drawing.Point(50, 50)
            };

            // 添加按钮点击事件处理程序
            button.Click += (sender, e) => 
            {
                MessageBox.Show("你点击了按钮!");
            };

            // 创建一个文本框控件
            TextBox textBox = new TextBox
            {
                Location = new System.Drawing.Point(50, 100),
                Width = 200
            };

            // 创建一个标签控件
            Label label = new Label
            {
                Text = "请输入内容:",
                Location = new System.Drawing.Point(50, 80)
            };

            // 将控件添加到窗体中
            this.Controls.Add(button);
            this.Controls.Add(textBox);
            this.Controls.Add(label);

            // 设置窗体属性
            this.Text = "C# 控件示例";
            this.Size = new System.Drawing.Size(300, 200);
        }

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

解释说明

  1. Button 控件:

    • 创建了一个按钮控件,并设置了其位置和文本。
    • 绑定了按钮的点击事件,当用户点击按钮时会弹出一个消息框。
  2. TextBox 控件:

    • 创建了一个文本框控件,用于用户输入文本。
    • 设置了文本框的位置和宽度。
  3. Label 控件:

    • 创建了一个标签控件,用于显示提示信息。
    • 设置了标签的位置和文本。
  4. 窗体设置:

    • 设置了窗体的标题和大小。
    • 使用 this.Controls.Add 方法将各个控件添加到窗体中。
  5. 主程序入口:

    • 使用 Application.Run 方法启动应用程序并显示窗体。

上一篇:c# checkedlistbox

下一篇:c# textbox

大家都在看

c# 二进制

c# tcp client

c# type.gettype

c# sqlconnection

.net和c#

c#游戏开发

c#网络编程

c# rectangle

c# if else

c# rtsp

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站