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();
}
}
}
04-06
812
05-23
11-02