如何突出/灰了自定义的Tabcontrol TabPage的 [英] How to highlight/grey-out Tabcontrol Tabpage

查看:209
本文介绍了如何突出/灰了自定义的Tabcontrol TabPage的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对其中只有某些选项卡是可选的基于用户的选择提出申请。
我如何可以在Windows窗体应用程序灰掉那些不可选择的选项卡(S)。

I have an application on which only certain Tabs are selectable based on choices user make. How can I can grey-out those unselectable tab(s) on a windows forms application.

推荐答案

要灰出来我猜你必须所有者绘制的选项卡。

To grey them out I guess you'll have to owner-draw the tabs.

enabled属性不能很好的支持;你可以看到,由它的甚至没有被列入智能感知。您可以仍然应该设置它,但它只能绘制背景灰色的,也不会是绘制标签,也不会从选择标签禁用任何控制或prevent用户。 (不知道这是这么好的UI设计anyway..You可能要至少设置一个工具提示解释了为什么网页无法访问,或者你让它被选中并禁用它所有控件递归..或者你请你做; - )

The Enabled property is not well supported; you can see that by its not even being included in Intellisense. You can and should still set it but it will only paint the Background grey, neither will it paint the Tabs nor will it disable any controls or prevent the user from selecting the tab. (Not sure if that's such a good UI design anyway..You may want to set at least a toolTip to explain why the page can't be accessed. Or you let it be selected and disable all controls on it recursively.. Or you do as you please ;-)

为了让他们无法选择简单地把这个到 tabControl1_Selecting 事件:

To make them unselectable simply put this into the tabControl1_Selecting event:

if (!e.TabPage.Enabled)  e.Cancel = true;

要在的OwnerDraw设定标签 DrawMode 来如 OwnerDrawFixed 把一些画code这样到 DRAWITEM 事件:

To ownerdraw the Tabs set DrawMode to e.g. OwnerDrawFixed put some painting code like this into the DrawItem event:

private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
    TabPage tp = tabControl1.TabPages[e.Index];
   using (SolidBrush brush = 
          new SolidBrush(tp.Enabled ? tp.BackColor : SystemColors.ControlLight))
   using (SolidBrush textBrush = 
          new SolidBrush(tp.Enabled ? tp.ForeColor : SystemColors.ControlDark))
    {
       e.Graphics.FillRectangle(brush, e.Bounds);
       e.Graphics.DrawString(tp.Text, e.Font, textBrush, e.Bounds.X + 3, e.Bounds.Y + 4);
    }
}

我决定也画主动标签在其页面的颜色,因为我觉得是应该的;你可以改变第一画笔颜色为 tabControl1.BackColor ,如果你想。
我选择了将SystemColor不一定是最好的,但你的想法,我希望..

I have decided to also paint the active Tabs in the color of their pages, as I feel it should be; you can change the 1st brush color to tabControl1.BackColor, if you want to. The Systemcolors I chose may not always be the best, but you get the idea, I hope..

这篇关于如何突出/灰了自定义的Tabcontrol TabPage的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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