本文整理匯總了C#中System.Drawing.Region.GetHrgn方法的典型用法代碼示例。如果您正苦於以下問題:C# Region.GetHrgn方法的具體用法?C# Region.GetHrgn怎麽用?C# Region.GetHrgn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Drawing.Region
的用法示例。
在下文中一共展示了Region.GetHrgn方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DrawDragOutline
public static void DrawDragOutline(Region region)
{
if (region == null)
return;
// Get hold of the DC for the desktop
IntPtr hDC = User32.GetDC(IntPtr.Zero);
// Define the area we are allowed to draw into
IntPtr hRegion = region.GetHrgn(Graphics.FromHdc(hDC));
Gdi32.SelectClipRgn(hDC, hRegion);
Win32.RECT rectBox = new Win32.RECT();
// Get the smallest rectangle that encloses region
Gdi32.GetClipBox(hDC, ref rectBox);
IntPtr brushHandler = GetHalfToneBrush();
// Select brush into the device context
IntPtr oldHandle = Gdi32.SelectObject(hDC, brushHandler);
// Blit to screen using provided pattern brush and invert with existing screen contents
Gdi32.PatBlt(hDC,
rectBox.left,
rectBox.top,
rectBox.right - rectBox.left,
rectBox.bottom - rectBox.top,
(uint)Win32.RasterOperations.PATINVERT);
// Put old handle back again
Gdi32.SelectObject(hDC, oldHandle);
// Reset the clipping region
Gdi32.SelectClipRgn(hDC, IntPtr.Zero);
Gdi32.DeleteObject(hRegion);
// Must remember to release the HDC resource!
User32.ReleaseDC(IntPtr.Zero, hDC);
}
示例2: cBAreo_CheckStateChanged
private void cBAreo_CheckStateChanged(object sender, EventArgs e)
{
Areo.AreoParams parameter;
switch (cBAreo.CheckState)
{
case CheckState.Checked:
cBAreo.Text = "窗體背景Areo效果";
parameter = new Areo.AreoParams();
parameter.Flags = Areo.AreoParams.ENABLE; //開啟Areo效果
parameter.Enable = true; //開啟Areo效果
parameter.AreoRegion = IntPtr.Zero; //區域為整個窗體背景區
Areo.AreoWindow(this.Handle, parameter); //將整個窗體背景設置為Areo效果
break;
case CheckState.Indeterminate:
cBAreo.Text = "窗體區域Areo效果";
ClearAreoWindow(); //清除原有Areo效果
using (Graphics G = CreateGraphics())
{
parameter = new Areo.AreoParams();
//開啟Areo效果和區域Areo效果
parameter.Flags = Areo.AreoParams.ENABLE | Areo.AreoParams.REGION;
parameter.Enable = true; //開啟Areo效果
Rectangle rect = this.ClientRectangle;
rect.Inflate(-rect.Width / 4, -rect.Height / 4);
regionAreo = new Region(rect); //獲取窗體中心區域
parameter.AreoRegion = regionAreo.GetHrgn(G);//設置Areo區域
Areo.AreoWindow(this.Handle, parameter); //將窗體中心區域設置成Areo效果
}
break;
case CheckState.Unchecked:
cBAreo.Text = "窗體無Areo效果";
ClearAreoWindow();
break;
default:
break;
}
this.Invalidate();
}
示例3: CreateRegion
public static void CreateRegion(IntPtr hWnd, int radius, RoundStyle roundStyle, bool redraw)
{
Win32.Struct.RECT lpRect = new Win32.Struct.RECT();
Win32.NativeMethods.GetWindowRect(hWnd, ref lpRect);
Rectangle rect = new Rectangle(System.Drawing.Point.Empty, lpRect.Size);
if (roundStyle != RoundStyle.None)
{
using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, radius, roundStyle, true))
{
using (Region region = new Region(path))
{
path.Widen(Pens.White);
region.Union(path);
IntPtr windowDC = Win32.NativeMethods.GetWindowDC(hWnd);
try
{
using (Graphics graphics = Graphics.FromHdc(windowDC))
{
Win32.NativeMethods.SetWindowRgn(hWnd, region.GetHrgn(graphics), redraw);
}
}
finally
{
Win32.NativeMethods.ReleaseDC(hWnd, windowDC);
}
}
return;
}
}
IntPtr hRgn = Win32.NativeMethods.CreateRectRgn(0, 0, rect.Width, rect.Height);
Win32.NativeMethods.SetWindowRgn(hWnd, hRgn, redraw);
}
示例4: SetClipRegion
internal override void SetClipRegion(IntPtr hwnd, Region region) {
if (region == null)
Win32SetWindowRgn (hwnd, IntPtr.Zero, true);
else
Win32SetWindowRgn(hwnd, region.GetHrgn(Graphics.FromHwnd(hwnd)), true);
}
示例5: GetMessage
//.........這裏部分代碼省略.........
} else {
if (!hwnd.nc_expose_pending) {
goto ProcessNextMessage;
}
switch (hwnd.border_style) {
case FormBorderStyle.Fixed3D: {
Graphics g;
g = Graphics.FromHwnd(hwnd.whole_window);
if (hwnd.border_static)
ControlPaint.DrawBorder3D(g, new Rectangle(0, 0, hwnd.Width, hwnd.Height), Border3DStyle.SunkenOuter);
else
ControlPaint.DrawBorder3D(g, new Rectangle(0, 0, hwnd.Width, hwnd.Height), Border3DStyle.Sunken);
g.Dispose();
break;
}
case FormBorderStyle.FixedSingle: {
Graphics g;
g = Graphics.FromHwnd(hwnd.whole_window);
ControlPaint.DrawBorder(g, new Rectangle(0, 0, hwnd.Width, hwnd.Height), Color.Black, ButtonBorderStyle.Solid);
g.Dispose();
break;
}
}
DriverDebug("GetMessage(): Window {0:X} Exposed non-client area {1},{2} {3}x{4}",
hwnd.client_window.ToInt32(), xevent.ExposeEvent.x, xevent.ExposeEvent.y,
xevent.ExposeEvent.width, xevent.ExposeEvent.height);
Rectangle rect = new Rectangle (xevent.ExposeEvent.x, xevent.ExposeEvent.y, xevent.ExposeEvent.width, xevent.ExposeEvent.height);
Region region = new Region (rect);
IntPtr hrgn = region.GetHrgn (null); // Graphics object isn't needed
msg.message = Msg.WM_NCPAINT;
msg.wParam = hrgn == IntPtr.Zero ? (IntPtr)1 : hrgn;
msg.refobject = region;
break;
}
DriverDebug("GetMessage(): Window {0:X} Exposed area {1},{2} {3}x{4}",
hwnd.client_window.ToInt32(), xevent.ExposeEvent.x, xevent.ExposeEvent.y,
xevent.ExposeEvent.width, xevent.ExposeEvent.height);
if (Caret.Visible == true) {
Caret.Paused = true;
HideCaret();
}
if (Caret.Visible == true) {
ShowCaret();
Caret.Paused = false;
}
msg.message = Msg.WM_PAINT;
break;
}
case XEventName.DestroyNotify: {
// This is a bit tricky, we don't receive our own DestroyNotify, we only get those for our children
hwnd = Hwnd.ObjectFromHandle(xevent.DestroyWindowEvent.window);
// We may get multiple for the same window, act only one the first (when Hwnd still knows about it)
if ((hwnd != null) && (hwnd.client_window == xevent.DestroyWindowEvent.window)) {
CleanupCachedWindows (hwnd);
DriverDebug("Received X11 Destroy Notification for {0}", XplatUI.Window(hwnd.client_window));
示例6: HitTestBackground
public HitTestCode HitTestBackground(Graphics g, Rectangle backgroundRectangle, Region region, Point pt, HitTestOptions options) {
if (g == null) {
throw new ArgumentNullException("g");
}
IntPtr hRgn = region.GetHrgn(g);
return HitTestBackground(g, backgroundRectangle, hRgn, pt, options);
}
示例7: GetMessage
//.........這裏部分代碼省略.........
xevent.ExposeEvent.x, xevent.ExposeEvent.y,
xevent.ExposeEvent.width, xevent.ExposeEvent.height);
#endif
msg.message = Msg.WM_PAINT;
}
else {
Graphics g;
switch (hwnd.border_style) {
case FormBorderStyle.Fixed3D:
g = Graphics.FromHwnd(hwnd.WholeWindow);
ControlPaint.DrawBorder3D(g, new Rectangle(0, 0, hwnd.Width, hwnd.Height),
Border3DStyle.Sunken);
g.Dispose();
break;
case FormBorderStyle.FixedSingle:
g = Graphics.FromHwnd(hwnd.WholeWindow);
ControlPaint.DrawBorder(g, new Rectangle(0, 0, hwnd.Width, hwnd.Height),
Color.Black, ButtonBorderStyle.Solid);
g.Dispose();
break;
}
#if DriverDebugExtra
Console.WriteLine("GetMessage(): Window {0:X} Exposed non-client area {1},{2} {3}x{4}",
hwnd.ClientWindow.ToInt32(),
xevent.ExposeEvent.x, xevent.ExposeEvent.y,
xevent.ExposeEvent.width, xevent.ExposeEvent.height);
#endif
Rectangle rect = new Rectangle (xevent.ExposeEvent.x, xevent.ExposeEvent.y,
xevent.ExposeEvent.width, xevent.ExposeEvent.height);
Region region = new Region (rect);
IntPtr hrgn = region.GetHrgn (null); // Graphics object isn't needed
msg.message = Msg.WM_NCPAINT;
msg.wParam = hrgn == IntPtr.Zero ? (IntPtr)1 : hrgn;
msg.refobject = region;
}
return true;
case XEventName.DestroyNotify:
// This is a bit tricky, we don't receive our own DestroyNotify, we only get those for our children
hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(xevent.DestroyWindowEvent.window);
// We may get multiple for the same window, act only one the first (when Hwnd still knows about it)
if ((hwnd != null) && (hwnd.ClientWindow == xevent.DestroyWindowEvent.window)) {
CleanupCachedWindows (hwnd);
#if DriverDebugDestroy
Console.WriteLine("Received X11 Destroy Notification for {0}", XplatUI.Window(hwnd.ClientWindow));
#endif
msg.hwnd = hwnd.ClientWindow;
msg.message=Msg.WM_DESTROY;
hwnd.Dispose();
}
else
goto ProcessNextMessage;
return true;
case XEventName.ClientMessage:
if (Dnd.HandleClientMessage (ref xevent))
goto ProcessNextMessage;
示例8: FromRegion
/// <devdoc>
/// Creates a WindowsRegion from a System.Drawing.Region.
/// </devdoc>
public static WindowsRegion FromRegion( Region region, Graphics g ){
if (region.IsInfinite(g)){
// An infinite region would cover the entire device region which is the same as
// not having a clipping region. Observe that this is not the same as having an
// empty region, which when clipping to it has the effect of excluding the entire
// device region.
// To remove the clip region from a dc the SelectClipRgn() function needs to be
// called with a null region ptr - that's why we use the empty constructor here.
// GDI+ will return IntPtr.Zero for Region.GetHrgn(Graphics) when the region is
// Infinite.
return new WindowsRegion();
}
return WindowsRegion.FromHregion(region.GetHrgn(g), true);
}
示例9: SetWindowRegion
protected void SetWindowRegion(Size winSize)
{
// Style specific handling
if (_style == VisualStyle.IDE)
{
int shadowHeight = _position[(int)_style, (int)PI.ShadowHeight];
int shadowWidth = _position[(int)_style, (int)PI.ShadowWidth];
// Create a new region object
using (Region drawRegion = new Region())
{
// Can draw anywhere
drawRegion.MakeInfinite();
// Remove the area above the right hand shadow
drawRegion.Xor(new Rectangle(winSize.Width - shadowWidth, 0, shadowWidth, shadowHeight));
// When drawing upwards from a vertical menu we need to allow a connection between the
// MenuControl selection box and the PopupMenu shadow
if (!((_direction == Direction.Vertical) && !_excludeTop))
{
// Remove the area left of the bottom shadow
drawRegion.Xor(new Rectangle(0, winSize.Height - shadowHeight, shadowWidth, shadowHeight));
}
// Define a region to prevent drawing over exposed corners of shadows
using(Graphics g = Graphics.FromHwnd(this.Handle))
WindowsAPI.SetWindowRgn(this.Handle, drawRegion.GetHrgn(g), false);
}
}
}
示例10: Update
/// <include file='doc\ErrorProvider.uex' path='docs/doc[@for="ErrorProvider.ErrorWindow.Update"]/*' />
/// <devdoc>
/// Move and size the error window, compute and set the window region,
/// set the tooltip rectangles and descriptions. This basically brings
/// the error window up to date with the internal data structures.
/// </devdoc>
public void Update(bool timerCaused) {
IconRegion iconRegion = provider.Region;
Size size = iconRegion.Size;
windowBounds = Rectangle.Empty;
for (int i = 0; i < items.Count; i++) {
ControlItem item = (ControlItem)items[i];
Rectangle iconBounds = item.GetIconBounds(size);
if (windowBounds.IsEmpty)
windowBounds = iconBounds;
else
windowBounds = Rectangle.Union(windowBounds, iconBounds);
}
Region windowRegion = new Region(new Rectangle(0, 0, 0, 0));
IntPtr windowRegionHandle = IntPtr.Zero;
try {
for (int i = 0; i < items.Count; i++) {
ControlItem item = (ControlItem)items[i];
Rectangle iconBounds = item.GetIconBounds(size);
iconBounds.X -= windowBounds.X;
iconBounds.Y -= windowBounds.Y;
bool showIcon = true;
if (!item.ToolTipShown) {
switch (provider.BlinkStyle) {
case ErrorBlinkStyle.NeverBlink:
// always show icon
break;
case ErrorBlinkStyle.BlinkIfDifferentError:
showIcon = (item.BlinkPhase == 0) || (item.BlinkPhase > 0 && (item.BlinkPhase & 1) == (i & 1));
break;
case ErrorBlinkStyle.AlwaysBlink:
showIcon = ((i & 1) == 0) == provider.showIcon;
break;
}
}
if (showIcon)
{
iconRegion.Region.Translate(iconBounds.X, iconBounds.Y);
windowRegion.Union(iconRegion.Region);
iconRegion.Region.Translate(-iconBounds.X, -iconBounds.Y);
}
if (tipWindow != null) {
NativeMethods.TOOLINFO_T toolInfo = new NativeMethods.TOOLINFO_T();
toolInfo.cbSize = Marshal.SizeOf(toolInfo);
toolInfo.hwnd = Handle;
toolInfo.uId = item.Id;
toolInfo.lpszText = item.Error;
toolInfo.rect = NativeMethods.RECT.FromXYWH(iconBounds.X, iconBounds.Y, iconBounds.Width, iconBounds.Height);
toolInfo.uFlags = NativeMethods.TTF_SUBCLASS;
if (provider.RightToLeft) {
toolInfo.uFlags |= NativeMethods.TTF_RTLREADING;
}
UnsafeNativeMethods.SendMessage(new HandleRef(tipWindow, tipWindow.Handle), NativeMethods.TTM_SETTOOLINFO, 0, toolInfo);
}
if (timerCaused && item.BlinkPhase > 0) {
item.BlinkPhase--;
}
}
if (timerCaused) {
provider.showIcon = !provider.showIcon;
}
DeviceContext dc = null;
dc = DeviceContext.FromHwnd(this.Handle);
try {
CreateMirrorDC(dc.Hdc, windowBounds.Width);
Graphics graphics = Graphics.FromHdcInternal(mirrordc.Hdc);
try {
windowRegionHandle = windowRegion.GetHrgn(graphics);
System.Internal.HandleCollector.Add(windowRegionHandle, NativeMethods.CommonHandles.GDI);
}
finally {
graphics.Dispose();
RestoreMirrorDC();
}
if (UnsafeNativeMethods.SetWindowRgn(new HandleRef(this, Handle), new HandleRef(windowRegion, windowRegionHandle), true) != 0) {
//The HWnd owns the region.
windowRegionHandle = IntPtr.Zero;
}
}
finally {
if (dc != null) {
dc.Dispose();
}
//.........這裏部分代碼省略.........
示例11: NcPaint
/// <summary>
/// Redraws the non client area.
/// </summary>
/// <param name="invalidateBuffer">if set to <c>true</c> the buffer is invalidated.</param>
/// <returns>true if the original painting should be suppressed otherwise false.</returns>
private bool NcPaint(bool invalidateBuffer)
{
if (!IsProcessNcArea)
return false;
bool result = false;
IntPtr hdc = (IntPtr)0;
Graphics g = null;
Region region = null;
IntPtr hrgn = (IntPtr)0;
try
{
// no drawing needed
if (_parentForm.MdiParent != null && _parentForm.WindowState == FormWindowState.Maximized)
{
_currentCacheSize = Size.Empty;
return false;
}
// prepare image bounds
Size borderSize = FormExtenders.GetBorderSize(_parentForm);
int captionHeight = FormExtenders.GetCaptionHeight(_parentForm);
RECT rectScreen = new RECT();
Win32Api.GetWindowRect(_parentForm.Handle, ref rectScreen);
Rectangle rectBounds = rectScreen.ToRectangle();
rectBounds.Offset(-rectBounds.X, -rectBounds.Y);
// prepare clipping
Rectangle rectClip = rectBounds;
region = new Region(rectClip);
rectClip.Inflate(-borderSize.Width, -borderSize.Height);
rectClip.Y += captionHeight;
rectClip.Height -= captionHeight;
// create graphics handle
hdc = Win32Api.GetDCEx(_parentForm.Handle, (IntPtr)0,
(DCXFlags.DCX_CACHE | DCXFlags.DCX_CLIPSIBLINGS | DCXFlags.DCX_WINDOW));
g = Graphics.FromHdc(hdc);
// Apply clipping
region.Exclude(rectClip);
hrgn = region.GetHrgn(g);
Win32Api.SelectClipRgn(hdc, hrgn);
// create new buffered graphics if needed
if (_bufferGraphics == null || _currentCacheSize != rectBounds.Size)
{
if (_bufferGraphics != null)
_bufferGraphics.Dispose();
_bufferGraphics = _bufferContext.Allocate(g, new Rectangle(0, 0,
rectBounds.Width, rectBounds.Height));
_currentCacheSize = rectBounds.Size;
invalidateBuffer = true;
}
if (invalidateBuffer)
{
// Create painting meta data for form
SkinningFormPaintData paintData = new SkinningFormPaintData(_bufferGraphics.Graphics, rectBounds)
{
Borders = borderSize,
CaptionHeight = captionHeight,
Active = _formIsActive,
HasMenu = FormExtenders.HasMenu(_parentForm),
IconSize = SystemInformation.SmallIconSize,
IsSmallCaption =
captionHeight ==
SystemInformation.ToolWindowCaptionHeight,
Text = _parentForm.Text
};
// create painting meta data for caption buttons
if (_captionButtons.Count > 0)
{
paintData.CaptionButtons = new CaptionButtonPaintData[_captionButtons.Count];
for (int i = 0; i < _captionButtons.Count; i++)
{
CaptionButton button = _captionButtons[i];
CaptionButtonPaintData buttonData = new CaptionButtonPaintData(_bufferGraphics.Graphics, button.Bounds)
{
Pressed = button.Pressed,
Hovered = button.Hovered,
Enabled = button.Enabled,
HitTest = button.HitTest
};
paintData.CaptionButtons[i] = buttonData;
}
}
// paint
result = _manager.CurrentSkin.OnNcPaint(_parentForm, paintData);
//.........這裏部分代碼省略.........
示例12: Update
public void Update(bool timerCaused)
{
ErrorProvider.IconRegion region = this.provider.Region;
Size size = region.Size;
this.windowBounds = Rectangle.Empty;
for (int i = 0; i < this.items.Count; i++)
{
Rectangle iconBounds = ((ErrorProvider.ControlItem) this.items[i]).GetIconBounds(size);
if (this.windowBounds.IsEmpty)
{
this.windowBounds = iconBounds;
}
else
{
this.windowBounds = Rectangle.Union(this.windowBounds, iconBounds);
}
}
Region wrapper = new Region(new Rectangle(0, 0, 0, 0));
IntPtr zero = IntPtr.Zero;
try
{
for (int j = 0; j < this.items.Count; j++)
{
ErrorProvider.ControlItem item2 = (ErrorProvider.ControlItem) this.items[j];
Rectangle rectangle2 = item2.GetIconBounds(size);
rectangle2.X -= this.windowBounds.X;
rectangle2.Y -= this.windowBounds.Y;
bool flag = true;
if (!item2.ToolTipShown)
{
switch (this.provider.BlinkStyle)
{
case ErrorBlinkStyle.BlinkIfDifferentError:
flag = (item2.BlinkPhase == 0) || ((item2.BlinkPhase > 0) && ((item2.BlinkPhase & 1) == (j & 1)));
break;
case ErrorBlinkStyle.AlwaysBlink:
flag = ((j & 1) == 0) == this.provider.showIcon;
break;
}
}
if (flag)
{
region.Region.Translate(rectangle2.X, rectangle2.Y);
wrapper.Union(region.Region);
region.Region.Translate(-rectangle2.X, -rectangle2.Y);
}
if (this.tipWindow != null)
{
System.Windows.Forms.NativeMethods.TOOLINFO_T toolinfo_t;
toolinfo_t = new System.Windows.Forms.NativeMethods.TOOLINFO_T {
cbSize = Marshal.SizeOf(toolinfo_t),
hwnd = base.Handle,
uId = item2.Id,
lpszText = item2.Error,
rect = System.Windows.Forms.NativeMethods.RECT.FromXYWH(rectangle2.X, rectangle2.Y, rectangle2.Width, rectangle2.Height),
uFlags = 0x10
};
if (this.provider.RightToLeft)
{
toolinfo_t.uFlags |= 4;
}
System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this.tipWindow, this.tipWindow.Handle), System.Windows.Forms.NativeMethods.TTM_SETTOOLINFO, 0, toolinfo_t);
}
if (timerCaused && (item2.BlinkPhase > 0))
{
item2.BlinkPhase--;
}
}
if (timerCaused)
{
this.provider.showIcon = !this.provider.showIcon;
}
DeviceContext context = null;
using (context = DeviceContext.FromHwnd(base.Handle))
{
this.CreateMirrorDC(context.Hdc, this.windowBounds.Width);
Graphics g = Graphics.FromHdcInternal(this.mirrordc.Hdc);
try
{
zero = wrapper.GetHrgn(g);
System.Internal.HandleCollector.Add(zero, System.Windows.Forms.NativeMethods.CommonHandles.GDI);
}
finally
{
g.Dispose();
this.RestoreMirrorDC();
}
if (System.Windows.Forms.UnsafeNativeMethods.SetWindowRgn(new HandleRef(this, base.Handle), new HandleRef(wrapper, zero), true) != 0)
{
zero = IntPtr.Zero;
}
}
}
finally
{
wrapper.Dispose();
if (zero != IntPtr.Zero)
{
System.Windows.Forms.SafeNativeMethods.DeleteObject(new HandleRef(null, zero));
//.........這裏部分代碼省略.........
示例13: GetHrgn_Infinite_MakeEmpty
public void GetHrgn_Infinite_MakeEmpty ()
{
Region r = new Region ();
Assert.IsFalse (r.IsEmpty (graphic), "!Empty");
Assert.IsTrue (r.IsInfinite (graphic), "Infinite");
Assert.AreEqual (IntPtr.Zero, r.GetHrgn (graphic), "Handle==0");
r.MakeEmpty ();
Assert.IsTrue (r.IsEmpty (graphic), "Empty");
Assert.IsFalse (r.IsInfinite (graphic), "!Infinite");
IntPtr h = r.GetHrgn (graphic);
Assert.IsFalse (h == IntPtr.Zero, "Handle!=0");
#if NET_2_0
r.ReleaseHrgn (h);
#endif
}
示例14: NCPaint
private void NCPaint()
{
if (this.Parent == null)
return;
if (this.Width <= 0 || this.Height <= 0)
return;
IntPtr windowDC = NativeMethods.GetDCEx(this.Handle,
IntPtr.Zero, NativeMethods.DCX_CACHE |
NativeMethods.DCX_WINDOW |
NativeMethods.DCX_CLIPSIBLINGS |
NativeMethods.DCX_LOCKWINDOWUPDATE);
if (windowDC.Equals(IntPtr.Zero))
return;
using (Bitmap bm = new Bitmap(this.Width, this.Height,
System.Drawing.Imaging.PixelFormat.Format32bppPArgb))
{
using (Graphics g = Graphics.FromImage(bm))
{
Rectangle borderRect = new Rectangle(0, 0,
Width - 1, Height - 1);
using (Pen borderPen = new Pen(this.borderColor, 1))
{
borderPen.Alignment = PenAlignment.Inset;
g.DrawRectangle(borderPen, borderRect);
}
// Create and Apply a Clip Region to the WindowDC
using (Region Rgn = new Region(new
Rectangle(0, 0, Width, Height)))
{
Rgn.Exclude(new Rectangle(1, 1, Width - 2, Height - 2));
IntPtr hRgn = Rgn.GetHrgn(g);
if (!hRgn.Equals(IntPtr.Zero))
NativeMethods.SelectClipRgn(windowDC, hRgn);
IntPtr bmDC = g.GetHdc();
IntPtr hBmp = bm.GetHbitmap();
IntPtr oldDC = NativeMethods.SelectObject(bmDC,
hBmp);
NativeMethods.BitBlt(windowDC, 0, 0, bm.Width,
bm.Height, bmDC, 0, 0, NativeMethods.SRCCOPY);
NativeMethods.SelectClipRgn(windowDC, IntPtr.Zero);
NativeMethods.DeleteObject(hRgn);
g.ReleaseHdc(bmDC);
NativeMethods.SelectObject(oldDC, hBmp);
NativeMethods.DeleteObject(hBmp);
bm.Dispose();
}
}
}
NativeMethods.ReleaseDC(this.Handle, windowDC);
}
示例15: GetHRegion
private IntPtr GetHRegion()
{
//Define a Clip Region to pass back to WM_NCPAINTs wParam.
//Must be in Screen Coordinates.
IntPtr hRgn;
Rectangle winRect = this.Parent.RectangleToScreen(this.Bounds);
Rectangle clientRect =
this.RectangleToScreen(this.ClientRectangle);
Region updateRegion = new Region(winRect);
updateRegion.Complement(clientRect);
using (Graphics g = this.CreateGraphics())
hRgn = updateRegion.GetHrgn(g);
updateRegion.Dispose();
return hRgn;
}