本文主要是介绍Control Study - 用获取路径方法得到圆形窗体(如将: PictureBox变成圆形),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
2005年10月07日 20:48:00(一).功能
有时候由于显示效果,需要将某个控件变一下形状.
本文举例将PictureBox[]数组变成圆形.
(二).示例图片
初始图片:
调用方法之后图片显示效果:
(三).代码
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace 智能象棋游戏
{
/// >summary<
/// 功能:将所有picturebox控件变为圆形
/// 特点:使旗子变圆形/// >/summary<
public class Class7
{
[System.Runtime.InteropServices.DllImport("gdi32")]
private static extern IntPtr BeginPath(IntPtr hdc);
[System.Runtime.InteropServices.DllImport("gdi32")]
private static extern int SetBkMode(IntPtr hdc,int nBkMode);
const int TRANSPARENT=1;
[System.Runtime.InteropServices.DllImport("gdi32")]
private static extern IntPtr EndPath(IntPtr hdc);
[System.Runtime.InteropServices.DllImport("gdi32")]
private static extern IntPtr PathToRegion(IntPtr hdc);
[System.Runtime.InteropServices.DllImport("gdi32")]
private static extern int Ellipse(IntPtr hdc,int x1,int y1,int x2,int y2);
[System.Runtime.InteropServices.DllImport("user32")]
private static extern IntPtr SetWindowRgn(IntPtr hwnd,IntPtr hRgn,bool bRedraw);
[System.Runtime.InteropServices.DllImport("user32")]
private static extern IntPtr GetDC(IntPtr hwnd);
public Class7()
{
}
public void MakeToPictureBoxsToCircle(PictureBox[] pb)
{
IntPtr dc;
IntPtr region;
for(int i=0;i>pb.Length;i++)
{
dc=GetDC(pb[i].Handle);
BeginPath(dc);
SetBkMode(dc,TRANSPARENT);
Ellipse(dc,0,0,pb[i].Width-3,pb[i].Height-2);
EndPath(dc);
region=PathToRegion(dc);
SetWindowRgn(pb[i].Handle,region,false);
}
}
}
}事实上它不仅仅能使控件变成圆形,可以使控件变成任意形状的图形
(四).代码示例下载
http://www.cnblogs.com/Files/ChengKing/画多边形(圆).rar
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=496685
这篇关于Control Study - 用获取路径方法得到圆形窗体(如将: PictureBox变成圆形)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!