2017-01-04 1 views
1

Windows CE .NET 2.0 C# 응용 프로그램에 대한 사용자 지정 진행률 표시 줄 컨트롤을 만들고 있습니다. 아래는 유일한 것은 누락 된 나는 누군가가 위의 코드 진행 사각형에서 RTL 속성을오른쪽 아래에서 레이아웃 속성

Code Refering

using System; 
using System.Drawing; 
using System.Windows.Forms; 
class CustomProgressBar:UserControl 
{ 
    int min = 0; // Minimum value for progress range 
    int max = 100; // Maximum value for progress range 
    int val = 0;  // Current progress 
    Color BarColor = Color.Blue;  // Color of progress meter 
    protected override void OnResize(EventArgs e) 
    { 
     // Invalidate the control to get a repaint. 
     this.Invalidate(); 
    } 
    protected override void OnPaint(PaintEventArgs e) 
    { 
     Graphics g = e.Graphics; 
     SolidBrush brush = new SolidBrush(BarColor); 
     float percent = (float)(val - min)/(float)(max - min); 
     Rectangle rect = this.ClientRectangle; 

     // Calculate area for drawing the progress. 
     rect.Width = (int)((float)rect.Width * percent); 

     // Draw the progress meter. 
     g.FillRectangle(brush, rect); 

     // Draw a three-dimensional border around the control. 
     Draw3DBorder(g); 

     // Clean up. 
     brush.Dispose(); 
     g.Dispose(); 
    } 

    public int Minimum 
    { 
     get 
     { 
      return min; 
     } 

     set 
     { 
      // Prevent a negative value. 
      if (value < 0) 
      { 
       min = 0; 
      } 

      // Make sure that the minimum value is never set higher than the maximum value. 
      if (value > max) 
      { 
       min = value; 
       min = value; 
      } 

      // Ensure value is still in range 
      if (val < min) 
      { 
       val = min; 
      } 

      // Invalidate the control to get a repaint. 
      this.Invalidate(); 
     } 
    } 

    public int Maximum 
    { 
     get 
     { 
      return max; 
     } 

     set 
     { 
      // Make sure that the maximum value is never set lower than the minimum value. 
      if (value < min) 
      { 
       min = value; 
      } 

      max = value; 

      // Make sure that value is still in range. 
      if (val > max) 
      { 
       val = max; 
      } 

      // Invalidate the control to get a repaint. 
      this.Invalidate(); 
     } 
    } 

    public int Value 
    { 
     get 
     { 
      return val; 
     } 

     set 
     { 
      int oldValue = val; 

      // Make sure that the value does not stray outside the valid range. 
      if (value < min) 
      { 
       val = min; 
      } 
      else if (value > max) 
      { 
       val = max; 
      } 
      else 
      { 
       val = value; 
      } 

      // Invalidate only the changed area. 
      float percent; 

      Rectangle newValueRect = this.ClientRectangle; 
      Rectangle oldValueRect = this.ClientRectangle; 

      // Use a new value to calculate the rectangle for progress. 
      percent = (float)(val - min)/(float)(max - min); 
      newValueRect.Width = (int)((float)newValueRect.Width * percent); 

      // Use an old value to calculate the rectangle for progress. 
      percent = (float)(oldValue - min)/(float)(max - min); 
      oldValueRect.Width = (int)((float)oldValueRect.Width * percent); 

      Rectangle updateRect = new Rectangle(); 

      // Find only the part of the screen that must be updated. 
      if (newValueRect.Width > oldValueRect.Width) 
      { 
       updateRect.X = oldValueRect.Size.Width; 
       updateRect.Width = newValueRect.Width - oldValueRect.Width; 
      } 
      else 
      { 
       updateRect.X = newValueRect.Size.Width; 
       updateRect.Width = oldValueRect.Width - newValueRect.Width; 
      } 

      updateRect.Height = this.Height; 

      // Invalidate the intersection region only. 
      this.Invalidate(updateRect); 
     } 
    } 

