V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
imn1
V2EX  ›  PowerShell

搞不定,左标签,横文字

  •  
  •   imn1 · 2018-06-18 13:18:00 +08:00 · 2959 次点击
    这是一个创建于 2130 天前的主题,其中的信息可能已经有所发展或是发生改变。
    winform
    $TabControl.Alignment = "LEFT"
    标签放在左边,但标签文字默认是竖排的,现在想横排文字,如何实现?

    M$上面的例子是 C#/VB,google 只找到 WPF 的例子,winform 的没找到

    另外问一下标签放在左边底部,怎么写?
    第 1 条附言  ·  2018-06-18 18:47:29 +08:00
    自己搞定
    首先,这四个属性缺一不可
    $TabControl.Alignment = "LEFT"
    $TabControl.DrawMode = "OwnerDrawFixed"
    $TabControl.SizeMode = "Fixed" #这个是所有标签等宽,结合下面 ItemSize
    $tbItem = New-Object System.Drawing.Size
    $tbItem.Height = 150
    $tbItem.Width = 30
    $TabControl.ItemSize = $tbItem

    然后,要添加一个 event:DrawItem
    因为这个 event 是上面 DrawMode = "OwnerDrawFixed"触发的
    没有这个 event 就不显示字,没有 DrawMode = "OwnerDrawFixed"字体就竖排
    $tabControl.add_DrawItem({
    param([object]$s, [System.Windows.Forms.DrawItemEventArgs]$e)
    $g = $e.Graphics;
    $items = $TabControl.TabPages;
    $brush = New-Object System.Drawing.SolidBrush Black;
    $g.DrawString($items[$e.Index].Text, $e.Font, $brush, $e.Bounds.Left, $e.Bounds.Top, [System.Drawing.StringFormat]::GenericDefault);
    })

    改一个 C#的,有点乱,$s 是什么没搞清楚
    6 条回复    2018-06-18 18:59:49 +08:00
    imn1
        1
    imn1  
    OP
       2018-06-18 13:39:11 +08:00
    为何在 技术 没见到这贴? PowerShell 不算技术类话题?
    @Livid
    Livid
        2
    Livid  
    MOD
       2018-06-18 15:14:51 +08:00
    @imn1 谢谢。那里的列表是手工维护的。现在会加进去。
    geelaw
        3
    geelaw  
       2018-06-18 18:02:20 +08:00 via iPhone
    这个 context 实在是太少了,你提供了 MS 的 C#/VB 的例子的话可以翻译成中文 PowerShell 的。
    imn1
        4
    imn1  
    OP
       2018-06-18 18:47:54 +08:00
    @geelaw
    APPEND
    geelaw
        5
    geelaw  
       2018-06-18 18:51:27 +08:00 via iPhone   ❤️ 1
    $s 是第一个参数,在委托声明中的名字是 sender,指事件的发送者,TabControl 自己触发的话,一般是这个 TabControl instance。
    imn1
        6
    imn1  
    OP
       2018-06-18 18:59:49 +08:00
    @geelaw #5
    了解,THX
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3485 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 00:17 · PVG 08:17 · LAX 17:17 · JFK 20:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.