2014-09-04 202 views
0

对不起,这个问题,但我一直在谷歌搜索“C#垂直菜单栏”了一段时间,我不能找到一个看起来是这样的: enter image description here垂直导航栏?

不,我不是做一个调查储物柜,但这是我能找到我要找的唯一图像。

谁能告诉我该怎么做呢?

+1

看起来像垂直标签。 WinForms或WPF? – 2014-09-04 02:04:20

+0

我已经编辑好标题。请参阅:“[应该在其标题中包含”标签“](http://meta.stackexchange.com/questions/19190/)”,其中的共识是“不,他们不应该”。 – 2014-09-04 02:04:35

+0

我正在使用WinForms。 – user3818701 2014-09-04 02:16:45

回答

0

假设WPF,只是扑通菜单那比其更广泛和添加菜单项

+0

我正在使用WinForms,现在是WPF。 – user3818701 2014-09-04 02:17:09

+0

然后使用像p.s.w.g这样的垂直标签。说过 – Steve 2014-09-04 02:21:24

1

可以创造自定义用户控件,从标签控件继承高。

对于Windows窗体,请按照下列步骤:

  1. 右键单击项目 - >添加新项 - >用户控制(C#)
  2. 从TabControl的继承和写下面的代码在默认构造 3覆盖的OnPaint方法手工设计选项卡控制
  3. 将它保存
  4. 将它添加到您的窗体从工具箱。
  5. 设置Dock属性为Fill和取向性,以左侧Control的
  6. 添加更多标签

希望这有助于!

class CustomControl : TabControl 
    { 
     public CustomControl() 
     { 
      SetStyle(ControlStyles.AllPaintingInWmPaint , true); 
      SetStyle(ControlStyles.OptimizedDoubleBuffer , true); 
      SetStyle(ControlStyles.ResizeRedraw, true); 
      SetStyle(ControlStyles.UserPaint, true); 

      DoubleBuffered = true; 
      SizeMode = TabSizeMode.Fixed; 
      ItemSize = new System.Drawing.Size(30, 120); 

     } 


     protected override void OnPaint(PaintEventArgs e) 
     { 
     var B = new Bitmap(Width, Height); 
     var G = (Graphics)Graphics.FromImage(B); 
     G.Clear(Color.Gainsboro); 

      for (int i = 0; i < TabCount -1; i++) 
      { 
      var TabRectangle = (Rectangle)GetTabRect(i); 

      if (i == SelectedIndex) 
      { 
       G.FillRectangle(Brushes.Navy, TabRectangle); 
      } 
      else 
      { 

       G.FillRectangle(Brushes.BlueViolet, TabRectangle); 


      } 
      G.DrawString(TabPages[i].Text, Font, Brushes.White, TabRectangle, new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }); 
      TabPages[i].Font = new Font(TabPages[i].Font, FontStyle.Strikeout); 

     } 

     e.Graphics.DrawImage((Image)B.Clone(),0,0); 
     G.Dispose(); 
     B.Dispose(); 

     base.OnPaint(e); 

     } 

enter image description here

enter image description here

编码快乐!