using System.Runtime.InteropServices;
...
[DllImport("Coredll")]
private static extern IntPtr GetCapture();
[DllImport("Coredll")]
private static extern int GetWindowLong(IntPtr hWnd, int offset);
[DllImport("Coredll")]
private static extern int SetWindowLong(IntPtr hWnd, int offset, int value);
[DllImport("Coredll")]
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter,
int x, int y, int width, int height, int flags);
private const int GWL_STYLE = -16;
private const int GWL_EXSTYLE = -20;
private const int SWP_NOSIZE = 0x0001;
private const int SWP_NOMOVE = 0x0002;
private const int SWP_NOZORDER = 0x0004;
private const int SWP_NOACTIVATE = 0x0010;
private const int SWP_FRAMECHANGED = 0x0020;
private const int WS_BORDER = 0x00800000;
private const int WS_EX_CLIENTEDGE = 0x00000200;
private void UpdateBorderStyle(Control ctrl, BorderStyle style)
{
IntPtr hWnd;
int styleValue;
int exStyleValue;
ctrl.Capture = true;
hWnd = GetCapture();
ctrl.Capture = false;
// Get the style, and extended style, information for the control.
styleValue = GetWindowLong(hWnd, GWL_STYLE);
exStyleValue = GetWindowLong(hWnd, GWL_EXSTYLE);
// Determine the new window styles based on the specified value.
switch (style)
{
case System.Windows.Forms.BorderStyle.None:
{
// Indicate that the border should be removed.
styleValue &= (~WS_BORDER);
exStyleValue &= (~WS_EX_CLIENTEDGE);
break;
}
case System.Windows.Forms.BorderStyle.FixedSingle:
{
// Indicate that the border should be a thin line.
styleValue |= (WS_BORDER);
exStyleValue &= (~WS_EX_CLIENTEDGE);
break;
}
case System.Windows.Forms.BorderStyle.Fixed3D:
{
// Indicate that the border should have a 3D appearance.
styleValue &= (~WS_BORDER);
exStyleValue |= (WS_EX_CLIENTEDGE);
break;
}
}
// Update the window styles for the control.
SetWindowLong(hWnd, GWL_STYLE, styleValue);
SetWindowLong(hWnd, GWL_EXSTYLE, exStyleValue);
// Refresh the window to ensure that the style change has been updated
properly.
SetWindowPos(hWnd, IntPtr.Zero, 0, 0, 0, 0, (SWP_FRAMECHANGED |
SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE));
}
And you can update the border style for a control in the following way.
UpdateBorderStyle(this.panel1, BorderStyle.FixedSingle);
--
Tim Wilson
.NET Compact Framework MVP
<joannet...@bellsouth.net> wrote in message
news:1132332910.2...@g43g2000cwa.googlegroups.com...
> Is there a way to set the border for a tabpage or panel? I've added
> them to a form but
> do not see a property for setting the border style.
>
--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com