简体   繁体   English

如何绘制选项卡控件边框

[英]How to draw a tab control border

I have a custom tab control but I wish to remove the Left, bottom and right big border like the picture bellow, I dont know how these variable work and searching didnt give me anything related to it.我有一个自定义选项卡控件,但我希望删除左、下和右大边框,如下图所示,我不知道这些变量是如何工作的,搜索并没有给我任何与之相关的信息。 Sorry i just start to learn coding.对不起,我刚开始学习编码。

在此处输入图片说明

Here is the code, i tried to play around with it but it gave me weird borders all the time.这是代码,我尝试使用它,但它一直给我带来奇怪的边框。 Can you help me?你能帮助我吗? Or please tell me how does it work.或者请告诉我它是如何工作的。 Thank you!谢谢!

        public virtual void DrawBorder(Graphics g, Rectangle borderBounds)
        {
            if (Parent.SelectedIndex == -1)
            {
                using (Pen pen = new Pen(BorderColor))
                {
                    g.DrawRectangleFixed(pen, borderBounds);
                }
                return;
            }
            var tabBounds = Parent.GetTabBounds(Parent.SelectedTab);
            Point[] pt = new Point[8];
            if ((Parent.TabLocation & TabLocation.Top) != TabLocation.None)
            {
                pt[0] = borderBounds.GetBottomLeft().GetOffset(0, -1);
                pt[1] = borderBounds.GetBottomRight().GetOffset(-1, -1);
                pt[2] = borderBounds.GetTopRight().GetOffset(-1, 0);
                pt[3] = tabBounds.GetBottomRight().GetOffset(-1, -1);
                pt[4] = tabBounds.GetTopRight().GetOffset(-1, 0);
                pt[5] = tabBounds.GetTopLeft();
                pt[6] = tabBounds.GetBottomLeft().GetOffset(0, -1);
                pt[7] = borderBounds.GetTopLeft();
            }
            else if ((Parent.TabLocation & TabLocation.Bottom) != TabLocation.None)
            {
                pt[0] = borderBounds.GetBottomLeft().GetOffset(0, -1);
                pt[1] = tabBounds.GetTopLeft();
                pt[2] = tabBounds.GetBottomLeft().GetOffset(0, -1);
                pt[3] = tabBounds.GetBottomRight().GetOffset(-1, -1);
                pt[4] = tabBounds.GetTopRight().GetOffset(-1, 0);
                pt[5] = borderBounds.GetBottomRight().GetOffset(-1, -1);
                pt[6] = borderBounds.GetTopRight().GetOffset(-1, 0);
                pt[7] = borderBounds.GetTopLeft();
            }
            using (Pen pen = new Pen(BorderColor))
            {
                g.DrawPolygon(pen, pt);
            }
        }

I agree with others suggesting having a reproducible example makes helping easier.我同意其他人的建议,即拥有一个可重现的示例会使帮助更容易。 So please don't mind if I was doing the wrong guesses ...所以请不要介意我是否猜错了......

First, what is the point to leave away the outside borders of your tab control?首先,离开选项卡控件的外边框有什么意义? One of the UI purpose of a tab control is to group some and optically separate controls them from the rest of those in your UI.选项卡控件的 UI 目的之一是将一些控件分组并在视觉上将它们与 UI 中的其余控件分开。

Second, if you still like to do that, why are you (probably) creating your own TabControl subclass and take care of custom drawing at all?其次,如果您仍然喜欢这样做,为什么您(可能)要创建自己的 TabControl 子类并完全处理自定义绘图? You can archive this in the XAML code directly by using the TabControl BorderThickness property:您可以使用 TabControl BorderThickness 属性直接将其存档在 XAML 代码中:

<TabControl BorderThickness="0">
    <TabItem Header="Tab1">
        <TextBox Text="First Textbox"/>
    </TabItem>
    <TabItem Header="Tab2">
        <TextBox Text="Second Textbox"/>
    </TabItem>
</TabControl>

Finally, if you like to style any control rather than adding / changing its functionality, think about using XAML styling instead of creating a custom control.最后,如果您喜欢设置任何控件的样式而不是添加/更改其功能,请考虑使用 XAML 样式而不是创建自定义控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM