程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> 關於C# >> C#制作任意不規則按鈕

C#制作任意不規則按鈕

編輯:關於C#

using System.Drawing.Drawing2D;
private void button3_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
 { this.button3.Cursor = Cursors.Hand;
     Bitmap bmpBob =(Bitmap)this.button3.Image;
   GraphicsPath graphicsPath = CalculateControlGraphicsPath(bmpBob);
   this.button3.Region = new Region(graphicsPath);
 }
 private static GraphicsPath CalculateControlGraphicsPath(Bitmap bitmap)
 {

  GraphicsPath graphicsPath = new GraphicsPath();

  Color colorTransparent = bitmap.GetPixel(0, 0);

  int colOpaquePixel = 0;

  for(int row = 0; row < bitmap.Height; row ++)
  {

  colOpaquePixel = 0;

  for(int col = 0; col < bitmap.Width; col ++)
  {

   if(bitmap.GetPixel(col, row) != colorTransparent)
   {

   colOpaquePixel = col;

   int colNext = col;

   for(colNext=colOpaquePixel; colNext<bitmap.Width; colNext++)
    if(bitmap.GetPixel(colNext, row) == colorTransparent)
    break;

   graphicsPath.AddRectangle(new Rectangle(colOpaquePixel,
    row, colNext - colOpaquePixel, 1));

   col = colNext;
   }
  }
  }

  return graphicsPath;
 }

http://www.cnblogs.com/zengping/archive/2006/08/30/490720.html

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved