[성현모] 타이틀바, 리사이즈, 아이콘 추가

This commit is contained in:
SHM
2026-03-09 16:43:30 +09:00
parent 4db0c87735
commit 01a64ce2aa
8 changed files with 3957 additions and 2 deletions

View File

@ -22,7 +22,8 @@ namespace eCIAv2.Library.Services
var configJson = File.ReadAllText(ConfigPath); var configJson = File.ReadAllText(ConfigPath);
Config = JsonConvert.DeserializeObject<eCIAConfig>(configJson); Config = JsonConvert.DeserializeObject<eCIAConfig>(configJson);
LogXnet.WriteLine($"Config read Success.", LogXLabel.INFO); LogXnet.WriteLine($"eCIA Config read Success.");
LogXnet.WriteLine($"Path:{ConfigPath}");
return Config; return Config;
} }

View File

@ -28,13 +28,16 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
SuspendLayout(); SuspendLayout();
// //
// MainForm // MainForm
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
BackColor = Color.FromArgb(24, 28, 32);
ClientSize = new Size(800, 450); ClientSize = new Size(800, 450);
Icon = (Icon)resources.GetObject("$this.Icon");
Name = "MainForm"; Name = "MainForm";
Text = "eCIAv2"; Text = "eCIAv2";
ResumeLayout(false); ResumeLayout(false);

View File

@ -3,16 +3,205 @@ using eCIAv2.Library.Devices.DIIO;
using eCIAv2.Library.Devices.Scanner; using eCIAv2.Library.Devices.Scanner;
using eCIAv2.WindowsApp.ViewModels; using eCIAv2.WindowsApp.ViewModels;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System.Runtime.InteropServices;
using static System.Net.Mime.MediaTypeNames;
namespace eCIAv2.WindowsApp namespace eCIAv2.WindowsApp
{ {
public partial class MainForm : Form public partial class MainForm : Form
{ {
#region Custom TitleBar
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(
IntPtr hWnd, int Msg, int wParam, int lParam);
private Panel titleBar;
private void CreateCustomTitle()
{
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
this.MinimumSize = new Size(600, 400);
titleBar = new Panel();
titleBar.Height = 36;
titleBar.Dock = DockStyle.Top;
titleBar.BackColor = Color.FromArgb(40, 40, 40);
titleBar.MouseDown += TitleBar_MouseDown;
this.Controls.Add(titleBar);
CreateTitleIcon();
CreateTitleLabel();
CreateButtons();
}
private void CreateTitleIcon()
{
PictureBox icon = new PictureBox();
icon.Image = this.Icon.ToBitmap();
icon.SizeMode = PictureBoxSizeMode.StretchImage;
icon.Size = new Size(20, 20);
icon.Location = new Point(8, 8);
titleBar.Controls.Add(icon);
}
private void CreateTitleLabel()
{
Label lbl = new Label();
lbl.Text = this.Text;
lbl.ForeColor = Color.White;
lbl.AutoSize = true;
lbl.Location = new Point(36, 9);
titleBar.Controls.Add(lbl);
}
private void CreateButtons()
{
Button btnClose = CreateTitleButton("X");
btnClose.Click += (s, e) => this.Close();
Button btnMax = CreateTitleButton("<22><>");
btnMax.Click += (s, e) =>
{
ToggleMaximize();
};
Button btnMin = CreateTitleButton("<22><>");
btnMin.Click += (s, e) =>
{
this.WindowState = FormWindowState.Minimized;
};
titleBar.Controls.Add(btnMin);
titleBar.Controls.Add(btnMax);
titleBar.Controls.Add(btnClose);
}
private Button CreateTitleButton(string text)
{
Button btn = new Button();
btn.Text = text;
btn.Dock = DockStyle.Right;
btn.Width = 45;
btn.FlatStyle = FlatStyle.Flat;
btn.FlatAppearance.BorderSize = 0;
btn.ForeColor = Color.White;
btn.BackColor = Color.FromArgb(40, 40, 40);
btn.MouseEnter += (s, e) =>
{
btn.BackColor = Color.FromArgb(70, 70, 70);
};
btn.MouseLeave += (s, e) =>
{
btn.BackColor = Color.FromArgb(40, 40, 40);
};
return btn;
}
private void TitleBar_DoubleClick(object sender, EventArgs e)
{
ToggleMaximize();
}
private void TitleBar_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, 0xA1, 0x2, 0);
}
private void ToggleMaximize()
{
if (this.WindowState == FormWindowState.Normal)
this.WindowState = FormWindowState.Maximized;
else
this.WindowState = FormWindowState.Normal;
}
protected override void WndProc(ref Message m)
{
const int HTLEFT = 10;
const int HTRIGHT = 11;
const int HTTOP = 12;
const int HTTOPLEFT = 13;
const int HTTOPRIGHT = 14;
const int HTBOTTOM = 15;
const int HTBOTTOMLEFT = 16;
const int HTBOTTOMRIGHT = 17;
const int WM_NCHITTEST = 0x84;
const int resizeArea = 8;
if (m.Msg == WM_NCHITTEST)
{
base.WndProc(ref m);
if ((int)m.Result == 0x01)
{
Point pos = this.PointToClient(new Point(m.LParam.ToInt32()));
if (pos.X <= resizeArea && pos.Y <= resizeArea)
m.Result = (IntPtr)HTTOPLEFT;
else if (pos.X >= Width - resizeArea && pos.Y <= resizeArea)
m.Result = (IntPtr)HTTOPRIGHT;
else if (pos.X <= resizeArea && pos.Y >= Height - resizeArea)
m.Result = (IntPtr)HTBOTTOMLEFT;
else if (pos.X >= Width - resizeArea && pos.Y >= Height - resizeArea)
m.Result = (IntPtr)HTBOTTOMRIGHT;
else if (pos.X <= resizeArea)
m.Result = (IntPtr)HTLEFT;
else if (pos.X >= Width - resizeArea)
m.Result = (IntPtr)HTRIGHT;
else if (pos.Y <= resizeArea)
m.Result = (IntPtr)HTTOP;
else if (pos.Y >= Height - resizeArea)
m.Result = (IntPtr)HTBOTTOM;
}
return;
}
base.WndProc(ref m);
}
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
var screen = Screen.FromHandle(this.Handle);
this.MaximizedBounds = screen.WorkingArea;
}
#endregion
private readonly MainFromViewModel _vm; private readonly MainFromViewModel _vm;
public MainForm(MainFromViewModel vm) public MainForm(MainFromViewModel vm)
{ {
InitializeComponent(); InitializeComponent();
CreateCustomTitle();
_vm = vm; _vm = vm;
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,7 @@ using eCIAv2.WindowsApp.ViewModels;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Runtime.InteropServices;
namespace eCIAv2.WindowsApp namespace eCIAv2.WindowsApp
{ {

View File

@ -6,8 +6,14 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<PackageIcon></PackageIcon>
<ApplicationIcon>icon.ico</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Content Include="icon.ico" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />

BIN
eCIAv2.WindowsApp/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 KiB

BIN
icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 KiB