📄 skinengine.cs
字号:
sName = sName.Replace("SKIN_", "");
switch (sName)
{
case "BTN_UP": bmp = GetBitmapFromResource("BTN_Up"); break;
case "BTN_LEFT": bmp = GetBitmapFromResource("BTN_Left"); break;
case "BTN_RIGHT": bmp = GetBitmapFromResource("BTN_Right"); break;
case "BTN_DOWN": bmp = GetBitmapFromResource("BTN_Down"); break;
case "BTN_RESET": bmp = GetBitmapFromResource("BTN_Reset"); break;
case "BTN_PAUSE": bmp = GetBitmapFromResource("BTN_Pause"); break;
case "BTN_SELECTFILE": bmp = GetBitmapFromResource("BTN_SelectFile"); break;
case "BTN_CLOSE": bmp = GetBitmapFromResource("BTN_Close"); break;
case "BTN_ICONIZE": bmp = GetBitmapFromResource("BTN_Iconize"); break;
case "BTN_RESTORE": bmp = GetBitmapFromResource("BTN_Restore"); break;
case "BTN_MAXIMIZE": bmp = GetBitmapFromResource("BTN_Maximize"); break;
case "BTN_DOCKOUT": bmp = GetBitmapFromResource("BTN_DockOut"); break;
case "BTN_DOCKIN": bmp = GetBitmapFromResource("BTN_DockIn"); break;
case "BTN_ABOUT": bmp = GetBitmapFromResource("BTN_About"); break;
default: bmp = GetBitmapFromResource("BTN_Push"); IsPushButon = true; break;
}
return bmp;
}
public static void USE_BTN_Image(Button btn, int UseImage)
{
Bitmap bmpBack = new Bitmap(btn.Width, btn.Height);
Bitmap bmp = GetResourceBitmap(btn.Name);
if (bmp != null)
{
StretchBltButton(UseImage, btn, bmp, bmpBack);
btn.BackgroundImage = bmpBack;
}
}
public static void InitButton(Button btn)
{
int UseImage;
if (btn.Enabled) { UseImage = 1; } else { UseImage = 3; }
USE_BTN_Image(btn, UseImage);
}
private static void StretchBltButton(int UseImage, Button btn, Bitmap bmp, Bitmap bmpBack)
{
if (btn == null || bmp == null || bmpBack == null) return;
Graphics g = Graphics.FromImage(bmpBack);
Rectangle srceRect, destRect;
int x, bmpWidth = bmp.Width / 5;
x = (bmpWidth * UseImage) - bmpWidth;
if (IsPushButon) // Adapt the size of the bitmap to the button's.
{
int xSet = 4;
int ySet = 4;
// Horizontal up
destRect = new Rectangle(btn.Width - xSet, 0, xSet, ySet); ;
srceRect = new Rectangle(bmpWidth * UseImage - xSet, 0, xSet, ySet);
g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel);
destRect = new Rectangle(xSet, 0, btn.Width - xSet * 2, ySet);
srceRect = new Rectangle(x + xSet, 0, bmpWidth - xSet * 2, ySet);
g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel);
// Vertical left
destRect = new Rectangle(0, 0, xSet, ySet);
srceRect = new Rectangle(x, 0, xSet, ySet);
g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel);
destRect = new Rectangle(0, ySet, xSet, btn.Height - ySet * 2);
srceRect = new Rectangle(x, ySet, xSet, bmp.Height - ySet * 2);
g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel);
destRect = new Rectangle(0, btn.Height - ySet, xSet, ySet);
srceRect = new Rectangle(x, bmp.Height - ySet, xSet, ySet);
g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel);
// Middle button
destRect = new Rectangle(xSet, ySet, btn.Width - xSet * 2, btn.Height - ySet * 2);
srceRect = new Rectangle(x + xSet, ySet, bmpWidth - xSet * 2, bmp.Height - ySet * 2);
g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel);
// Horizontal down
destRect = new Rectangle(xSet, btn.Height - ySet, btn.Width - xSet * 2, ySet);
srceRect = new Rectangle(x + xSet, bmp.Height - ySet, bmpWidth - xSet * 2, ySet);
g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel);
// Vertical right
destRect = new Rectangle(btn.Width - xSet, ySet, xSet, btn.Height - ySet * 2);
srceRect = new Rectangle(bmpWidth * UseImage - xSet, ySet, xSet, bmp.Height - ySet * 2);
g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel);
destRect = new Rectangle(btn.Width - xSet, btn.Height - ySet, xSet, ySet);
srceRect = new Rectangle(bmpWidth * UseImage - xSet, bmp.Height - ySet, xSet, ySet);
g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel);
}
else
{
destRect = new Rectangle(0, 0, btn.Width, btn.Height);
srceRect = new Rectangle(x, 0, bmpWidth, bmp.Height);
g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel);
}
g.Dispose();
}
public static void CreateButtonRegion(Control control)
{
if (control == null) return; // Bail out if control is null
// Cast to a button object
Button btn = (Button)control;
Bitmap bmp = GetResourceBitmap(btn.Name);
if (bmp == null) return;// Bail if bmp is null
Bitmap bmpBack = new Bitmap(btn.Width, btn.Height);
StretchBltButton(1, btn, bmp, bmpBack);
// Create the region
GraphicsPath path = CreateRegion(bmpBack);
// Apply new region
btn.Region = new Region(path);
// Clean up
bmpBack.Dispose();
bmp.Dispose();
path.Dispose();
// Init btn (to show enabled/disabled mode)
InitButton(btn);
}
public static void DrawBackGround(IntPtr hWnd)
{
Api.RECT rw = new Api.RECT();
Api.GetWindowRect(hWnd, ref rw);
int RgnWidth = rw.right - rw.left, RgnHeight = rw.bottom - rw.top;
Rectangle srceRect, destRect;
Bitmap bmpFrmBack, bmp;
bmpFrmBack = new Bitmap(RgnWidth, RgnHeight);
Graphics g = Graphics.FromImage(bmpFrmBack);
bmp = GetBitmapFromResource("TopLeft");
srceRect = new Rectangle(0, 0, bmp.Width, bmp.Height);
destRect = new Rectangle(0,
0,
FixCaptionLeft,
FixCaptionHeight);
g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel);
bmp.Dispose();
bmp = GetBitmapFromResource("SideLeft");
srceRect = new Rectangle(0, 0, bmp.Width, bmp.Height);
destRect = new Rectangle(0,
FixCaptionHeight,
FixCaptionLeft,
Math.Max(RgnHeight - FixCaptionHeight - FixBottomHeight + 4, 0));
g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel);
bmp.Dispose();
bmp = GetBitmapFromResource("BottomLeft");
srceRect = new Rectangle(0, 0, bmp.Width, bmp.Height);
destRect = new Rectangle(0,
RgnHeight - FixBottomHeight,
FixCaptionLeft,
FixBottomHeight);
g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel);
bmp.Dispose();
bmp = GetBitmapFromResource("TopSide");
srceRect = new Rectangle(0, 0, bmp.Width, bmp.Height);
destRect = new Rectangle(FixCaptionLeft,
0,
Math.Max(RgnWidth - FixCaptionLeft - FixCaptionRight + 8, 0),
FixCaptionHeight);
g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel);
bmp.Dispose();
bmp = GetBitmapFromResource("Center");
srceRect = new Rectangle(0, 0, bmp.Width, bmp.Height);
destRect = new Rectangle(FixCaptionLeft,
FixCaptionHeight,
Math.Max(RgnWidth - FixCaptionLeft - FixCaptionRight + 8, 0),
Math.Max(RgnHeight - FixCaptionHeight - FixBottomHeight + 4, 0));
g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel);
bmp.Dispose();
bmp = GetBitmapFromResource("BottomSide");
srceRect = new Rectangle(0, 0, bmp.Width, bmp.Height);
destRect = new Rectangle(FixCaptionLeft,
RgnHeight - FixBottomHeight,
Math.Max(RgnWidth - FixCaptionLeft - FixCaptionRight + 8, 0),
FixBottomHeight);
g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel);
bmp.Dispose();
bmp = GetBitmapFromResource("TopRight");
srceRect = new Rectangle(0, 0, bmp.Width, bmp.Height);
destRect = new Rectangle(RgnWidth - FixCaptionRight,
0,
FixCaptionRight,
FixCaptionHeight);
g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel);
bmp.Dispose();
bmp = GetBitmapFromResource("SideRight");
srceRect = new Rectangle(0, 0, bmp.Width, bmp.Height);
destRect = new Rectangle(RgnWidth - FixCaptionRight,
FixCaptionHeight,
FixCaptionRight,
Math.Max(RgnHeight - FixCaptionHeight - FixBottomHeight + 4, 0));
g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel);
bmp.Dispose();
bmp = GetBitmapFromResource("BottomRight");
srceRect = new Rectangle(0, 0, bmp.Width, bmp.Height);
destRect = new Rectangle(RgnWidth - FixCaptionRight,
RgnHeight - FixBottomHeight,
FixCaptionRight,
FixBottomHeight);
g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel);
bmp.Dispose();
Form.ActiveForm.BackgroundImage = bmpFrmBack;
g.Dispose();
}
// Rebuild new region from previous one
public static void BuildRegion(IntPtr hWnd)
{
IntPtr hRgnClip = IntPtr.Zero;
Api.RECT rw = new Api.RECT();
Api.GetWindowRect(hWnd, ref rw);
int RgnWidth = rw.right - rw.left, RgnHeight = rw.bottom - rw.top;
// Avoid changing region when iconized !
if (RgnHeight < DockMin) return;
IntPtr hRgn = Api.CreateRectRgn(0, 0, 0, 0);
if (hRgn != IntPtr.Zero)
{
if (Api.GetWindowRgn(hWnd, hRgn))
{
hRgnClip = Api.CreateRectRgn(0, 0, RgnWidth, RgnHeight);
if (hRgnClip != IntPtr.Zero)
{
// Top left corner.
int rgnX = 0; int rgnY = 0;
CombineRegion(ref hRgnClip, hRgn, 0, 0, FixCaptionLeft, FixCaptionHeight, rgnX, rgnY);
// Top right corner.
rgnX = -LastRgnWidth + FixCaptionRight; rgnY = 0;
CombineRegion(ref hRgnClip, hRgn, RgnWidth - FixCaptionRight, 0, FixCaptionRight, FixCaptionHeight, rgnX, rgnY);
// Bottom left corner.
rgnX = 0; rgnY = -LastRgnHeight + FixBottomHeight;
CombineRegion(ref hRgnClip, hRgn, 0, RgnHeight - FixBottomHeight, FixCaptionLeft, FixBottomHeight, rgnX, rgnY);
// Bottom right corner.
rgnX = -LastRgnWidth + FixCaptionRight; rgnY = -LastRgnHeight + FixBottomHeight;
CombineRegion(ref hRgnClip, hRgn, RgnWidth - FixCaptionRight, RgnHeight - FixBottomHeight, FixCaptionRight, FixBottomHeight, rgnX, rgnY);
DrawBackGround(hWnd);
// Set the new region to the form.
Api.SetWindowRgn(hWnd, hRgnClip, false);
// Save the new region size
LastRgnWidth = RgnWidth; LastRgnHeight = RgnHeight;
}
}
Api.DeleteObject(hRgn);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -