Eron
Mr & Ms Pac-Man
- 20/7/06
- 271
- 4
Mã:
class ControlRegion
{
public static GraphicsPath CreateControlGraphicPath(Bitmap image)
{
GraphicsPath g = new GraphicsPath();
Color transparent = image.GetPixel(0, 0);
int col0;
for (int row = 0; row < image.Height; row++)
{
col0 = 0;
for (int col = 0; col < image.Width; col++)
{
if (image.GetPixel(col, row) != transparent)
{
col0 = col;
int colNext = col;
for (colNext = col0; colNext < image.Width; colNext++)
if (image.GetPixel(colNext, row) == transparent)
break;
g.AddRectangle(new Rectangle(col0, row, colNext - col0, 1));
col = colNext;
}
}
}
return g;
}
public static void CreateControlRegion(object control, Bitmap image)
{
if (control == null || image == null)
return;
Form form = (Form)control;
form.Width = image.Width + 15;
form.Height = image.Height + 30;
form.FormBorderStyle = FormBorderStyle.None;
form.BackgroundImage = image;
form.Region = new Region(CreateControlGraphicPath(image));
}
}
Ở trên là 2 hàm cắt form của mình, hok hỉu sao xung quanh form bị vệt trắng, nhờ các pro chỉ giúp T_T thx