垂直选项卡控制与水平的WinForms文本 [英] Vertical Tab Control with horizontal text in Winforms

查看:154
本文介绍了垂直选项卡控制与水平的WinForms文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对我的TabControl显示在左边,有时右边的标签。
不同于System.Windows.Forms.TabControl,不过,我想文本保持水平,而不是被旋转了90度或270度的水平。

下面是几个图片说明概念

虽然我可以写code要做到这一点我在大约一两个小时,我只是想我会先问是否有任何现有的WinForms控制实现这种功能。

注:任何现有的解决方案应该preferably是非商业性

感谢。

解决方案

我不知道该如何强劲,这是我不能声称已经创造了它,但... <一href="http://www.dreamin$c$c.net/forums/topic/125792-how-to-make-vertical-tabs/">http://www.dreamin$c$c.net/forums/topic/125792-how-to-make-vertical-tabs/

下面是这样做的一种方式。

所以我们首先要改变其调整到左,通过设置属性:

对齐=左

如果您有XP主题打开,那么你可能会注意到奇怪的布局选项卡控制。不要担心,我们将使它罚款。

正如你可能已经注意到,标签是垂直的,而我们的要求是水平的。因此,我们可以改变标签的大小。但在此之前,我们可以做到这一点,我们必须设置SizeMode属性为,

SizeMode =固定

现在,我们可以通过使用ItemSize属性更改大小,

ItemSize = 30,120 宽度= 30高度= 120

设置对齐=左侧后,按Tab键控制旋转标签引起的宽度和高度似乎被颠倒。这就是为什么当我们增加高度,我们看到,宽度增加,当我们增加宽度高度影响。

现在的文本也将被显示,但垂直。不幸的是没有解决这个问题的简单方法。为此,我们必须通过自己写的文字。要做到这一点,我们将首先设置DrawMode

DrawMode = OwnerDrawFixed

01

 私人小组TabControl1_DrawItem(BYVAL发件人为对象,BYVAL E上System.Windows.Forms.DrawItemEventArgs)处理TabControl1.DrawItem
    昏暗克作为图形
    昏暗STEXT作为字符串

    昏暗的iX作为整数
    昏暗IY作为整数
    昏暗sizeText作为的SizeF

    昏暗ctlTab作为TabControl的

    ctlTab = CTYPE(发件人的TabControl)

    G = e.Graphics

    STEXT = ctlTab.TabPages(e.Index)。文
    sizeText = g.MeasureString(STEXT,ctlTab.Font)

    的iX = e.Bounds.Left + 6
    IY = e.Bounds.Top +(e.Bounds.Height  -  sizeText.Height)/ 2

    g.DrawString(STEXT,ctlTab.Font,Brushes.Black,IX,IY)
结束小组
 

I would like to have the tabs on my TabControl displayed on the left, or sometimes right.
Unlike the System.Windows.Forms.TabControl, however, I would like the text to remain horizontal instead of being rotated by 90 or 270 degrees to the horizontal.

Here are a couple of pictures illustrating the concept

Though I could write code to do this myself in about an hour or two, I just thought I'd ask first if there is any existing Winforms control that implements such feature.

NB: Any existing solution should preferably be non-commercial.

Thanks.

解决方案

I don't know how robust this is and I can't claim to have created it but... http://www.dreamincode.net/forums/topic/125792-how-to-make-vertical-tabs/

Here's a way of doing it.

So first we are going to change its alignment to Left, by setting the property:

Alignment = Left

If you have XP themes turned on then you may notice the weird layout of Tab Control. Don't worry we will make it fine.

As you may have noticed that Tabs are vertical, and our requirement is horizontal. So we can change the size of Tabs. But before we can do this we have to set the SizeMode property as,

SizeMode = Fixed

Now we can change the size by using the ItemSize property,

ItemSize = 30, 120 Width = 30 and Height = 120

After setting the Alignment = Left, Tab control rotates the Tabs which causes the Width and Height seem to be reversed. That is why when we increase Height, we see that width is increasing and when we increase width the height is effected.

Now Text will also be displaying, but vertically. Unfortunately there is no simple way to resolve this issue. For this purpose we have to write the Text by ourselves. To do this we will first set the DrawMode

DrawMode = OwnerDrawFixed

01

Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem
    Dim g As Graphics
    Dim sText As String

    Dim iX As Integer
    Dim iY As Integer
    Dim sizeText As SizeF

    Dim ctlTab As TabControl

    ctlTab = CType(sender, TabControl)

    g = e.Graphics

    sText = ctlTab.TabPages(e.Index).Text
    sizeText = g.MeasureString(sText, ctlTab.Font)

    iX = e.Bounds.Left + 6
    iY = e.Bounds.Top + (e.Bounds.Height - sizeText.Height) / 2

    g.DrawString(sText, ctlTab.Font, Brushes.Black, iX, iY)
End Sub

这篇关于垂直选项卡控制与水平的WinForms文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