WinForm 窗体

Winform是.NET开发中对windows Form的一种称谓,form是窗体的意思,winform 称之为windows form。

一般中我们使用的东西分为 客户端、网页、APP 三大类。

winfrom属于客户端应用程序  c/s 

客户端代码是执行在客户端上的,通过用户电脑运行,用户电脑配置越高,运行越快。

 

客户端和网页的区别:

客户端是需要一个项目在用户电脑上;

网页 只需要一个浏览器就可以。

 

客户端的特点:

可以操作的用户电脑的文件(可以写文件,读取文件)。

 

 

                    可视化的窗体

  界面代码

界面后台代码

 

 

点开可视化窗体 →视图→工具箱→点开

               

 

可以把控件的东西  拖拽到窗体上去

 

                 多选项                                        单选项                

 下拉框

         文本框                                              按钮

 

label    在窗体显示的文字

text    文本框,让用户输入的内容

checkBox   多选项

radioButton 单选项

comboBox 下拉框

button 按钮

 

右键控件点击  属性  

Text  显示的文本文字

Font   字体样式

ForeColor 前景色,字体颜色

BackColor 背景色

调好之后

简单的窗体创建出来了

点击事件

下单按钮→属性→ 事件→操作→Click→双击    就可以了

checkBox1.Text  选项中给用户显示的文本名

checkBox1.checked 显示选中状态,返回bool类型

radiobutton.Text  选项中给用户显示的文本名

radiobutton.checked  显示选中状态,返回bool类型

comboBox1.SelectedItem.Tostring()     显示下拉给用户看到的内容,没有返回null

下拉框          选中项         转string类型

TextBox1.Text  用户输入的文本框内容

MessageBox.Show();弹出小窗口提示

 private void button1_Click(object sender, EventArgs e)
        {
            string end = "您的订餐为:\r";
            //先获取主食
            if (checkBox1.Checked)
                end += checkBox1.Text + ",";
            if (checkBox2.Checked)
                end += checkBox2.Text + ",";
            if (checkBox3.Checked)
                end += checkBox3.Checked + ",";
            //配餐
            if (radioButton1.Checked)
                end += radioButton1.Text + ",";
            if (radioButton2.Checked)
                end += radioButton2.Text + ",";
            //饮品
            if (comboBox1.SelectedItem != null)
                end += comboBox1.SelectedItem.ToString() + "";

            if (end.Substring(end.Length - 1) == ",")
            {
                end.Remove(end.Length - 1);
                end += "";
            }

            end += "\r";
                //电话
            end += "您的电话是:\r"+textBox1.Text;
            MessageBox.Show(end);
        }
View Code

 

账号登录界面

public class UsersData
    {
        SqlConnection conn = null;
        SqlCommand cmd = null;
        public UsersData()
        {
            conn = new SqlConnection("server=.;database=dat0216;user=sa;pwd=123;");
            cmd = conn.CreateCommand();
        }
        public bool HasSelect(string name, string pwd)
        {
            bool has = false;
            cmd.CommandText = "select *from Users where UserName=@a and PassWard=@b";
            cmd.Parameters.Clear();
            cmd.Parameters.AddWithValue("@a",name);
            cmd.Parameters.AddWithValue("@b",pw
);
            conn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.HasRows)
                has = true;
            conn.Close();
            return has;
        }
    }
View Code

点击事件

   private void button1_Click(object sender, EventArgs e)
        {
            string name = textBox1.Text;
            string pwd = textBox2.Text;
            if (new UsersData().HasSelect(name, pwd))
            { MessageBox.Show("登录成功"); }
            else
            { MessageBox.Show("账号密码错误"); }
        }
View Code

 

posted @ 2017-04-24 23:51  天晴微笑  阅读(872)  评论(0编辑  收藏  举报