imn1

搞不定,左标签,横文字

  •  
  •   imn1 · Jun 18, 2018 · 3973 views
    This topic created in 3090 days ago, the information mentioned may be changed or developed.
    winform
    $TabControl.Alignment = "LEFT"
    标签放在左边,但标签文字默认是竖排的,现在想横排文字,如何实现?

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

    另外问一下标签放在左边底部,怎么写?
    Supplement 1  ·  Jun 18, 2018
    自己搞定
    首先,这四个属性缺一不可
    $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 replies  •  2018-06-18 18:59:49 +08:00
    imn1
    imn1
    OP
    Jun 18, 2018
    1
    为何在 技术 没见到这贴? PowerShell 不算技术类话题?
    @Livid
    Livid
    Livid
    MOD
    PRO
    Jun 18, 2018
    2
    @imn1 谢谢。那里的列表是手工维护的。现在会加进去。
    geelaw
    geelaw
    Jun 18, 2018 via iPhone
    3
    这个 context 实在是太少了,你提供了 MS 的 C#/VB 的例子的话可以翻译成中文 PowerShell 的。
    imn1
    imn1
    OP
    Jun 18, 2018
    4
    @geelaw
    APPEND
    geelaw
    geelaw
    Jun 18, 2018 via iPhone❤️1
    5
    $s 是第一个参数,在委托声明中的名字是 sender,指事件的发送者,TabControl 自己触发的话,一般是这个 TabControl instance。
    imn1
    imn1
    OP
    Jun 18, 2018
    6
    @geelaw #5
    了解,THX
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1335 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 17:13 · PVG 01:13 · LAX 09:13 · JFK 12:13
    ♥ Do have faith in what you're doing.