当前位置: 首页> 科技> 互联网 > 建筑模板哪种好_赣州章贡区疫情最新消息_怎么样进行网络推广_如何制作网址

建筑模板哪种好_赣州章贡区疫情最新消息_怎么样进行网络推广_如何制作网址

时间:2025/7/12 2:58:55来源:https://blog.csdn.net/think__deeply/article/details/147519876 浏览次数:0次
建筑模板哪种好_赣州章贡区疫情最新消息_怎么样进行网络推广_如何制作网址

使用的控件有:Button,Label,TextBox

button:表示一个按钮,用户点击按钮触发事件 click事件最常用

label:标签,用于显示文本   Name属性:变量名称

textBox:输入框
 

Form1代码:

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

namespace _1.Winform控件学习
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //控件除了拖拽,也可以自定义(窍门:查看属性列表)
            TextBox userNameTextBox = new TextBox
            {

                Location = new Point(350, 40),
                Size = new Size(200, 20),
                PasswordChar = '*',
            };
            //Controls代表当前窗体的控制集合
            this.Controls.Add(userNameTextBox);
        }
        //按钮点击时执行的事件
        //1.事件绑定者
        //2.事件的基类
        private void button1_Click(object sender, EventArgs e)
        {
            //MessageBox:消息提示框
            //show:弹出的文本
            MessageBox.Show("这是一个简单的消息提示框");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //带有标题
            MessageBox.Show("带有标题的提示框","早上好");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //制定按钮和图标:选项和图标都是枚举
            //DialogResult:代表获取用户的点击
            DialogResult result = MessageBox.Show("这是一个带有按钮和图标的对话框","早上好",MessageBoxButtons.YesNo,MessageBoxIcon.Question);

            //具体的判断根据Show中的枚举来配对
            if (result ==DialogResult.Yes)
            {
                //获取到当前label标签,添加内容
                this.resultLabel.Text = "用户确定了,点击了yes";
            }
            else
            {
                this.resultLabel.Text = "用户取消了,点击了No";
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            //指定默认按钮:用户按下回车触发的按钮
            //MessageBoxDefaultButton.Button2:默认为第二个按钮(否)
            //MessageBoxDefaultButton.Button1:默认为第一个按钮(是)
            MessageBox.Show("这是一个带有默认按钮的对话框","我是标题",MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            //案例
            MessageBox.Show("欢迎来到winform教程","欢迎大家");
            DialogResult result = MessageBox.Show("确定要学习吗?", "态度选择", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {
                MessageBox.Show("您选择了是,程序会继续运行", "提醒");
            }
            else
            {
                MessageBox.Show("您选择了否,程序将退出", "提醒");
                //关闭程序
                this.Close();
            }

        }

        private void button6_Click(object sender, EventArgs e)
        {
            string userInput = AccountTxt.Text;
            if (userInput =="admin")
            {
                MessageBox.Show("欢迎");
            }
            else
            {
                MessageBox.Show("输入错误");
            }
        }
    }
}

关键字:建筑模板哪种好_赣州章贡区疫情最新消息_怎么样进行网络推广_如何制作网址

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: