2.
Label控件的边框属性为BorderStyle,一共有两种属性值:0和1。分别表示没有边框和固定边框,该属性在Label控件的属性表中通过单击鼠标选择设置
VB中,对象的边框类型由属性BorderStyle设置。
border-style属性用于设置元素所有边框的样式,或者单独地为各边设置边框样式。只有当这个值不是none时,边框才可能出现。
语法:Object.style.borderStyle=style
扩展资料
VB基础边框类型:有0-none,1-fixed Single,2-Sizable,3-fixed dialog,4-fixed toolwindow,5-sizable toolwindow。这六种边框类型,其中2-Sizable是VB默认的设置。
当BorderStyle设为1-fixed Single时,可自行改变窗体大小,没有最大最小按钮,只有关闭按钮。
当BorderStyle设为2-Sizable时,也就是VB默认的设置,此时,会有最大最小和关闭按钮,也可以调整大小。
当BorderStyle设为3-fixed dialog时,单边固定边框,也就是只能单边调整大小,没有最大最小按钮,有关闭按钮。
当BorderStyle设为4-fixed toolwindow时,也是单边固定按钮,只有关闭按钮,可伸缩。
当BorderStyle设为5-sizable toolwindow时,也就是最后一种类型,显示关闭按钮。
private const int GWL_STYLE = (-16)
private const int GWL_EXSTYLE = (-20)
private const uint WS_EX_LAYERED = 0x80000
private const uint WS_EX_TRANSPARENT = 0x20
private const uint WS_THICKFRAME = 262144
private const uint WS_BORDER = 8388608
/// <summary>使指定 「 <see cref="IntPtr"/>句柄」 窗体 边框样式变为无边框。</summary>
public static uint 无边框窗体(IntPtr 句柄) {
uint style = API_窗口.GetWindowLong(句柄, GWL_STYLE)
style &= ~WS_BORDER
style &= ~WS_THICKFRAME
return API_窗口.SetWindowLong(句柄, GWL_STYLE, style)
}
API窗口静态类
[DllImport("user32", EntryPoint = "SetWindowLong")]
public static extern uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong)
[DllImport("user32", EntryPoint = "GetWindowLong")]
public static extern uint GetWindowLong(IntPtr hwnd, int nIndex)
修改窗口位置
/// <summary>
/// 设置窗体的位置和大小。
/// </summary>
/// <param name="hWnd"></param>
/// <param name="hWndInsertAfter">用于标识在z-顺序的此 CWnd 对象之前的 CWnd 对象。
/// <para></para>如果uFlags参数中设置了SWP_NOZORDER标记则本参数将被忽略。可为下列值之一:
/// <para></para>HWND_BOTTOM:值为1,将窗体置于Z序的底部。如果参数hWnd标识了一个顶层窗体,则窗体失去顶级位置,并且被置在其他窗体的底部。
/// <para></para>HWND_NOTOPMOST:值为-2,将窗体置于所有非顶层窗体之上(即在所有顶层窗体之后)。如果窗体已经是非顶层窗体则该标志不起作用。
/// <para></para>HWND_TOP:值为0,将窗体置于Z序的顶部。
/// <para></para>HWND_TOPMOST:值为-1,将窗体置于所有非顶层窗体之上。即使窗体未被激活窗体也将保持顶级位置。</param>
/// <param name="x">窗体新的x坐标。如hwnd是一个子窗体,则x用父窗体的客户区坐标表示</param>
/// <param name="y">窗体新的y坐标。如hwnd是一个子窗体,则y用父窗体的客户区坐标表示</param>
/// <param name="Width">指定新的窗体宽度</param>
/// <param name="Height">指定新的窗体高度</param>
/// <param name="wFlags"></param>
/// <returns></returns>
[DllImport("user32.dll", CharSet = CharSet.Ansi, EntryPoint = "SetWindowPos")]
public static extern int SetWindowPos(IntPtr hWnd, hWndInsertAfter hWndInsertAfter, int x, int y, int Width, int Height, wFlags wFlags)
/// <summary>
/// 调整指定 「 <see cref="IntPtr"/>句柄」 窗体的位置和尺寸。
/// </summary>
/// <param name="句柄">指定 「 <see cref="IntPtr"/>句柄」 窗体</param>
/// <param name="x">横坐标</param>
/// <param name="y">纵坐标</param>
/// <param name="w">宽</param>
/// <param name="h">高</param>
public static int 调整窗体(IntPtr 句柄, int x, int y, int w, int h) {
return API_窗口.SetWindowPos(句柄, 0, x, y, w, h, wFlags.SWP_NOZORDER)
}
/// <summary>
/// 调整指定 「 <see cref="IntPtr"/>句柄」 窗体的位置。
/// </summary>
/// <param name="句柄">指定 「 <see cref="IntPtr"/>句柄」 窗体</param>
/// <param name="x">横坐标</param>
/// <param name="y">纵坐标</param>
public static int 调整窗体位置(IntPtr 句柄, int x, int y) {
return API_窗口.SetWindowPos(句柄, 0, x, y, 0, 0, wFlags.SWP_NOSIZE | wFlags.SWP_NOZORDER)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)