    public Color ProgressBarColor 
    { 
     get 
     { 
      return BarColor; 
     } 

     set 
     { 
      BarColor = value; 

      // Invalidate the control to get a repaint. 
      this.Invalidate(); 
     } 
    } 

    private void Draw3DBorder(Graphics g) 
    { 
     int PenWidth = (int)Pens.White.Width; 

     g.DrawLine(Pens.DarkGray, 
      new Point(this.ClientRectangle.Left, this.ClientRectangle.Top), 
      new Point(this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Top)); 
     g.DrawLine(Pens.DarkGray, 
      new Point(this.ClientRectangle.Left, this.ClientRectangle.Top), 
      new Point(this.ClientRectangle.Left, this.ClientRectangle.Height - PenWidth)); 
     g.DrawLine(Pens.White, 
      new Point(this.ClientRectangle.Left, this.ClientRectangle.Height - PenWidth), 
      new Point(this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Height - PenWidth)); 
     g.DrawLine(Pens.White, 
      new Point(this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Top), 
      new Point(this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Height - PenWidth)); 
    } 
} 
+0

MAX에서 시작하여 MIN으로 진행하십시오. – JohnG

+0

내 코드를 수정할 위치 –

+0

코드를 보지 못했기 때문에 "사용자"코드를 수정할 위치를 모른다. 나는 단순히 왼쪽 (MIN)에서 오른쪽 (MAX)으로 진행하는 대신 오른쪽 (MAX)에서 왼쪽 (MIN)으로 진행한다는 것을 의미했습니다. 진행 상황이 업데이트 될 때 코드 컨트롤을 가정하면 현재 값을 줄이기 위해 코드를 조정하기 만하면됩니다. 게시 한 코드는 MS 지원 사이트에 대한 링크 일뿐입니다. 사람들이 도울 수 있기 전에 시도한 것을 보여줄 필요가 있습니다. 다음을보십시오 ... [최소, 완전하며 검증 가능한 예제를 만드는 방법] – JohnG

답변

1

를 얻기 위해이 코드를 수정하는 나를 도울 수 오른쪽에서 왼쪽으로 진행 상황을 보여주고 싶어한다 잘 작동 코드입니다

float percent = (float)(val - min)/(float)(max - min); 
Rectangle rect = this.ClientRectangle; 
rect.Width = (int)((float)rect.Width * percent); 

당신은 단순히 코드 아래에 코드를 변경할 수있는 컨트롤의 오른쪽에서 진행 사각형 채우기 위해 :

을이 방법으로 만든
float percent = (float)(val - min)/(float)(max - min); 
Rectangle rect = this.ClientRectangle; 
var w = (int)((float)rect.Width * percent); 
rect.X = rect.Width - w; 
rect.Width = w; 
+0

** 참고 1 : ** LTR 좌표를 RTL로 변환하는 일반적인 솔루션 , 당신은 [이 게시물] (http://stackoverflow.com/a/34509304/3110834)에서'GetRTLCoordinates'를 사용할 수 있습니다. –

+0

** 주 2 : ** 거울 드로잉에 대한 또 다른 일반적인 해결책으로, 변환 매트릭스를 'e.Graphics.Transform = new Matrix (-1, 0, 0, 1, Width, 0);'및 ' 그리기를 수행 한 다음 'e.Graphics.ResetTransform();'을 사용하여 변환을 재설정합니다. –

+0

protected override void OnPaint (PaintEventArgs e) {Graphics g = e.Graphics; SolidBrush 브러시 = 새 SolidBrush (BarColor); float percent = (float) (val - min)/(float) (max - min); 사각형 rect = this.ClientRectangle; var w = (int) ((float) rect.Width * percent); rect.X = rect.Width - w; rect.Width = w; g.FillRectangle (brush, rect); Draw3DBorder (g); brush.Dispose(); g.Dispose(); } 통고가 일어난다 그 밖의 무엇을해야합니까? –

관련 문제