仿QQ登录

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 qq
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            //点击登录后跳转到新页面
            //创建新窗口,实现点击跳转
            /*Form2 form2 = new Form2();
            form2.Show();*/

            //实现不同窗体随机背景颜色
            /*  Random r = new Random();
              for(int i=0;i<10;i++)
              {
                  Color color = Color.FromArgb(255, r.Next(32, 250), r.Next(0, 255));
                  Form2 form2 = new Form2();
                  form2.BackColor = color;
                  form2.Show();
              }*/

            //实现不同窗体随机位置

            Random r = new Random();

            //使用Screen类中的GetWorkingArea方法来获取除去任务栏的工作区域的分辨率,以便考虑到任务栏的影响:
            Rectangle workingArea = Screen.GetWorkingArea(this);
            int workingWidth = workingArea.Width;
            int workingHeight = workingArea.Height;

            for (int i = 0; i < 50; i++)
            {
                Form2 form2 = new Form2();

                //随机位置
                /*Point location = new Point(r.Next(1920), r.Next(1080));
                form2.Location = location;*/

                //实现自适应电脑分辨率
                int formWidth = 800; // 设置窗体的初始宽度
                int formHeight = 600; // 设置窗体的初始高度

                // 计算窗体的缩放比例
                float widthRatio = (float)workingWidth / formWidth;
                float heightRatio = (float)workingHeight / formHeight;
                float scale = Math.Min(widthRatio, heightRatio);

                // 缩放窗体的控件
                form2.Scale(new SizeF(scale, scale));

                // 调整窗体的位置
                int x = (workingWidth - form2.Width) / 2;
                int y = (workingHeight - form2.Height) / 2;
                form2.Location = new Point(x, y);



                //随机颜色
                Color color = Color.FromArgb(r.Next(255), r.Next(255), r.Next(255));
                form2.BackColor = color;
                form2.Show();


            }
        }

        private void panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        //头像移动
        int step = 0;
        private void picHead_MouseEnter(object sender, EventArgs e)
        {
            step = 5;
            //开启定时器
            timer1.Enabled = true;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //默认 interval =100ms 执行一次
            picAdd.Location = new Point(picAdd.Location.X + step, picAdd.Location.Y);

            if (picAdd.Location.X > 350)
            {
                step = 0;
            }
            if (picAdd.Location.X < 255)
            {
                step = 0;
            }

        }

        private void picHead_MouseLeave(object sender, EventArgs e)
        {
            //鼠标移走 头像返回
            timer1.Enabled = true;
            step =-5;

        }

        private void picQrCode_MouseEnter(object sender, EventArgs e)
        {
            //鼠标移入
            picQrCode.BackgroundImage = Properties.Resources.tdcode1;

        }

        private void picQrCode_MouseLeave(object sender, EventArgs e)
        {
            //鼠标移走
            picQrCode.BackgroundImage = Properties.Resources.tdcode;

        }

        private void picClose_MouseEnter(object sender, EventArgs e)
        {
            picClose.BackColor = Color.Red;

        }

        private void picClose_MouseLeave(object sender, EventArgs e)
        {
            picClose.BackColor = Color.Transparent;
        }

        private void picClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值