winform窗体应用类QQ

可分为加载界面、登录、注册、聊天、播放音乐、截图、查看天气等功能模块

加载功能
在这里插入图片描述

代码实现如下:

private void timer1_Tick(object sender, EventArgs e)//窗口透明度随时间变化
        {
            if (this.Opacity < 1)
                this.Opacity += 0.01;
            else
            {
                this.Close();
            }
            progressBar1.Value = (int)(Opacity * 100);
        }

        private void Add_Load(object sender, EventArgs e)
        {
            progressBar1.Maximum = 100;//进度条的最大值
            progressBar1.Minimum = 0;//进度条的最小值
            if(this.Opacity==1)
            {
                this.Hide();
                Form1 form1 = new Form1();
                form1.ShowDialog();
                this.Close();
            }
        }

登录界面:
在这里插入图片描述
在这里插入图片描述
代码如下:

private void Form1_Click(object sender, EventArgs e)      
        {
            if (IDBOX.Text == "")
            {
                IDBOX.Text = "请输入手机号";
            }
            if (PASSWORDBOX.Text == "")
            {
                PASSWORDBOX.Text = "请输入密码";
                PASSWORDBOX.UseSystemPasswordChar = false;
            }
        }

        private string name = " ";
private void Login_Click(object sender, EventArgs e)
        {
            string username = IDBOX.Text.Trim();
            string pwd = PASSWORDBOX.Text.Trim();
            string constr = "Server=.;Database=login;Integrated Security=True";
            SqlConnection con = new SqlConnection(constr);
            con.Open();
            SqlCommand com = new SqlCommand("Select ID password from test1 where ID='" + username + "'and password='" + pwd + "'", con);
            SqlDataAdapter da = new SqlDataAdapter(com);
            DataSet ds = new DataSet();
            int n = da.Fill(ds, "test1");

            SqlCommand com1 = new SqlCommand("Select password from test1 where and password='" + pwd + "'", con);
            SqlDataAdapter da1 = new SqlDataAdapter(com);
            DataSet ds1 = new DataSet();
            int m = da.Fill(ds, "test1");

            
            if (n != 0)
            {
                if ((IDBOX.Text != "" && IDBOX.Text != "请输入手机号") && (PASSWORDBOX.Text != "" && PASSWORDBOX.Text != "请输入密码")
                && (radioButton1.Checked == true || radioButton2.Checked == true || radioButton3.Checked == true))
                {
                    this.Hide();
                    Form3 nf = new Form3(name);
                    nf.ShowDialog();
                    this.Close();
                }

                else if (radioButton1.Checked == false && radioButton2.Checked == false && radioButton3.Checked == false)
                {
                    MessageBox.Show("请选择身份!");
                }

            }
            else
            {
                if (IDBOX.Text == "" || IDBOX.Text == "请输入手机号")
                {
                    MessageBox.Show("手机号不能为空!");
                }
                else if (PASSWORDBOX.Text == "" || PASSWORDBOX.Text == "请输入密码")
                {
                    MessageBox.Show("密码不能为空!");
                }
                else if (m == 0)
                    MessageBox.Show("输入错误!");

                IDBOX.Focus();
            }
            con.Close();
        }
        private void textBox1_Click(object sender, EventArgs e)//点击文本框输入信息
        {
            IDBOX.Text = "";//将文本框内容置为空
        }

        private void textBox2_Click_1(object sender, EventArgs e)//点击文本框输入信息
        {
            PASSWORDBOX.Text = "";//将文本框内容置为空
            PASSWORDBOX.PasswordChar = '*';//将密码样式设置为*
        }

注册功能
在这里插入图片描述

