2014-09-04 167 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

編碼快樂!