2014-08-31 2 views
-3

사각형이나 무언가를 화면에 그릴 때 문제가 있습니다. 이 코드에서는 좌표 x = 0 및 y = 화면 절반에 직사각형을 그릴 것으로 예상되지만 화면 중앙에 있지는 않습니다.C# draw 문제가 발생했습니다.

감사합니다.

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     private Graphics gr; 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void Form1_Paint(object sender, PaintEventArgs e) 
     { 
      gr = this.CreateGraphics(); 

      Pen p = new Pen(new SolidBrush(Color.Black),1); 

      gr.DrawRectangle(p, 0, this.Height/2 - 50, 100, 100); 
     } 
    } 
} 
+0

그래서 귀하의 질문은 ????? – Bas

답변

0

문제는

this.Height

반환 제목 표시 줄의 높이와 높이를 형성한다는 것이다. x = 0, y = 다음 좌표를 사용하여 직사각형을 그리려면 다음 코드를 사용하십시오.

protected void Form1_Paint(object sender, PaintEventArgs e) 
    { 
     gr = this.CreateGraphics(); 
     Pen p = new Pen(new SolidBrush(Color.Black), 1); 
     gr.DrawRectangle(p, 0, ClientRectangle.Height/2 - 50, 100, 100); 
    } 
+0

대단히 감사합니다! –

+0

질문을 닫으려면 정답으로 표시하는 것을 잊지 마십시오. – ntl