winform窗口的工具箱

 在WinForm窗体中,工具箱是一个非常重要的功能区,它包含了许多常用的控件,如按钮、标签、文本框等等。使用工具箱可以方便地向窗体中添加控件,从而实现窗体的各种功能。

1:发现和查找工具箱

打开Visual Studio,创建一个WinForm项目。
在Visual Studio的界面中找到工具箱,如果没有显示出来,可以通过菜单栏的“视图”->“工具箱”打开。

 (2)还有可以在搜索框可以搜索工具箱

 2:使用用工具箱

在工具箱中找到“Button”控件,可以通过拖拽的方式将其拖到窗体中。

 在窗体中调整按钮的位置和大小,可以通过属性窗口来设置按钮的属性,如文本、字体、颜色等等。

3: 在代码中添加按钮的事件处理程序,可以通过双击按钮

这就是写按钮代码的位置

第二章

WinForm是一种基于Windows操作系统的GUI框架,它提供了一种创建Windows桌面应用程序的方式。下面是WinForm中一些基本控件的使用方法:

1:Label控件:用于显示文本或图像。

Label label1 = new Label();
label1.Text = "Hello World!";

2:Button控件:用于触发事件

Button button1 = new Button();
button1.Text = "Click me!";
button1.Click += new EventHandler(button1_Click);
private void button1_Click(object sender, EventArgs e)
{
    MessageBox.Show("Button clicked!");
}

3:TextBox控件:用于输入文本。

TextBox textBox1 = new TextBox();

textBox1.Text = "Enter text here";

4:CheckBox控件:用于选择一个或多个选项。

CheckBox checkBox1 = new CheckBox();

checkBox1.Text = "Check me!";

checkBox1.CheckedChanged += new EventHandler(checkBox1_CheckedChanged);

private void checkBox1_CheckedChanged(object sender, EventArgs e) { if (checkBox1.Checked) { MessageBox.Show("Checked!");

} else { MessageBox.Show("Unchecked!"); } }

5:RadioButton控件:用于选择一个选项

RadioButton radioButton1 = new RadioButton();

radioButton1.Text = "Select me!";

radioButton1.CheckedChanged += new EventHandler(radioButton1_CheckedChanged);

private void radioButton1_CheckedChanged(object sender, EventArgs e) {

if (radioButton1.Checked) { MessageBox.Show("Selected!"); }

}

6:ComboBox控件:用于选择一个选项。

ComboBox comboBox1 = new ComboBox();

comboBox1.Items.Add("Option 1");

comboBox1.Items.Add("Option 2");

comboBox1.SelectedIndex = 0;

comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged); private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { MessageBox.Show("Selected: " + comboBox1.SelectedItem.ToString());

}

7:ListBox控件:用于选择一个或多个选项

ListBox listBox1 = new ListBox();

listBox1.Items.Add("Option 1");

listBox1.Items.Add("Option 2");

listBox1.SelectedIndex = 0;

listBox1.SelectedIndexChanged += new EventHandler(listBox1_SelectedIndexChanged); private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { MessageBox.Show("Selected: " + listBox1.SelectedItem.ToString()); }

8:PictureBox控件:用于显示图像。

tureBox pictureBox1 = new PictureBox();

pictureBox1.Image = Image.FromFile("image.jpg");

9:NotifyIcon控件:用于在系统托盘中显示图标和提示信息。

NotifyIcon notifyIcon1 = new NotifyIcon();

notifyIcon1.Icon = new Icon("icon.ico");

notifyIcon1.Visible = true;

notifyIcon1.BalloonTipTitle = "Title";

notifyIcon1.BalloonTipText = "Text";

notifyIcon1.ShowBalloonTip(5000);

WinForm链接sql数据库

等等同学们,还有一个重要的知识,WinForm链接sql数据库,你可以使用C#链接sql数据库,下面是一个简单的链接代码,

 public static  class FrmChooseDoctor
    {
        static string connstr = ConfigurationManager.ConnectionStrings["SQLConnString"].ConnectionString;

        public static DataSet getDatasetdata(SqlParameter[] sqlParameters, string sqlstr)
        {
            SqlConnection conn = new SqlConnection(connstr);
            DataSet ds = new DataSet();
            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = sqlstr;
                cmd.Connection = conn;
                if (sqlParameters != null)
                {
                    cmd.Parameters.AddRange(sqlParameters);
                }
                SqlDataAdapter sda = new SqlDataAdapter(cmd);
                sda.Fill(ds, "searchdata");
                return ds;
            }
            catch (Exception ex)
            {
                DataTable dt = new DataTable();
                DataColumn dc = new DataColumn();
                dc.ColumnName = "错误提示";
                dt.Columns.Add(dc);
                DataRow dr = dt.NewRow();
                dr["错误提示"] = ex.Message;
                dt.Rows.Add(dr);
                ds.Tables.Add(dt);
                return ds;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }

        internal static DataSet getDatasetData(SqlParameter[] sqlParameter, string sqlstr)
        {
            throw new NotImplementedException();
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值