您的位置:首页 > 其它

将资源文件应用在Skin

2006-01-13 15:12 316 查看
思路来源:http://community.csdn.net//Expert/TopicView1.asp?id=4514237

private ResourceManager rm;
private Bitmap titlemiddle;
private Bitmap titleleft;
private Bitmap bottom;
private Bitmap right;
private Bitmap left;
private Bitmap system3back;
private Bitmap system3max;
private Bitmap systembutton;
private Brush brush;

......

rm = new ResourceManager("Cool.XPResources", Assembly.GetExecutingAssembly());
titleleft = (Bitmap)rm.GetObject("titleleft.jpg");
titlemiddle = (Bitmap)rm.GetObject("titlemiddle.jpg");
system3back = (Bitmap)rm.GetObject("system3back.jpg");
system3max = (Bitmap)rm.GetObject("system3max.jpg");
bottom = (Bitmap)rm.GetObject("bottom.jpg");
right = (Bitmap)rm.GetObject("right.jpg");
left = (Bitmap)rm.GetObject("left.jpg");

if(this.WindowState == System.Windows.Forms.FormWindowState.Maximized )
systembutton = system3back;
else
systembutton = system3max;
}

...

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
g = e.Graphics;
DrawTop_Left(g);//画标题栏左边
DrawTop_Right(g);//画标题栏右边
DrawTop_Middle(g);//画标题栏中间
g.Dispose();
g = null;
}

...

private void DrawTop_Left(Graphics g)
{//画标题栏左边(左上角)
brush = new TextureBrush(titleleft, new Rectangle(0, 0, titleleft.Width, titleleft.Height));
g.FillRectangle(brush, 0, 0, titleleft.Width, titleleft.Height);
brush.Dispose();
brush = null;
this.ititleleftWidth = titleleft.Width;
this.ititleleftHeight = titleleft.Height;
GC.Collect();
}

...

private void DrawTop_Right(Graphics g)
{//画标题栏右边(右上角)
iTop_Right_Width = systembutton.Width;
iTop_Right_Height = systembutton.Height;
brush = new TextureBrush(systembutton, new Rectangle(0, 0, systembutton.Width , systembutton.Height));
g.FillRectangle(brush,this.Width - systembutton.Width,0,systembutton.Width,systembutton.Height);
brush.Dispose();
brush = null;
GC.Collect();
}

...

private void DrawTop_Middle(Graphics g)
{//画标题栏中间
brush = new TextureBrush(titlemiddle,new Rectangle(0, 0, titlemiddle.Width , titlemiddle.Height));
g.FillRectangle(brush,ititleleftWidth ,0, this.Width - ititleleftWidth - iTop_Right_Width , titlemiddle.Height);
brush.Dispose();
brush = null;
System.GC.Collect();
}

...
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: