Files
2026-07-03 16:43:53 +09:00

147 lines
5.4 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
namespace ControlServer
{
public partial class Form2 : Form
{
public TerminalInfo TerminalData { get; private set; } = new TerminalInfo();
// 둥근 모서리 반지름 설정
private const int CornerRadius = 15;
public Form2()
{
InitializeComponent();
// 1. 버튼 테두리 없애고 Flat 스타일로 변경
ConfigureModernButtons();
btnRegister.BackColor = Color.FromArgb(160, 180, 240); // 연해진 블루
btnRegister.Enabled = false; // 저장버튼 비활성화
// 모든 텍스트박스의 값이 변할 때마다 실행될 이벤트 연결
txtBoxName.TextChanged += ValidateInputs;
txtBoxIP.TextChanged += ValidateInputs;
txtBoxPort.TextChanged += ValidateInputs;
txtBoxMac.TextChanged += ValidateInputs;
// 2. 둥근 모서리를 그리기 위한 Paint 이벤트 연결
if (lblBox != null) lblBox.Paint += lblBox_Paint;
btnRegister.Paint += Button_Paint;
btnCancel.Paint += Button_Paint;
}
private void ConfigureModernButtons()
{
// 등록 버튼 스타일 설정
btnRegister.FlatStyle = FlatStyle.Flat;
btnRegister.FlatAppearance.BorderSize = 0; // 보더라인 삭제
// 취소 버튼 스타일 설정
btnCancel.BackColor = Color.FromArgb(230, 235, 240);
btnCancel.FlatStyle = FlatStyle.Flat;
btnCancel.FlatAppearance.BorderSize = 0; // 보더라인 삭제
}
// 컨트롤을 둥글게 만들기 위한 공통 경로 생성 메서드
private GraphicsPath GetRoundPath(Rectangle bounds, int radius)
{
GraphicsPath path = new GraphicsPath();
int diameter = radius * 2;
path.AddArc(bounds.X, bounds.Y, diameter, diameter, 180, 90);
path.AddArc(bounds.Right - diameter, bounds.Y, diameter, diameter, 270, 90);
path.AddArc(bounds.Right - diameter, bounds.Bottom - diameter, diameter, diameter, 0, 90);
path.AddArc(bounds.X, bounds.Bottom - diameter, diameter, diameter, 90, 90);
path.CloseAllFigures();
return path;
}
// 흰색 배경 박스 둥글게 자르기
private void lblBox_Paint(object? sender, PaintEventArgs e)
{
if (sender is Panel panel)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (GraphicsPath path = GetRoundPath(new Rectangle(0, 0, panel.Width, panel.Height), CornerRadius))
{
panel.Region = new Region(path);
}
}
}
// 버튼 둥글게 자르기
private void Button_Paint(object? sender, PaintEventArgs e)
{
if (sender is Button button)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
// 버튼은 박스보다 조금 더 작으므로 반지름을 10 정도로 주면 예쁩니다
using (GraphicsPath path = GetRoundPath(new Rectangle(0, 0, button.Width, button.Height), 10))
{
button.Region = new Region(path);
}
}
}
private void ValidateInputs(object? sender, EventArgs e)
{
bool isValid = !string.IsNullOrWhiteSpace(txtBoxName.Text) &&
!string.IsNullOrWhiteSpace(txtBoxIP.Text) &&
!string.IsNullOrWhiteSpace(txtBoxPort.Text) &&
!string.IsNullOrWhiteSpace(txtBoxMac.Text);
btnRegister.Enabled = isValid;
// [팁] 비활성화 상태일 때 버튼 색상 피드백을 주면 더 자연스럽습니다.
if (isValid)
{
btnRegister.BackColor = Color.FromArgb(65, 105, 225); // 원래 로열 블루 색상
}
else
{
btnRegister.BackColor = Color.FromArgb(160, 180, 240); // 연해진 블루
}
}
private void btnCancel_MouseClick(object sender, MouseEventArgs e)
{
this.Close();
}
private void btnRegister_MouseClick(object sender, MouseEventArgs e)
{
// 1. DB 중복 데이터 확인
// 2. 메시지박스 띄우기 (알림 아이콘과 OK 버튼 포함)
DialogResult result = MessageBox.Show(
"등록되었습니다.",
"알림",
MessageBoxButtons.OK,
MessageBoxIcon.Information
);
// 사용자가 메시지박스의 '확인'을 누르면 데이터 저장 진행
if (result == DialogResult.OK)
{
this.TerminalData = new TerminalInfo
{
TerminalName = txtBoxName.Text.Trim(),
IP = txtBoxIP.Text.Trim(),
Port = txtBoxPort.Text.Trim(),
Mac = txtBoxMac.Text.Trim(),
};
}
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}