winform设置竖向的tabcontrol
时间: 2023-11-08 11:06:45 浏览: 139
要设置竖向的TabControl,可以使用如下代码:
```c#
public class VerticalTabControl : TabControl
{
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
if (!DesignMode && Alignment == TabAlignment.Left)
{
var style = NativeMethods.SendMessage(Handle, NativeMethods.TCM_GETEXTENDEDSTYLE, IntPtr.Zero, IntPtr.Zero);
style |= NativeMethods.TCS_VERTICAL | NativeMethods.TCS_TABS | NativeMethods.TCS_MULTILINE;
NativeMethods.SendMessage(Handle, NativeMethods.TCM_SETEXTENDEDSTYLE, IntPtr.Zero, (IntPtr)style);
}
}
private static class NativeMethods
{
public const int TCM_GETEXTENDEDSTYLE = 0x4D0;
public const int TCM_SETEXTENDEDSTYLE = 0x4D1;
public const int TCS_VERTICAL = 0x0080;
public const int TCS_TABS = 0x0000;
public const int TCS_MULTILINE = 0x0200;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
}
}
```
然后在窗体中使用VerticalTabControl替换原来的TabControl即可。
相关问题:
1. 如何设置TabControl的外观?
2. 如何在TabPage中添加控件?
3. 如何在TabPage之
阅读全文