2010-09-10 63 views
0

是否有可以打開或使用旋轉標籤90度的peramerter或設置?我想通過設計小組使用它。在Visual Studio中翻轉設計面板中的標籤

我想避免必須通過代碼,如果可能的話。

即時通訊目前使用C#作爲我的基地

+0

有許多不同的GUI技術可以在Visual Studio中進行佈局,其中大部分都包含一個'Label'控件。祈禱告訴你,你指的是? – Jay 2010-09-10 14:27:01

+0

我目前正在使用C#作爲我的基礎。 – 2010-09-10 14:41:11

+0

Jay的意思是你用什麼來創建GUI? WinForms,WPF,ASP.NET? – w69rdy 2010-09-10 14:46:40

回答

3

沒有物業旋轉文字90度。你需要編寫自己的控件。

2

爲您的項目添加一個新類並粘貼下面顯示的代碼。編譯。將新的控件從工具箱的頂部拖放到表單上。注意低於恆星的渲染質量和測量字符串長度的正常麻煩。

using System; 
using System.ComponentModel; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 

class VerticalLabel : Label { 
    private SizeF mSize; 
    public VerticalLabel() { 
     base.AutoSize = false; 
    } 
    [Browsable(false)] 
    public override bool AutoSize { 
     get { return false; } 
     set { base.AutoSize = false; } 
    } 
    public override string Text { 
     get { return base.Text; } 
     set { base.Text = value; calculateSize(); } 
    } 
    public override Font Font { 
     get { return base.Font; } 
     set { base.Font = value; calculateSize(); } 
    } 
    protected override void OnPaint(PaintEventArgs e) { 
     using (var br = new SolidBrush(this.ForeColor)) { 
      e.Graphics.RotateTransform(-90); 
      e.Graphics.DrawString(Text, Font, br, -mSize.Width, 0); 
     } 
    } 
    private void calculateSize() { 
     using (var gr = this.CreateGraphics()) { 
      mSize = gr.MeasureString(this.Text, this.Font); 
      this.Size = new Size((int)mSize.Height, (int)mSize.Width); 
     } 
    } 
}