CaculatePartLocation
在这个方法中就是根据当前窗体的width和height,再加上读取到的配置信息计算各个背景块的大小和位置。请注意方法中计算的顺序,先是左上角然后右上角最后中间。因为为了实现窗体的可缩放,中间的宽度是可变的。然后是左下方右下方,最后才是中间。中间的内容区域被我放了一个panel,其大小是可以变化的,具体的大小位置要看计算的结果。panel的另一个作用就是实现放在里面的控件的布局更好设置而不必关心上下两个边框。
private void CaculatePartLocation()
{
//顶部
_topLeft.X = 0;
_topLeft.Y = 0;
_topRight.X = Width - _topRight.Width;
_topRight.Y = 0;
_topMiddle.X = _topLeft.Width;
_topMiddle.Y = 0;
_topMiddle.Width = Width - _topLeft.Width - _topRight.Width;
//中间部分
_centerLeft.X = 0;
_centerLeft.Y = _topLeft.Height;
_centerLeft.Height = Height - _topLeft.Height - _bottomLeft.Height;
_centerRight.X = Width - _centerRight.Width;
_centerRight.Y = _topRight.Height;
_centerRight.Height = Height - _topLeft.Height - _bottomLeft.Height;
_centerMiddle.X = _centerLeft.Width;
_centerMiddle.Y = _topMiddle.Height;
_centerMiddle.Width = Width - _centerLeft.Width - _centerRight.Width;
_centerMiddle.Height = Height - _topMiddle.Height - _bottomMiddle.Height;
//底部
_bottomLeft.X = 0;
_bottomLeft.Y = Height - _bottomLeft.Height;
_bottomRight.X = Width - _bottomRight.Width;
_bottomRight.Y = Height - _bottomRight.Height;
_bottomMiddle.X = _bottomLeft.Width;
_bottomMiddle.Y = Height - _bottomMiddle.Height;
_bottomMiddle.Width = Width - _bottomLeft.Width - _bottomRight.Width;
//按钮位置
if (MaximizeBox && MinimizeBox) // 允许最大化,最小化
{
maxButton.Left = Width - maxButton.Width - maxButton.XOffset;
minButton.Left = Width - minButton.Width - minButton.XOffset;
selectSkinButton.Left = Width - selectSkinButton.Width - selectSkinButton.XOffset;
}
if (MaximizeBox && !MinimizeBox) //不允许最小化
{
maxButton.Left = Width - maxButton.Width - maxButton.XOffset;
selectSkinButton.Left = Width - selectSkinButton.Width - minButton.XOffset;
minButton.Top = -60;
}
if (!MaximizeBox && MinimizeBox) //不允许最大化
{
maxButton.Top = -60;
minButton.Left = Width - maxButton.XOffset - minButton.Width;
selectSkinButton.Left = Width - selectSkinButton.Width - minButton.XOffset;
}
if (!MaximizeBox && !MinimizeBox) //不允许最大化,最小化
{
minButton.Top = -60;
maxButton.Top = -60;
selectSkinButton.Left = Width - selectSkinButton.Width - maxButton.XOffset;
}
if (!_showSelectSkinButton)
{
selectSkinButton.Top = -60;
}
closeButton.Left = Width - closeButton.Width - closeButton.XOffset;
//内容panel位置大小
contentPanel.Top = _centerMiddle.Y;
contentPanel.Left = _centerMiddle.X;
contentPanel.Width = _centerMiddle.Width;
contentPanel.Height = _centerMiddle.Height;
}
{
//顶部
_topLeft.X = 0;
_topLeft.Y = 0;
_topRight.X = Width - _topRight.Width;
_topRight.Y = 0;
_topMiddle.X = _topLeft.Width;
_topMiddle.Y = 0;
_topMiddle.Width = Width - _topLeft.Width - _topRight.Width;
//中间部分
_centerLeft.X = 0;
_centerLeft.Y = _topLeft.Height;
_centerLeft.Height = Height - _topLeft.Height - _bottomLeft.Height;
_centerRight.X = Width - _centerRight.Width;
_centerRight.Y = _topRight.Height;
_centerRight.Height = Height - _topLeft.Height - _bottomLeft.Height;
_centerMiddle.X = _centerLeft.Width;
_centerMiddle.Y = _topMiddle.Height;
_centerMiddle.Width = Width - _centerLeft.Width - _centerRight.Width;
_centerMiddle.Height = Height - _topMiddle.Height - _bottomMiddle.Height;
//底部
_bottomLeft.X = 0;
_bottomLeft.Y = Height - _bottomLeft.Height;
_bottomRight.X = Width - _bottomRight.Width;
_bottomRight.Y = Height - _bottomRight.Height;
_bottomMiddle.X = _bottomLeft.Width;
_bottomMiddle.Y = Height - _bottomMiddle.Height;
_bottomMiddle.Width = Width - _bottomLeft.Width - _bottomRight.Width;
//按钮位置
if (MaximizeBox && MinimizeBox) // 允许最大化,最小化
{
maxButton.Left = Width - maxButton.Width - maxButton.XOffset;
minButton.Left = Width - minButton.Width - minButton.XOffset;
selectSkinButton.Left = Width - selectSkinButton.Width - selectSkinButton.XOffset;
}
if (MaximizeBox && !MinimizeBox) //不允许最小化
{
maxButton.Left = Width - maxButton.Width - maxButton.XOffset;
selectSkinButton.Left = Width - selectSkinButton.Width - minButton.XOffset;
minButton.Top = -60;
}
if (!MaximizeBox && MinimizeBox) //不允许最大化
{
maxButton.Top = -60;
minButton.Left = Width - maxButton.XOffset - minButton.Width;
selectSkinButton.Left = Width - selectSkinButton.Width - minButton.XOffset;
}
if (!MaximizeBox && !MinimizeBox) //不允许最大化,最小化
{
minButton.Top = -60;
maxButton.Top = -60;
selectSkinButton.Left = Width - selectSkinButton.Width - maxButton.XOffset;
}
if (!_showSelectSkinButton)
{
selectSkinButton.Top = -60;
}
closeButton.Left = Width - closeButton.Width - closeButton.XOffset;
//内容panel位置大小
contentPanel.Top = _centerMiddle.Y;
contentPanel.Left = _centerMiddle.X;
contentPanel.Width = _centerMiddle.Width;
contentPanel.Height = _centerMiddle.Height;
}
ReadBitmap
这个方法是用来加载要使用皮肤的各个背景图片的,大家看代码就明白了,没什么好讲的。
private void ReadBitmap(string skinFolder)
{
//读取需要透明的颜色值
int r = int.Parse(IniHelper.ReadIniValue(skinFolder + "\\config.ini", "Main", "TransparentColorR"));
int g = int.Parse(IniHelper.ReadIniValue(skinFolder + "\\config.ini", "Main", "TransparentColorG"));
int b = int.Parse(IniHelper.ReadIniValue(skinFolder + "\\config.ini", "Main", "TransparentColorB"));
Color trans = Color.FromArgb(r, g, b);
TransparencyKey = trans; //透明处理
_topLeft.BackgroundBitmap = Image.FromFile(skinFolder + "\\TopLeft.bmp") as Bitmap;
_topMiddle.BackgroundBitmap = Image.FromFile(skinFolder + "\\TopMiddle.bmp") as Bitmap;
_topRight.BackgroundBitmap = Image.FromFile(skinFolder + "\\TopRight.bmp") as Bitmap;
_centerLeft.BackgroundBitmap = Image.FromFile(skinFolder + "\\MiddleLeft.bmp") as Bitmap;
_centerMiddle.BackgroundBitmap = Image.FromFile(skinFolder + "\\Middle.bmp") as Bitmap;
_centerRight.BackgroundBitmap = Image.FromFile(skinFolder + "\\MiddleRight.bmp") as Bitmap;
_bottomLeft.BackgroundBitmap = Image.FromFile(skinFolder + "\\BottomLeft.bmp") as Bitmap;
_bottomMiddle.BackgroundBitmap = Image.FromFile(skinFolder + "\\BottomMiddle.bmp") as Bitmap;
_bottomRight.BackgroundBitmap = Image.FromFile(skinFolder + "\\BottomRight.bmp") as Bitmap;
minButton.ReadButtonImage(skinFolder + "\\MinNormal.bmp", skinFolder + "\\MinMove.bmp", skinFolder + "\\MinDown.bmp");
maxButton.ReadButtonImage(skinFolder + "\\MaxNormal.bmp", skinFolder + "\\MaxMove.bmp", skinFolder + "\\MaxDown.bmp");
closeButton.ReadButtonImage(skinFolder + "\\CloseNormal.bmp", skinFolder + "\\CloseMove.bmp", skinFolder + "\\CloseDown.bmp");
selectSkinButton.ReadButtonImage(skinFolder + "\\SelectSkinNormal.bmp", skinFolder + "\\SelectSkinMove.bmp", skinFolder + "\\SelectSkinDown.bmp");
}
{
//读取需要透明的颜色值
int r = int.Parse(IniHelper.ReadIniValue(skinFolder + "\\config.ini", "Main", "TransparentColorR"));
int g = int.Parse(IniHelper.ReadIniValue(skinFolder + "\\config.ini", "Main", "TransparentColorG"));
int b = int.Parse(IniHelper.ReadIniValue(skinFolder + "\\config.ini", "Main", "TransparentColorB"));
Color trans = Color.FromArgb(r, g, b);
TransparencyKey = trans; //透明处理
_topLeft.BackgroundBitmap = Image.FromFile(skinFolder + "\\TopLeft.bmp") as Bitmap;
_topMiddle.BackgroundBitmap = Image.FromFile(skinFolder + "\\TopMiddle.bmp") as Bitmap;
_topRight.BackgroundBitmap = Image.FromFile(skinFolder + "\\TopRight.bmp") as Bitmap;
_centerLeft.BackgroundBitmap = Image.FromFile(skinFolder + "\\MiddleLeft.bmp") as Bitmap;
_centerMiddle.BackgroundBitmap = Image.FromFile(skinFolder + "\\Middle.bmp") as Bitmap;
_centerRight.BackgroundBitmap = Image.FromFile(skinFolder + "\\MiddleRight.bmp") as Bitmap;
_bottomLeft.BackgroundBitmap = Image.FromFile(skinFolder + "\\BottomLeft.bmp") as Bitmap;
_bottomMiddle.BackgroundBitmap = Image.FromFile(skinFolder + "\\BottomMiddle.bmp") as Bitmap;
_bottomRight.BackgroundBitmap = Image.FromFile(skinFolder + "\\BottomRight.bmp") as Bitmap;
minButton.ReadButtonImage(skinFolder + "\\MinNormal.bmp", skinFolder + "\\MinMove.bmp", skinFolder + "\\MinDown.bmp");
maxButton.ReadButtonImage(skinFolder + "\\MaxNormal.bmp", skinFolder + "\\MaxMove.bmp", skinFolder + "\\MaxDown.bmp");
closeButton.ReadButtonImage(skinFolder + "\\CloseNormal.bmp", skinFolder + "\\CloseMove.bmp", skinFolder + "\\CloseDown.bmp");
selectSkinButton.ReadButtonImage(skinFolder + "\\SelectSkinNormal.bmp", skinFolder + "\\SelectSkinMove.bmp", skinFolder + "\\SelectSkinDown.bmp");
}