2012-12-12 7 views
2

최근에 나는 win forms 응용 프로그램을위한 수직 진행 막대가 필요했습니다. 파생 된 클래스는 아래와 같습니다. 진행률 표시 줄에 텍스트를 추가해야합니다. 그것에 레이블은 transperancy 문제의 beacuse 작동하지 않습니다. 몇 가지 조사를 한 후에 뭔가를 발견했습니다. 그러나 문제는 진행률 표시 줄이 세로 인 경우 텍스트가 가로로 표시된다는 것입니다. 나는 그것도 수직으로 필요로한다. 어떻게해야합니까?.NET Winforms 세로 진행률 막대 텍스트

감사합니다.

public class VProgressBar : ProgressBar 
{ 
    protected override CreateParams CreateParams 
    { 
     get 
     { 
      CreateParams cp = base.CreateParams; 
      cp.Style |= 0x04; 

      if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 6) 
      { 
       cp.ExStyle |= 0x02000000; // WS_EX_COMPOSITED 
      } 

      return cp; 
     } 
    } 

    protected override void WndProc(ref Message m) 
    { 
     base.WndProc(ref m); 
     if (m.Msg == 0x000F) 
     { 
      using (Graphics graphics = CreateGraphics()) 
      using (SolidBrush brush = new SolidBrush(ForeColor)) 
      { 
       SizeF textSize = graphics.MeasureString(Text, Font); 
       graphics.DrawString(Text, Font, brush, (Width - textSize.Width)/2, (Height - textSize.Height)/2); 
      } 
     } 
    } 

    [EditorBrowsable(EditorBrowsableState.Always)] 
    [Browsable(true)] 
    public override string Text 
    { 
     get 
     { 
      return base.Text; 
     } 
     set 
     { 
      base.Text = value; 
      Refresh(); 
     } 
    } 

    [EditorBrowsable(EditorBrowsableState.Always)] 
    [Browsable(true)] 
    public override Font Font 
    { 
     get 
     { 
      return base.Font; 
     } 
     set 
     { 
      base.Font = value; 
      Refresh(); 
     } 
    } 
} 
+0

이 질문에 대한 이전 답변을 참조하십시오 - http://stackoverflow.com/questions/1371943/c-sharp-vertical-label-in-a-winform을 – ChrisF

답변

0

깃발을 사용하여 문자열을 세로로 그리려면 StringFormat을 사용해야합니다. 당신의 WndProc 방법으로 다음과 같은 시도 :

protected override void WndProc(ref Message m) 
    { 
     base.WndProc(ref m); 
     if (m.Msg == 0x000F) 
     { 
      using (Graphics graphics = CreateGraphics()) 
      using (SolidBrush brush = new SolidBrush(ForeColor)) 
      { 
       StringFormat format = new StringFormat(
         StringFormatFlags.DirectionVertical); 

       SizeF textSize = graphics.MeasureString(Text, Font); 
       graphics.DrawString(
        Text, Font, brush, 
        (Width/2 - textSize.Height/2), 
        (Height/2 - textSize.Width/2), 
        format); 
      } 
     } 
    } 
+0

감사 다니엘 , 효과가있었습니다. 나는 또한 텍스트를 아래에서 위로 보여주기 위해 graphics.RotateTransform (180)을 사용할 필요가 있었다. –