GDI绘图:如何创建不规则的区域 想画一个不规则的窗体,窗体的形状通过一个透明的图片来表示,这个图片的外框非常不规则,该如何创建这个区域?发现REGION没有办法使用IMAGE对象为区域参考的,GRAPHICSPATH也没有这个功能。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我在设置了窗体无边框后,把图片的透明色去掉在通过draw的方式绘制到窗体上,结果看到的是透明的,但实际却不是。 你到WWW.CNBLOGS.COM搜搜!!!还没见过你这种问题呢!! using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace APIDemo { public partial class Form1 : Form { [StructLayout(LayoutKind.Sequential)] private struct POINTAPI { internal int x; internal int y; } [DllImport("gdi32.dll")] private static extern IntPtr CreatePolygonRgn( ref POINTAPI lpPoint, int nCount, int nPolyFillMode); [DllImport("user32.dll")] private static extern IntPtr SetWindowRgn( IntPtr hWnd, IntPtr hRgn, ref Boolean bRedraw); public Form1() { InitializeComponent(); //创建不规则窗体 POINTAPI[] poin; poin =new POINTAPI [5]; poin[0].x = 90; poin[0].y = 90; poin[1].x = this.Width; poin[1].y = 0; poin[2].x = Width ; poin[2].y = this.Height/2; poin[3].x = Width / 2; poin[3].y = Height / 2; poin[4].x = 0; poin[4].y = Width; Boolean flag = true; IntPtr hRgn= CreatePolygonRgn(ref poin[0],8,1); SetWindowRgn(this.Handle, hRgn, ref flag ); this.BackColor = Color.BurlyWood; } //设置窗体显示状态 [DllImport("user32.dll")] private static extern int SetWindowPos( IntPtr hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags); private void Start_Btn_Click(object sender, EventArgs e) {//始终显示在前面 SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 1); } private void button1_Click(object sender, EventArgs e) { //最小化始终显示在前面 SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 0); } } } 使用dataGridView的FormattedValue代替Value,可以吗? 有没有仿vs2005 开发界面的 程序 GridView行单击事件改变行颜色 protected成员的使用问题 关于DockPanel V2.2版权的问题 我想写个小游戏,高人给设计设计思路 在什么控件中可以显示类似附件中带图标的文件名称?就像OutLook中的附件显示一样。 通用类型访问类 求助红外编程300分 问题解决马上给分 决不食言 请问textbox里哪个事件是获取焦点的?我要加个JS日历 怎样快速替换字符串中的字符 C# 一个文件流的问题
还没见过你这种问题呢!!
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace APIDemo
{
public partial class Form1 : Form
{
[StructLayout(LayoutKind.Sequential)]
private struct POINTAPI
{
internal int x;
internal int y;
}
[DllImport("gdi32.dll")]
private static extern IntPtr CreatePolygonRgn(
ref POINTAPI lpPoint,
int nCount,
int nPolyFillMode);
[DllImport("user32.dll")]
private static extern IntPtr SetWindowRgn(
IntPtr hWnd,
IntPtr hRgn,
ref Boolean bRedraw);
public Form1()
{
InitializeComponent();
//创建不规则窗体
POINTAPI[] poin;
poin =new POINTAPI [5];
poin[0].x = 90;
poin[0].y = 90;
poin[1].x = this.Width;
poin[1].y = 0;
poin[2].x = Width ;
poin[2].y = this.Height/2;
poin[3].x = Width / 2;
poin[3].y = Height / 2;
poin[4].x = 0;
poin[4].y = Width;
Boolean flag = true;
IntPtr hRgn= CreatePolygonRgn(ref poin[0],8,1);
SetWindowRgn(this.Handle, hRgn, ref flag );
this.BackColor = Color.BurlyWood;
}
//设置窗体显示状态
[DllImport("user32.dll")]
private static extern int SetWindowPos(
IntPtr hwnd,
int hWndInsertAfter,
int x,
int y,
int cx,
int cy,
int wFlags);
private void Start_Btn_Click(object sender, EventArgs e)
{//始终显示在前面
SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 1);
}
private void button1_Click(object sender, EventArgs e)
{
//最小化始终显示在前面
SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 0);
}
}
}