winform:竖的tab页

今日,公司一MM coder问我“竖的tab页怎么做呀,就像VS旁边的那个一样”

 

 

。。。。。。。。。

 

原以为是很EASY的问题试了一下,原来并不是一两个属性设置可用,还记得以前在MSDN上看过一遍有关系到的

 

。。。。。。。。

 

找了找,还是找到了,嘿嘿

直接把网址发给他,里面代码是vb.net

http://blogs.msdn.com/winformsue/archive/2006/03/14/551564.aspx

 

MM回了一句,看不懂,不明白是啥意思,要不,你帮我做吧!。。。。。。我又不是做界面的

 

其实挺不爽人家说偶是做界面的,好像偶做的就是很普通的一样,好像写模块的就很强的样子,不爽中,还是答应做了

 

切。。。。。偶也写一个“模块出来”

 

namespace TopWindow

{

    class UpLightTabControl : System.Windows.Forms.TabControl

    {

        public UpLightTabControl()

            : base()

        {

            this.Alignment = TabAlignment.Left;

            this.DrawMode = TabDrawMode.OwnerDrawFixed;

            this.SizeMode = TabSizeMode.FillToRight;

            this.ItemSize = new Size(96, 25);

        }

 

        protected override void OnDrawItem(DrawItemEventArgs e)

        {

 

            Graphics g = e.Graphics;

            Brush _TextBrush;

 

            // Get the item from the collection.

            TabPage _TabPage = this.TabPages[e.Index];

 

            // Get the real bounds for the tab rectangle.

            Rectangle _TabBounds = this.GetTabRect(e.Index);

 

            if ((e.State == DrawItemState.Selected))

            {

                // Draw a different background color, and don't paint a focus rectangle.

                _TextBrush = new SolidBrush(Color.Red);

                g.FillRectangle(Brushes.Gray, e.Bounds);

            }

            else

            {

                _TextBrush = new System.Drawing.SolidBrush(e.ForeColor);

                e.DrawBackground();

            }

 

            // Use our own font. Because we CAN.

            Font _TabFont = new Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Pixel);

 

            // Draw string. Center the text.

            StringFormat _StringFlags = new StringFormat();

            _StringFlags.Alignment = StringAlignment.Center;

            _StringFlags.LineAlignment = StringAlignment.Center;

            g.DrawString(_TabPage.Text, _TabFont, _TextBrush, _TabBounds, new StringFormat(_StringFlags));

 

            base.OnDrawItem(e);

        }

    }

}

 

下面是原作者的话,我想他说得很清楚了。

 

  1. On TabControl, set the following properties:
    1. .Alignment=Right
    2. .SizeMode=Fixed (Must be set to change ItemSize.Width, below)
    3. .DrawMode=OwnerDrawFixed
  2. Set the ItemSize property to the preferred width and height of your tabs. Since we're owner-drawing, we need the tabs to be a fixed width and height so we have a well-defined area in which to draw the tab labels.

    Here's one of the tricky bits, though: Width and height do not flip even though you are now right-aligned. In other words, you have to change the Width property to change the height (y axis) of the tabs, and change the Height property to change the width (x axis) of the tabs.
  3. Handle DrawItem() and define code to render the text the way you want it. Here's a sampling:

 

 

只是,为什么总感觉好像好多人把像我这样做UI界面工作的人,看得很轻呢。。。。。

并且,我一C++的同事就直接说:”别想我去碰那东西。。。。没前途的。。。。。‘

 

而我。。。

继续坚持着。。。。。

加油。。。。。

 

 


 

 


 

posted @ 2008-09-04 00:34  yellowyu  阅读(2854)  评论(5编辑  收藏  举报