詳解C#如何實現(xiàn)窗體換膚
更新時間:2022年12月31日 10:30:53 作者:芝麻粒兒
這篇文章主要為大家詳細(xì)介紹了如何利用C#實現(xiàn)窗體換膚,文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以跟隨小編一起了解一下
實踐過程
效果

代碼

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static int var_bar = 1;
private void barter(int n)
{
switch (n)
{
case 1:
{
this.Width = Properties.Resources.sy1_01.Width;
this.Height = Properties.Resources.sy1_01.Height + Properties.Resources.sy1_02.Height - 5;
panel_Title.BackgroundImage = Properties.Resources.sy1_01;
panel_ALL.BackgroundImage = Properties.Resources.sy1_02;
pictureBox_Min.Image = null;
pictureBox_Min.Image = Properties.Resources.sy1_04;
pictureBox_Max.Image = null;
pictureBox_Max.Image = Properties.Resources.sy1_05;
pictureBox_Close.Image = null;
pictureBox_Close.Image = Properties.Resources.sy1_03;
var_bar = 1;
break;
}
case 2:
{
this.Width = Properties.Resources.sy2_01.Width;
this.Height = Properties.Resources.sy2_01.Height + Properties.Resources.sy2_02.Height - 5;
panel_Title.BackgroundImage = Properties.Resources.sy2_01;
panel_ALL.BackgroundImage = Properties.Resources.sy2_02;
pictureBox_Min.Image = null;
pictureBox_Min.Image = Properties.Resources.sy2_04;
pictureBox_Max.Image = null;
pictureBox_Max.Image = Properties.Resources.sy2_05;
pictureBox_Close.Image = null;
pictureBox_Close.Image = Properties.Resources.sy2_03;
var_bar = 2;
break;
}
case 3:
{
this.Width = Properties.Resources.sy3_01.Width;
this.Height = Properties.Resources.sy3_01.Height + Properties.Resources.sy3_02.Height - 5;
panel_Title.BackgroundImage = Properties.Resources.sy3_01;
panel_ALL.BackgroundImage = Properties.Resources.sy3_02;
pictureBox_Min.Image = null;
pictureBox_Min.Image = Properties.Resources.sy3_04;
pictureBox_Max.Image = null;
pictureBox_Max.Image = Properties.Resources.sy3_05;
pictureBox_Close.Image = null;
pictureBox_Close.Image = Properties.Resources.sy3_03;
var_bar = 3;
break;
}
}
barterShow(n);
}
private void barterShow(int n)
{
ToolS_1.Checked = false;
ToolS_2.Checked = false;
ToolS_3.Checked = false;
switch (n)
{
case 1:
ToolS_1.Checked = true;
break;
case 2:
ToolS_2.Checked = true;
break;
case 3:
ToolS_3.Checked = true;
break;
}
}
private void Form1_Load(object sender, EventArgs e)
{
barter(1);
}
#region 設(shè)置窗體的最大化、最小化和關(guān)閉按鈕的單擊事件
/// <summary>
/// 設(shè)置窗體的最大化、最小化和關(guān)閉按鈕的單擊事件
/// </summary>
/// <param Frm_Tem="Form">窗體</param>
/// <param n="int">標(biāo)識</param>
public void FrmClickMeans(Form Frm_Tem, int n)
{
switch (n)
{
case 0:
Frm_Tem.WindowState = FormWindowState.Minimized;
break;
case 1:
{
if (Frm_Tem.WindowState == FormWindowState.Maximized)
Frm_Tem.WindowState = FormWindowState.Normal;
else
Frm_Tem.WindowState = FormWindowState.Maximized;
break;
}
case 2:
Frm_Tem.Close();
break;
}
}
#endregion
#region 控制圖片的切換狀態(tài)
/// <summary>
/// 控制圖片的切換狀態(tài)
/// </summary>
/// <param Frm_Tem="Form">要改變圖片的對象</param>
/// <param n="int">標(biāo)識</param>
/// <param ns="int">移出移入標(biāo)識</param>
public static PictureBox Tem_PictB = new PictureBox();
public void ImageSwitch(object sender, int n, int ns)
{
Tem_PictB = (PictureBox) sender;
switch (n)
{
case 0:
{
Tem_PictB.Image = null;
if (ns == 0)
{
switch (var_bar)
{
case 1:
Tem_PictB.Image = Properties.Resources.sy1_04_1;
break;
case 2:
Tem_PictB.Image = Properties.Resources.sy2_04_1;
break;
case 3:
Tem_PictB.Image = Properties.Resources.sy3_04_1;
break;
}
}
if (ns == 1)
{
switch (var_bar)
{
case 1:
Tem_PictB.Image = Properties.Resources.sy1_04;
break;
case 2:
Tem_PictB.Image = Properties.Resources.sy2_04;
break;
case 3:
Tem_PictB.Image = Properties.Resources.sy3_04;
break;
}
}
break;
}
case 1:
{
Tem_PictB.Image = null;
if (ns == 0)
{
switch (var_bar)
{
case 1:
Tem_PictB.Image = Properties.Resources.sy1_05_1;
break;
case 2:
Tem_PictB.Image = Properties.Resources.sy2_05_1;
break;
case 3:
Tem_PictB.Image = Properties.Resources.sy3_05_1;
break;
}
}
if (ns == 1)
{
switch (var_bar)
{
case 1:
Tem_PictB.Image = Properties.Resources.sy1_05;
break;
case 2:
Tem_PictB.Image = Properties.Resources.sy2_05;
break;
case 3:
Tem_PictB.Image = Properties.Resources.sy3_05;
break;
}
}
break;
}
case 2:
{
Tem_PictB.Image = null;
if (ns == 0)
{
switch (var_bar)
{
case 1:
Tem_PictB.Image = Properties.Resources.sy1_03_1;
break;
case 2:
Tem_PictB.Image = Properties.Resources.sy2_03_1;
break;
case 3:
Tem_PictB.Image = Properties.Resources.sy3_03_1;
break;
}
}
if (ns == 1)
{
switch (var_bar)
{
case 1:
Tem_PictB.Image = Properties.Resources.sy1_03;
break;
case 2:
Tem_PictB.Image = Properties.Resources.sy2_03;
break;
case 3:
Tem_PictB.Image = Properties.Resources.sy3_03;
break;
}
}
break;
}
}
}
#endregion
private void pictureBox_Close_Click(object sender, EventArgs e)
{
FrmClickMeans(this, Convert.ToInt16(((PictureBox) sender).Tag.ToString()));
}
private void pictureBox_Close_MouseEnter(object sender, EventArgs e)
{
ImageSwitch(sender, Convert.ToInt16(((PictureBox) sender).Tag.ToString()), 0);
}
private void pictureBox_Close_MouseLeave(object sender, EventArgs e)
{
ImageSwitch(sender, Convert.ToInt16(((PictureBox) sender).Tag.ToString()), 1);
}
private void ToolS_1_Click(object sender, EventArgs e)
{
barter(Convert.ToInt32(((ToolStripMenuItem) sender).Tag));
}
}
到此這篇關(guān)于詳解C#如何實現(xiàn)窗體換膚的文章就介紹到這了,更多相關(guān)C#窗體換膚內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C#實現(xiàn)操作MySql數(shù)據(jù)層類MysqlHelper實例
這篇文章主要介紹了C#實現(xiàn)操作MySql數(shù)據(jù)層類MysqlHelper,實例分析了C#操作MySQL的常用技巧,并將其封裝入一個類中以方便調(diào)用,需要的朋友可以參考下2015-04-04
C#中async await異步關(guān)鍵字用法和異步的底層原理全解析
這篇文章主要介紹了C#中async await異步關(guān)鍵字用法和異步的底層原理全解析,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧2025-04-04
C#設(shè)計模式之Template模板方法模式實現(xiàn)ASP.NET自定義控件 密碼強(qiáng)度檢測功能
這篇文章主要介紹了C#設(shè)計模式之Template模板方法模式實現(xiàn)ASP.NET自定義控件 密碼強(qiáng)度檢測功能,簡單介紹了模板方法模式的定義、原理及檢測密碼強(qiáng)度的相關(guān)使用技巧,需要的朋友可以參考下2017-09-09
本文主要介紹了C#中利用GDI來繪制圖形和文字的方法,并提供的簡單的示例供大家參考學(xué)習(xí),希望能夠?qū)Υ蠹矣兴鶐椭?/div> 2016-03-03
C#使用Newtonsoft.Json中的JObject對象
本文詳細(xì)講解了C#使用Newtonsoft.Json中JObject對象的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-07-07最新評論

