C# 버튼에 다양한 아이콘 넣을수 있는 방법
NuGet관리 들어가서 FontAwesome.Shape를 설치합니다.
그럼 도구상자에 IconButton, IconPictureBox가 생성됩니다.
참고로 fontawesome.com 사이트에 가면 수천가지 종류의 아이콘을 찾아 볼 수 있습니다.
https://fontawesome.com/icons?d=gallery&q=chart
IconButton은 다음과 같은 속성들이 있다.
대충 아이콘버튼들을 이렇게 손쉽게 만들수 있다.
동영상으로 확인하기
레이아웃 코드
namespace Monitor0._2.Test_Forms
{
partial class FormUI_1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormUI_1));
this.panelMenu = new System.Windows.Forms.Panel();
this.iconButton6 = new FontAwesome.Sharp.IconButton();
this.iconButton5 = new FontAwesome.Sharp.IconButton();
this.iconButton4 = new FontAwesome.Sharp.IconButton();
this.iconButton3 = new FontAwesome.Sharp.IconButton();
this.iconButton2 = new FontAwesome.Sharp.IconButton();
this.iconButton1 = new FontAwesome.Sharp.IconButton();
this.panelLogo = new System.Windows.Forms.Panel();
this.pictureBox_btnHome = new System.Windows.Forms.PictureBox();
this.panelTitlebar = new System.Windows.Forms.Panel();
this.pictureBox_btnRestroe = new System.Windows.Forms.PictureBox();
this.pictureBox_btnMinimize = new System.Windows.Forms.PictureBox();
this.pictureBox_btnMaximize = new System.Windows.Forms.PictureBox();
this.pictureBox_btnExit = new System.Windows.Forms.PictureBox();
this.lblTitleChildForm = new System.Windows.Forms.Label();
this.iconCurrentChildForm = new FontAwesome.Sharp.IconPictureBox();
this.panelShadow = new System.Windows.Forms.Panel();
this.panelDesktop = new System.Windows.Forms.Panel();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.panelMenu.SuspendLayout();
this.panelLogo.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox_btnHome)).BeginInit();
this.panelTitlebar.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox_btnRestroe)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox_btnMinimize)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox_btnMaximize)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox_btnExit)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.iconCurrentChildForm)).BeginInit();
this.panelDesktop.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// panelMenu
//
this.panelMenu.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(31)))), ((int)(((byte)(38)))), ((int)(((byte)(60)))));
this.panelMenu.Controls.Add(this.iconButton6);
this.panelMenu.Controls.Add(this.iconButton5);
this.panelMenu.Controls.Add(this.iconButton4);
this.panelMenu.Controls.Add(this.iconButton3);
this.panelMenu.Controls.Add(this.iconButton2);
this.panelMenu.Controls.Add(this.iconButton1);
this.panelMenu.Controls.Add(this.panelLogo);
this.panelMenu.Dock = System.Windows.Forms.DockStyle.Left;
this.panelMenu.Location = new System.Drawing.Point(0, 0);
this.panelMenu.Name = "panelMenu";
this.panelMenu.Size = new System.Drawing.Size(200, 738);
this.panelMenu.TabIndex = 1;
//
// iconButton6
//
this.iconButton6.FlatAppearance.BorderSize = 0;
this.iconButton6.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.iconButton6.Flip = FontAwesome.Sharp.FlipOrientation.Normal;
this.iconButton6.ForeColor = System.Drawing.Color.Gainsboro;
this.iconButton6.IconChar = FontAwesome.Sharp.IconChar.Ruler;
this.iconButton6.IconColor = System.Drawing.Color.White;
this.iconButton6.IconSize = 32;
this.iconButton6.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.iconButton6.Location = new System.Drawing.Point(-1, 528);
this.iconButton6.Name = "iconButton6";
this.iconButton6.Padding = new System.Windows.Forms.Padding(10, 0, 20, 0);
this.iconButton6.Rotation = 0D;
this.iconButton6.Size = new System.Drawing.Size(200, 60);
this.iconButton6.TabIndex = 6;
this.iconButton6.Text = "Setting";
this.iconButton6.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
this.iconButton6.UseVisualStyleBackColor = true;
this.iconButton6.Click += new System.EventHandler(this.iconButton6_Click);
//
// iconButton5
//
this.iconButton5.FlatAppearance.BorderSize = 0;
this.iconButton5.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.iconButton5.Flip = FontAwesome.Sharp.FlipOrientation.Normal;
this.iconButton5.ForeColor = System.Drawing.Color.Gainsboro;
this.iconButton5.IconChar = FontAwesome.Sharp.IconChar.GasPump;
this.iconButton5.IconColor = System.Drawing.Color.White;
this.iconButton5.IconSize = 32;
this.iconButton5.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.iconButton5.Location = new System.Drawing.Point(-1, 451);
this.iconButton5.Name = "iconButton5";
this.iconButton5.Padding = new System.Windows.Forms.Padding(10, 0, 20, 0);
this.iconButton5.Rotation = 0D;
this.iconButton5.Size = new System.Drawing.Size(200, 60);
this.iconButton5.TabIndex = 5;
this.iconButton5.Text = "Marketing";
this.iconButton5.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
this.iconButton5.UseVisualStyleBackColor = true;
this.iconButton5.Click += new System.EventHandler(this.iconButton5_Click);
//
// iconButton4
//
this.iconButton4.FlatAppearance.BorderSize = 0;
this.iconButton4.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.iconButton4.Flip = FontAwesome.Sharp.FlipOrientation.Normal;
this.iconButton4.ForeColor = System.Drawing.Color.Gainsboro;
this.iconButton4.IconChar = FontAwesome.Sharp.IconChar.Dice;
this.iconButton4.IconColor = System.Drawing.Color.White;
this.iconButton4.IconSize = 32;
this.iconButton4.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.iconButton4.Location = new System.Drawing.Point(-1, 376);
this.iconButton4.Name = "iconButton4";
this.iconButton4.Padding = new System.Windows.Forms.Padding(10, 0, 20, 0);
this.iconButton4.Rotation = 0D;
this.iconButton4.Size = new System.Drawing.Size(200, 60);
this.iconButton4.TabIndex = 4;
this.iconButton4.Text = "Customers";
this.iconButton4.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
this.iconButton4.UseVisualStyleBackColor = true;
this.iconButton4.Click += new System.EventHandler(this.iconButton4_Click);
//
// iconButton3
//
this.iconButton3.FlatAppearance.BorderSize = 0;
this.iconButton3.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.iconButton3.Flip = FontAwesome.Sharp.FlipOrientation.Normal;
this.iconButton3.ForeColor = System.Drawing.Color.Gainsboro;
this.iconButton3.IconChar = FontAwesome.Sharp.IconChar.Chalkboard;
this.iconButton3.IconColor = System.Drawing.Color.White;
this.iconButton3.IconSize = 32;
this.iconButton3.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.iconButton3.Location = new System.Drawing.Point(-1, 299);
this.iconButton3.Name = "iconButton3";
this.iconButton3.Padding = new System.Windows.Forms.Padding(10, 0, 20, 0);
this.iconButton3.Rotation = 0D;
this.iconButton3.Size = new System.Drawing.Size(200, 60);
this.iconButton3.TabIndex = 3;
this.iconButton3.Text = "Products";
this.iconButton3.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
this.iconButton3.UseVisualStyleBackColor = true;
this.iconButton3.Click += new System.EventHandler(this.iconButton3_Click);
//
// iconButton2
//
this.iconButton2.FlatAppearance.BorderSize = 0;
this.iconButton2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.iconButton2.Flip = FontAwesome.Sharp.FlipOrientation.Normal;
this.iconButton2.ForeColor = System.Drawing.Color.Gainsboro;
this.iconButton2.IconChar = FontAwesome.Sharp.IconChar.ChartPie;
this.iconButton2.IconColor = System.Drawing.Color.White;
this.iconButton2.IconSize = 32;
this.iconButton2.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.iconButton2.Location = new System.Drawing.Point(-1, 222);
this.iconButton2.Name = "iconButton2";
this.iconButton2.Padding = new System.Windows.Forms.Padding(10, 0, 20, 0);
this.iconButton2.Rotation = 0D;
this.iconButton2.Size = new System.Drawing.Size(200, 60);
this.iconButton2.TabIndex = 2;
this.iconButton2.Text = "Orders";
this.iconButton2.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
this.iconButton2.UseVisualStyleBackColor = true;
this.iconButton2.Click += new System.EventHandler(this.iconButton2_Click);
//
// iconButton1
//
this.iconButton1.FlatAppearance.BorderSize = 0;
this.iconButton1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.iconButton1.Flip = FontAwesome.Sharp.FlipOrientation.Normal;
this.iconButton1.ForeColor = System.Drawing.Color.Gainsboro;
this.iconButton1.IconChar = FontAwesome.Sharp.IconChar.ChartBar;
this.iconButton1.IconColor = System.Drawing.Color.White;
this.iconButton1.IconSize = 32;
this.iconButton1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.iconButton1.Location = new System.Drawing.Point(-1, 143);
this.iconButton1.Name = "iconButton1";
this.iconButton1.Padding = new System.Windows.Forms.Padding(10, 0, 20, 0);
this.iconButton1.Rotation = 0D;
this.iconButton1.Size = new System.Drawing.Size(200, 60);
this.iconButton1.TabIndex = 1;
this.iconButton1.Text = "Dashboard";
this.iconButton1.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
this.iconButton1.UseVisualStyleBackColor = true;
this.iconButton1.Click += new System.EventHandler(this.iconButton1_Click);
//
// panelLogo
//
this.panelLogo.Controls.Add(this.pictureBox_btnHome);
this.panelLogo.Dock = System.Windows.Forms.DockStyle.Top;
this.panelLogo.Location = new System.Drawing.Point(0, 0);
this.panelLogo.Name = "panelLogo";
this.panelLogo.Size = new System.Drawing.Size(200, 100);
this.panelLogo.TabIndex = 0;
//
// pictureBox_btnHome
//
this.pictureBox_btnHome.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox_btnHome.Image")));
this.pictureBox_btnHome.Location = new System.Drawing.Point(51, 22);
this.pictureBox_btnHome.Name = "pictureBox_btnHome";
this.pictureBox_btnHome.Size = new System.Drawing.Size(71, 62);
this.pictureBox_btnHome.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox_btnHome.TabIndex = 0;
this.pictureBox_btnHome.TabStop = false;
this.pictureBox_btnHome.Click += new System.EventHandler(this.pictureBox_btnHome_Click);
//
// panelTitlebar
//
this.panelTitlebar.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(26)))), ((int)(((byte)(25)))), ((int)(((byte)(62)))));
this.panelTitlebar.Controls.Add(this.pictureBox_btnRestroe);
this.panelTitlebar.Controls.Add(this.pictureBox_btnMinimize);
this.panelTitlebar.Controls.Add(this.pictureBox_btnMaximize);
this.panelTitlebar.Controls.Add(this.pictureBox_btnExit);
this.panelTitlebar.Controls.Add(this.lblTitleChildForm);
this.panelTitlebar.Controls.Add(this.iconCurrentChildForm);
this.panelTitlebar.Dock = System.Windows.Forms.DockStyle.Top;
this.panelTitlebar.Location = new System.Drawing.Point(200, 0);
this.panelTitlebar.Name = "panelTitlebar";
this.panelTitlebar.Size = new System.Drawing.Size(1082, 80);
this.panelTitlebar.TabIndex = 2;
this.panelTitlebar.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelTitlebar_MouseDown);
//
// pictureBox_btnRestroe
//
this.pictureBox_btnRestroe.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox_btnRestroe.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox_btnRestroe.Image")));
this.pictureBox_btnRestroe.Location = new System.Drawing.Point(1005, 8);
this.pictureBox_btnRestroe.Name = "pictureBox_btnRestroe";
this.pictureBox_btnRestroe.Size = new System.Drawing.Size(30, 19);
this.pictureBox_btnRestroe.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox_btnRestroe.TabIndex = 5;
this.pictureBox_btnRestroe.TabStop = false;
this.pictureBox_btnRestroe.Visible = false;
this.pictureBox_btnRestroe.Click += new System.EventHandler(this.pictureBox_btnRestroe_Click);
//
// pictureBox_btnMinimize
//
this.pictureBox_btnMinimize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox_btnMinimize.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox_btnMinimize.Image")));
this.pictureBox_btnMinimize.Location = new System.Drawing.Point(966, 8);
this.pictureBox_btnMinimize.Name = "pictureBox_btnMinimize";
this.pictureBox_btnMinimize.Size = new System.Drawing.Size(30, 19);
this.pictureBox_btnMinimize.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox_btnMinimize.TabIndex = 4;
this.pictureBox_btnMinimize.TabStop = false;
this.pictureBox_btnMinimize.Click += new System.EventHandler(this.pictureBox_btnMinimize_Click);
//
// pictureBox_btnMaximize
//
this.pictureBox_btnMaximize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox_btnMaximize.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox_btnMaximize.Image")));
this.pictureBox_btnMaximize.Location = new System.Drawing.Point(1005, 8);
this.pictureBox_btnMaximize.Name = "pictureBox_btnMaximize";
this.pictureBox_btnMaximize.Size = new System.Drawing.Size(30, 19);
this.pictureBox_btnMaximize.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox_btnMaximize.TabIndex = 3;
this.pictureBox_btnMaximize.TabStop = false;
this.pictureBox_btnMaximize.Click += new System.EventHandler(this.pictureBox_btnMaximize_Click);
//
// pictureBox_btnExit
//
this.pictureBox_btnExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox_btnExit.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox_btnExit.Image")));
this.pictureBox_btnExit.Location = new System.Drawing.Point(1044, 8);
this.pictureBox_btnExit.Name = "pictureBox_btnExit";
this.pictureBox_btnExit.Size = new System.Drawing.Size(30, 19);
this.pictureBox_btnExit.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox_btnExit.TabIndex = 2;
this.pictureBox_btnExit.TabStop = false;
this.pictureBox_btnExit.Click += new System.EventHandler(this.pictureBox_btnExit_Click);
//
// lblTitleChildForm
//
this.lblTitleChildForm.AutoSize = true;
this.lblTitleChildForm.ForeColor = System.Drawing.Color.Gainsboro;
this.lblTitleChildForm.Location = new System.Drawing.Point(87, 41);
this.lblTitleChildForm.Name = "lblTitleChildForm";
this.lblTitleChildForm.Size = new System.Drawing.Size(43, 17);
this.lblTitleChildForm.TabIndex = 1;
this.lblTitleChildForm.Text = "Home";
//
// iconCurrentChildForm
//
this.iconCurrentChildForm.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(26)))), ((int)(((byte)(25)))), ((int)(((byte)(62)))));
this.iconCurrentChildForm.ForeColor = System.Drawing.Color.MediumPurple;
this.iconCurrentChildForm.IconChar = FontAwesome.Sharp.IconChar.Home;
this.iconCurrentChildForm.IconColor = System.Drawing.Color.MediumPurple;
this.iconCurrentChildForm.Location = new System.Drawing.Point(28, 22);
this.iconCurrentChildForm.Name = "iconCurrentChildForm";
this.iconCurrentChildForm.Size = new System.Drawing.Size(32, 32);
this.iconCurrentChildForm.TabIndex = 0;
this.iconCurrentChildForm.TabStop = false;
//
// panelShadow
//
this.panelShadow.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(26)))), ((int)(((byte)(24)))), ((int)(((byte)(58)))));
this.panelShadow.Dock = System.Windows.Forms.DockStyle.Top;
this.panelShadow.Location = new System.Drawing.Point(200, 80);
this.panelShadow.Name = "panelShadow";
this.panelShadow.Size = new System.Drawing.Size(1082, 10);
this.panelShadow.TabIndex = 3;
//
// panelDesktop
//
this.panelDesktop.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(34)))), ((int)(((byte)(33)))), ((int)(((byte)(74)))));
this.panelDesktop.Controls.Add(this.pictureBox1);
this.panelDesktop.Dock = System.Windows.Forms.DockStyle.Fill;
this.panelDesktop.Location = new System.Drawing.Point(200, 90);
this.panelDesktop.Name = "panelDesktop";
this.panelDesktop.Size = new System.Drawing.Size(1082, 648);
this.panelDesktop.TabIndex = 4;
//
// pictureBox1
//
this.pictureBox1.Anchor = System.Windows.Forms.AnchorStyles.None;
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(391, 79);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(268, 215);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 1;
this.pictureBox1.TabStop = false;
//
// FormUI_1
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(1282, 738);
this.Controls.Add(this.panelDesktop);
this.Controls.Add(this.panelShadow);
this.Controls.Add(this.panelTitlebar);
this.Controls.Add(this.panelMenu);
this.Font = new System.Drawing.Font("Century Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Name = "FormUI_1";
this.Text = "Form1";
this.panelMenu.ResumeLayout(false);
this.panelLogo.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBox_btnHome)).EndInit();
this.panelTitlebar.ResumeLayout(false);
this.panelTitlebar.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox_btnRestroe)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox_btnMinimize)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox_btnMaximize)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox_btnExit)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.iconCurrentChildForm)).EndInit();
this.panelDesktop.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel panelMenu;
private FontAwesome.Sharp.IconButton iconButton6;
private FontAwesome.Sharp.IconButton iconButton5;
private FontAwesome.Sharp.IconButton iconButton4;
private FontAwesome.Sharp.IconButton iconButton3;
private FontAwesome.Sharp.IconButton iconButton2;
private FontAwesome.Sharp.IconButton iconButton1;
private System.Windows.Forms.Panel panelLogo;
private System.Windows.Forms.PictureBox pictureBox_btnHome;
private System.Windows.Forms.Panel panelTitlebar;
private FontAwesome.Sharp.IconPictureBox iconCurrentChildForm;
private System.Windows.Forms.Label lblTitleChildForm;
private System.Windows.Forms.Panel panelShadow;
private System.Windows.Forms.Panel panelDesktop;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.PictureBox pictureBox_btnMaximize;
private System.Windows.Forms.PictureBox pictureBox_btnExit;
private System.Windows.Forms.PictureBox pictureBox_btnMinimize;
private System.Windows.Forms.PictureBox pictureBox_btnRestroe;
private System.Windows.Forms.Timer timer1;
}
}
소스코드
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;
using FontAwesome.Sharp;
using System.Runtime.InteropServices;
using Monitor0._2.UI_Forms;
namespace Monitor0._2.Test_Forms
{
public partial class FormUI_1 : Form
{
//Fields
private IconButton currentBtn;
private Panel leftBorderBtn;
private Form currentChildForm;
public FormUI_1()
{
InitializeComponent();
leftBorderBtn = new Panel();
leftBorderBtn.Size = new Size(7,60);
panelMenu.Controls.Add(leftBorderBtn);
//Form
this.Text = string.Empty;
this.ControlBox = false;
this.DoubleBuffered = true;
this.MaximizedBounds = Screen.FromHandle(this.Handle).WorkingArea;
}
//Structs
private struct RGBColors
{
public static Color color1 = Color.FromArgb(172, 126, 241);
public static Color color2 = Color.FromArgb(249, 118, 176);
public static Color color3 = Color.FromArgb(253, 138, 114);
public static Color color4 = Color.FromArgb(95, 77, 221);
public static Color color5 = Color.FromArgb(249, 88, 155);
public static Color color6 = Color.FromArgb(24, 161, 251);
}
//Methods
private void ActivateButton(object senderBtn, Color color)
{
if(senderBtn != null)
{
DisableButton();
//Button
currentBtn = (IconButton)senderBtn;
currentBtn.BackColor = Color.FromArgb(37, 36, 81);
currentBtn.ForeColor = color;
currentBtn.TextAlign = ContentAlignment.MiddleCenter;
currentBtn.IconColor = color;
currentBtn.TextImageRelation = TextImageRelation.TextBeforeImage;
currentBtn.ImageAlign = ContentAlignment.MiddleRight;
//Left border button
leftBorderBtn.BackColor = color;
leftBorderBtn.Location = new Point(0, currentBtn.Location.Y);
leftBorderBtn.Visible = true;
leftBorderBtn.BringToFront();
//IconCurrentChildForm
iconCurrentChildForm.IconChar = currentBtn.IconChar;
iconCurrentChildForm.IconColor = color;
}
}
private void DisableButton()
{
if(currentBtn != null)
{
currentBtn.BackColor = Color.FromArgb(31, 30, 68);
currentBtn.ForeColor = Color.Gainsboro;
currentBtn.TextAlign = ContentAlignment.MiddleLeft;
currentBtn.IconColor = Color.Gainsboro;
currentBtn.TextImageRelation = TextImageRelation.ImageBeforeText;
currentBtn.ImageAlign = ContentAlignment.MiddleLeft;
}
}
private void OpenChildForm(Form childForm)
{
if (currentChildForm != null)
{
//open only form
currentChildForm.Close();
}
currentChildForm = childForm;
childForm.TopLevel = false;
childForm.FormBorderStyle = FormBorderStyle.None;
childForm.Dock = DockStyle.Fill;
panelDesktop.Controls.Add(childForm);
panelDesktop.Tag = childForm;
childForm.BringToFront();
childForm.Show();
lblTitleChildForm.Text = childForm.Text;
}
private void iconButton1_Click(object sender, EventArgs e) //Dashboard
{
ActivateButton(sender, RGBColors.color1);
OpenChildForm(new FormDashboard());
}
private void iconButton2_Click(object sender, EventArgs e) //orders
{
ActivateButton(sender, RGBColors.color2);
OpenChildForm(new FormOrders());
}
private void iconButton3_Click(object sender, EventArgs e) //products
{
ActivateButton(sender, RGBColors.color3);
OpenChildForm(new FormProducts());
}
private void iconButton4_Click(object sender, EventArgs e) //customers
{
ActivateButton(sender, RGBColors.color4);
OpenChildForm(new FormCustomers());
}
private void iconButton5_Click(object sender, EventArgs e) //Marketing
{
ActivateButton(sender, RGBColors.color5);
OpenChildForm(new FormMarketing());
}
private void iconButton6_Click(object sender, EventArgs e) //Setting
{
ActivateButton(sender, RGBColors.color6);
OpenChildForm(new FormSetting());
}
private void pictureBox_btnHome_Click(object sender, EventArgs e) //Logo Click
{
currentChildForm.Close();
Reset();
}
private void Reset()
{
DisableButton();
leftBorderBtn.Visible = false;
iconCurrentChildForm.IconChar = IconChar.Home;
iconCurrentChildForm.IconColor = Color.MediumPurple;
lblTitleChildForm.Text = "Home";
}
//Drag Form
[DllImport("user32.DLL", EntryPoint = "ReleaseCapture")]
private extern static void ReleaseCapture();
[DllImport("user32.DLL", EntryPoint = "SendMessage")]
private extern static void SendMessage(System.IntPtr hwnd, int wmsg, int wparam, int lparam);
private void panelTitlebar_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, 0x112, 0xf012, 0);
}
private void pictureBox_btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void pictureBox_btnMaximize_Click(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Normal)
{
WindowState = FormWindowState.Maximized;
pictureBox_btnMaximize.Visible = false;
pictureBox_btnRestroe.Visible = true;
}
else
{
WindowState = FormWindowState.Normal;
pictureBox_btnMaximize.Visible = true;
pictureBox_btnRestroe.Visible = false;
}
}
private void pictureBox_btnMinimize_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Minimized;
}
private void pictureBox_btnRestroe_Click(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Normal)
{
WindowState = FormWindowState.Maximized;
pictureBox_btnMaximize.Visible = false;
pictureBox_btnRestroe.Visible = true;
}
else
{
WindowState = FormWindowState.Normal;
pictureBox_btnMaximize.Visible = true;
pictureBox_btnRestroe.Visible = false;
}
}
}
}
'기타 ETC > C#' 카테고리의 다른 글
C# 윈폼 Form(폼) 둥글게 타원으로 만드는 방법 (0) | 2020.03.24 |
---|---|
Form Drag (0) | 2020.03.19 |
c# 실시간 라인 차트(그래프) 만들기 (0) | 2020.02.18 |
C# 콤보박스에 목록 추가 및 제거하는 방법 (0) | 2018.12.27 |
datagridview 초기화 (0) | 2018.12.27 |