将资源文件应用在Skin

思路来源: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();   
  }

...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值