using System;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MinorClient
{
public class FormLogin : Form
{
private TextBox txtNick, txtPassword;
private Button btnLogin;
private Panel panelContainer;
private Label lblTitle;
private Timer fadeInTimer;
private float opacityIncrement = 0.05f;
private bool dragging = false;
private Point dragCursorPoint;
private Point dragFormPoint;
public FormLogin()
{
this.FormBorderStyle = FormBorderStyle.None;
this.Size = new Size(520, 400);
this.StartPosition = FormStartPosition.CenterScreen;
this.BackColor = Color.FromArgb(25, 25, 25);
this.Opacity = 0;
fadeInTimer = new Timer { Interval = 20 };
fadeInTimer.Tick += (s, e) =>
{
if (this.Opacity < 1) this.Opacity += opacityIncrement;
else fadeInTimer.Stop();
};
fadeInTimer.Start();
panelContainer = new Panel
{
Size = new Size(480, 360),
Location = new Point(20, 20),
BackColor = Color.FromArgb(30, 30, 30),
BorderStyle = BorderStyle.None
};
panelContainer.MouseDown += Panel_MouseDown;
panelContainer.MouseMove += Panel_MouseMove;
panelContainer.MouseUp += Panel_MouseUp;
this.Controls.Add(panelContainer);
lblTitle = new Label
{
Text = "Minor Client",
Font = new Font("Montserrat", 32, FontStyle.Bold),
ForeColor = Color.FromArgb(0, 175, 240),
AutoSize = false,
TextAlign = ContentAlignment.MiddleCenter,
Dock = DockStyle.Top,
Height = 100
};
panelContainer.Controls.Add(lblTitle);
txtNick = CreateTextBox("Nick", 60, 120);
panelContainer.Controls.Add(txtNick);
txtPassword = CreateTextBox("Password", 60, 180, true);
panelContainer.Controls.Add(txtPassword);
btnLogin = CreateButton("Login", 180, 250);
btnLogin.Click += (s, e) => MessageBox.Show("Login Clicked!");
panelContainer.Controls.Add(btnLogin);
this.Paint += (s, e) =>
{
using (var pen = new Pen(Color.FromArgb(0, 175, 240), 2))
e.Graphics.DrawRectangle(pen, new Rectangle(0, 0, this.Width - 1, this.Height - 1));
};
}
private TextBox CreateTextBox(string placeholder, int x, int y, bool isPassword = false)
{
TextBox tb = new TextBox
{
Location = new Point(x, y),
Width = 360,
Height = 45,
BackColor = Color.FromArgb(50, 50, 50),
ForeColor = Color.Gray,
BorderStyle = BorderStyle.None,
Font = new Font("Segoe UI", 13, FontStyle.Regular),
UseSystemPasswordChar = false
};
SetPlaceholder(tb, placeholder, isPassword);
return tb;
}
private void SetPlaceholder(TextBox textBox, string placeholder, bool isPassword = false)
{
textBox.Text = placeholder;
textBox.ForeColor = Color.Gray;
textBox.Enter += (s, e) =>
{
if (textBox.Text == placeholder)
{
textBox.Text = "";
textBox.ForeColor = Color.White;
if (isPassword) textBox.UseSystemPasswordChar = true;
}
};
textBox.Leave += (s, e) =>
{
if (string.IsNullOrWhiteSpace(textBox.Text))
{
textBox.Text = placeholder;
textBox.ForeColor = Color.Gray;
if (isPassword) textBox.UseSystemPasswordChar = false;
}
};
}
private Button CreateButton(string text, int x, int y)
{
Button btn = new Button
{
Text = text,
Location = new Point(x, y),
Width = 160,
Height = 50,
BackColor = Color.FromArgb(0, 175, 240),
FlatStyle = FlatStyle.Flat,
ForeColor = Color.White,
Font = new Font("Segoe UI Semibold", 14, FontStyle.Bold)
};
btn.FlatAppearance.BorderSize = 0;
btn.MouseEnter += async (s, e) => await AnimateButtonColor(btn, Color.FromArgb(0, 200, 255));
btn.MouseLeave += async (s, e) => await AnimateButtonColor(btn, Color.FromArgb(0, 175, 240));
return btn;
}
private async Task AnimateButtonColor(Button btn, Color targetColor)
{
Color startColor = btn.BackColor;
int steps = 10;
for (int i = 1; i <= steps; i++)
{
int r = startColor.R + (targetColor.R - startColor.R) * i / steps;
int g = startColor.G + (targetColor.G - startColor.G) * i / steps;
int b = startColor.B + (targetColor.B - startColor.B) * i / steps;
btn.BackColor = Color.FromArgb(r, g, b);
await Task.Delay(15);
}
}
private void Panel_MouseDown(object sender, MouseEventArgs e)
{
dragging = true;
dragCursorPoint = Cursor.Position;
dragFormPoint = this.Location;
}
private void Panel_MouseMove(object sender, MouseEventArgs e)
{
if (dragging)
{
Point diff = Point.Subtract(Cursor.Position, new Size(dragCursorPoint));
this.Location = Point.Add(dragFormPoint, new Size(diff));
}
}
private void Panel_MouseUp(object sender, MouseEventArgs e)
{
dragging = false;
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormLogin());
}
}
}