2016-09-23 1 views
-1

변수를 선택하면 화면에 스마일을 그려주는 프로그램을 작성하려고합니다.다른 방법에 대한 ReadLine 입력 사용

다음 내용을 작성했습니다.

내 프로그램에서 세 가지 질문을합니다.이 질문은 0에서 11 사이의 숫자로 대답 할 것입니다.이 대답은 'tekenscherm'메서드에서 사용하고 싶습니다. 어떻게이 메소드에서 이러한 변수를 호출 할 수 있습니까?

class HalloForm : Form 
{ 
    public string a,b,c = ""; //Declare them here. 
    public HalloForm() 
    { 
     this.Text = "Hallo"; 
     this.BackColor = Color.Yellow; 
     this.Size = new Size(800, 600); 
     this.Paint += this.tekenScherm; 
    } 

    public static void Main() 
    { 
     System.Console.WriteLine("Smiley size, on a scale of 1 tot 10?"); 
     string a = System.Console.ReadLine(); 
     Int32.Parse(a); 
     System.Console.WriteLine("X coordinate of the smiley, on a scale of 1 to 10"); 
     string b = System.Console.ReadLine(); 
     Int32.Parse(b); 
     System.Console.WriteLine("Y coordinate of the smiley, on a scale of 1 to 10"); 
     string c = System.Console.ReadLine(); 
     Int32.Parse(c); 
     HalloForm scherm; 
     scherm = new HalloForm(); 

     Application.Run(scherm); 
    } 
    void tekenScherm(object obj, PaintEventArgs pea) 
    { 

     SolidBrush blueBrush = new SolidBrush(Color.Blue); 
     Pen blackBrush = new Pen(Color.Black, 5); 
     int x = 360; 
     int y = x + 75; 
     pea.Graphics.FillEllipse(blueBrush, 300, 200, 200, 200); 
     pea.Graphics.DrawEllipse(blackBrush, 300, 200, 200, 200); 
     pea.Graphics.DrawArc(blackBrush, 350, 250, 100, 100, 45, 90); 
     pea.Graphics.DrawEllipse(blackBrush, a, 250, 5, 5); //I've used it here 
     pea.Graphics.DrawEllipse(blackBrush, y, 250, 5, 5); 
    } 
} 
+1

그것은 (: drawScreen 영어로 경우 tekenScherm에서) 모든 변수/함수 이름의 이름을 지정하는 것이 좋습니다입니다 : 여기

는 작업 코드입니다. –

+0

이것은 주로 영어로 말하는 웹 사이트입니다. 도움이 필요하면 영어로 모든 것을 작성하는 것이 좋습니다. 다른 언어를 보게되는 순간 나는 독서를 그만 둔다. – Krythic

답변

0

메서드 범위 외부의 변수를 정수로 선언하십시오.

Int32.Parse은 이러한 변수에 할당하지 않은 정수 값을 반환하므로 기본적으로 아무 것도 사용하지 않습니다.

class HalloForm : Form 
{ 
    public int a, b, c = 0; //Declare them here. 
    public HalloForm() 
    { 
     this.Text = "Hallo"; 
     this.BackColor = Color.Yellow; 
     this.Size = new Size(800, 600); 
     this.Paint += this.tekenScherm; 
    } 

    public static void Main() 
    { 
     System.Console.WriteLine("Smiley size, on a scale of 1 tot 10?"); 
     a = Int32.Parse(System.Console.ReadLine()); 
     System.Console.WriteLine("X coordinate of the smiley, on a scale of 1 to 10"); 
     b = Int32.Parse(System.Console.ReadLine()); 
     System.Console.WriteLine("Y coordinate of the smiley, on a scale of 1 to 10"); 
     c = Int32.Parse(System.Console.ReadLine()); 
     HalloForm scherm; 
     scherm = new HalloForm(); 

     Application.Run(scherm); 
    } 
    void tekenScherm(object obj, PaintEventArgs pea) 
    { 

     SolidBrush blueBrush = new SolidBrush(Color.Blue); 
     Pen blackBrush = new Pen(Color.Black, 5); 
     int x = 360; 
     int y = x + 75; 
     pea.Graphics.FillEllipse(blueBrush, 300, 200, 200, 200); 
     pea.Graphics.DrawEllipse(blackBrush, 300, 200, 200, 200); 
     pea.Graphics.DrawArc(blackBrush, 350, 250, 100, 100, 45, 90); 
     pea.Graphics.DrawEllipse(blackBrush, x, 250, 5, 5); 
     pea.Graphics.DrawEllipse(blackBrush, y, 250, 5, 5); 
    } 
} 
+0

하지만 'a'를 어떻게 사용할 수 있습니까 (예 : pea.Graphics.DrawEllipse (blackBrush, a, 200, 200, 200); ? – Whizkid95

+0

예, 해당 클래스의 모든 메소드에서 사용할 수 있습니다. – ThePerplexedOne

+0

코드를 사용하여 원래 게시물을 편집했습니다. 그러나 그것은 나를 위해 작동하지 않습니다. tekenScherm 메서드에서 'a'를 선언해야합니까? – Whizkid95

관련 문제