String str = "";//全局变量
        Random r = new Random();//全局对象

        private void zhuce_Click(object sender, EventArgs e)
        {
            string name = zhanghao.Text.Trim();
            string constr = "Server=.;Database=login;Integrated Security=True";
            SqlConnection con = new SqlConnection(constr);
            con.Open();
            SqlCommand com = new SqlCommand("select ID from test1 where ID='" + name + "'", con);
            // 建立SqlDataAdapter和DataSet对象
            SqlDataAdapter da = new SqlDataAdapter(com);
            DataSet ds = new DataSet();

            int n = da.Fill(ds, "账户密码");

            if (n != 0)
            {
                MessageBox.Show("手机号已注册!", "提示");
                zhanghao.Text = "";
                mima.Text = "";
            }
            else if (zhanghao.TextLength > 13)
            {
                MessageBox.Show("请输入正确手机号!");
            }

            else if (zhanghao.Text == "" || zhanghao.Text == "请输入手机号")
            {
                MessageBox.Show("手机号不能为空!");
            }
            else if (mima.Text != querenmima.Text)
            {
                MessageBox.Show("两次密码不一致!");
            }
            else if (yanzhengmaa.Text != str)
            {
                MessageBox.Show("验证码不正确!");
            }
            else if (radioButton1.Checked == false && radioButton2.Checked == false && radioButton3.Checked == false)
            {
                MessageBox.Show("请选择身份!");
            }
            else if (checkBox1.Checked == false)
            {
                MessageBox.Show("请阅读并同意相关服务政策和隐私条款!");
            }
            else
            {
                // 指定SQL语句
                com = new SqlCommand("insert into test1(ID,password) values ('"
                    + zhanghao.Text + "','" + mima.Text + "')", con);
                // 建立SqlDataAdapter和DataSet对象

                n = com.ExecuteNonQuery();
                com = null;
                if (n > 0)
                {
                    MessageBox.Show("注册成功!", "提示");
                    this.Hide();
                    Form1 nf = new Form1();
                    nf.ShowDialog();
                    this.Close();
                }

                else
                    MessageBox.Show("注册失败!", "提示");
                this.Close();
            }
            con.Close();
        }
        private void yanzhengma_Click(object sender, EventArgs e)//点击图片更换验证码
        {
            str = null;//将原有验证码清空
            for (int i = 0; i < 5; i++)//重新生成验证码
            {
                int rn = r.Next(0, 10);
                str += rn;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)//验证码的干扰条纹
        {
            Bitmap bmp = new Bitmap(120, 120);
            Graphics g = Graphics.FromImage(bmp);

            for (int i = 0; i < 5; i++)
            {
                String[] fonts = { "微软雅黑", "宋体", "黑体", "隶书", "仿宋" };//随机设置字体的样式
                Point p = new Point(i * 15, 0);
                Color[] colors = { Color.Red, Color.Pink, Color.Black, Color.Gray, Color.GreenYellow };//随机设置字体的颜色
                g.DrawString(str[i].ToString(), new Font(fonts[r.Next(0, 5)], 20, FontStyle.Bold), new SolidBrush(colors[r.Next(0, 5)]), p);//画图

            }
            for (int i = 0; i < 100; i++)//画出声燥线

            {
                Point p1 = new Point(r.Next(0, bmp.Width), r.Next(0, bmp.Height));
                Point p2 = new Point(r.Next(0, bmp.Width), r.Next(0, bmp.Height));
                g.DrawLine(new Pen(Brushes.Green), p1, p2);
            }
            yanzhengma.Image = bmp;
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            timer1.Start();
            for (int i = 0; i < 5; i++)
            {
                int rn = r.Next(0, 10);
                str += rn;
            }
        }

        private void Form2_Click(object sender, EventArgs e)
        {
            if (name.Text == "")
            {
                name.Text = "请输入姓名";
            }
            if (IDname.Text == "")
            {
               IDname.Text = "请输入昵称";
            }
            if (zhanghao.Text == "")
            {
                zhanghao.Text = "请输入手机号";
            }
            if (mima.Text == "")
            {
                mima.Text = "请输入密码";
                mima.UseSystemPasswordChar = false;
            }
            if (querenmima.Text == "")
            {
                querenmima.Text = "请确认密码";
                querenmima.UseSystemPasswordChar = false;
            }
            if (yanzhengmaa.Text == "")
            {
                yanzhengmaa.Text = "请输入验证码";
            }
        }
        private void name_Click(object sender, EventArgs e)
        {
            name.Text = "";//将文本框内容置为空
        }
        private void IDname_Click(object sender, EventArgs e)
        {
            IDname.Text = "";//将文本框内容置为空
        }

        private void zhanghao_Click(object sender, EventArgs e)//点击文本框输入信息
        {
            zhanghao.Text = "";//将文本框内容置为空
        }

        private void mima_Click(object sender, EventArgs e)//点击文本框输入信息
        {
            mima.Text = "";//将文本框内容置为空
            mima.PasswordChar = '*';//将密码样式设置为*
        }

        private void querenmima_Click(object sender, EventArgs e)//点击文本框输入信息
        {
            querenmima.Text = "";//将文本框内容置为空
            querenmima.PasswordChar = '*';//将密码样式设置为*
        }

        private void textBox4_Click(object sender, EventArgs e)//点击文本框输入信息
        {
            yanzhengmaa.Text = "";//将文本框内容置为空
        }

聊天功能
在这里插入图片描述

private void send_Click(object sender, EventArgs e)
        {
            UdpClient udpClient = new UdpClient();
            udpClient.Connect("192.0.62.22", 10001);
            byte[] data = Encoding.UTF8.GetBytes(name + " " + DateTime.Now.ToString() + "\n" + richTextBox2.Text + "\n");
            udpClient.Send(data, data.Length);
            udpClient.Close();
            if (richTextBox2.Text == "")
            {
                MessageBox.Show("发送内容不能为空!");
            }
            else
                richTextBox1.Text += name + " " + DateTime.Now.ToString() + "\n" + richTextBox2.Text + "\n";
            richTextBox2.Clear();
        }
        private void chakanjilu_Click(object sender, EventArgs e)
        {
            pictureBox1.Hide();
            richTextBox3.Show();
            richTextBox3.Text = "\n" + richTextBox1.Text;
            label1.Visible = true;
        }

        private void guanbijilu_Click(object sender, EventArgs e)
        {
            pictureBox1.Visible = true;
            label1.Visible = false;
            richTextBox3.Hide();
        }

在这里插入图片描述

天气查询功能

private void button1_Click(object sender, EventArgs e)
        {
            cn.com.webxml.www.WeatherWebService w = new cn.com.webxml.www.WeatherWebService();
            string[] s = new string[23];//声明string数组存放返回结果  
            string city = this.textBox1.Text.Trim();//获得文本框录入的查询城市  
            s = w.getWeatherbyCityName(city);
            if (s[8] == "")
            {
                MessageBox.Show("输入错误,请重新输入");
            }
            else
            {
                textBox2.Text = s[1] + " " + s[6] + s[10];
            }
        }

在这里插入图片描述
以上是部分功能实现,如需完整代码或者需要连接数据库的代码可私信我

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值