본문 바로가기

C#

[질답] C# PictureBox Drawing 제어

반응형
지금 실행되는건 button1을 누를 때 마다 원이 생성됩니다. 여기서 button2와 button3 클릭으로
button2는 picturebox1 안의 원을 초기화시키는 기능을하고 button3는 초기화시켰던 기능을 해제하는
역할을 하게 하려면 어떤 문장을 써야 하나요?


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 Form1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            X_LOCATION = 10;// X열의 처음 시작하는 위치 값
        }
        public int X_LOCATION
        {
            get;
            private set;
        }
        private void button1_MouseClick(object sender, MouseEventArgs e)
        {         
            Graphics g = pictureBox1.CreateGraphics();// 픽쳐박스에 그림을 그리게 합니다.
            Pen blackpen = new Pen(Color.Black, 5);// 검은색 팬 5굵기로 그립니다.
            Rectangle rect = new Rectangle(X_LOCATION, 10, 5, 5);// 직사각형의 좌표(x,y)와 가로세로 길이를 설정
            g.DrawEllipse(blackpen, rect);// 원을그리게 하고 검은색팬과 좌표및 길이를 조정하는 값을 적용시킨다.
            g.Dispose();// 응용프로그램의 정의작업 수행
            X_LOCATION += 10 + 5;// 원 생성시 값의 크기로 간격조절
        }
        private void button2_MouseClick(object sender, MouseEventArgs e)
        {
          
        }
    }
}





button2 는 초기화 시키는것이고


button3는 초기화시켰던 기능을 해제
 = button2 가 동작하지 않도록 제어하라는건가요??
아래와 같이 해보세요.
도움되시길 바랍니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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 bool ActionForceJudge = false;
 
        public int X_LOCATION
        {
            get;
            private set;
        }
 
        public Form1()
        {
            InitializeComponent();
            X_LOCATION = 10;// X열의 처음 시작하는 위치 값
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
 
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            Graphics g = pictureBox1.CreateGraphics();// 픽쳐박스에 그림을 그리게 합니다.
            Pen blackpen = new Pen(Color.Black, 5);// 검은색 팬 5굵기로 그립니다.
            Rectangle rect = new Rectangle(X_LOCATION, 1055);// 직사각형의 좌표(x,y)와 가로세로 길이를 설정
            g.DrawEllipse(blackpen, rect);// 원을그리게 하고 검은색팬과 좌표및 길이를 조정하는 값을 적용시킨다.
            g.Dispose();// 응용프로그램의 정의작업 수행
            X_LOCATION += 10 + 5;// 원 생성시 값의 크기로 간격조절
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            if (ActionForceJudge)
            { pictureBox1.Image = null; }
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
            ActionForceJudge = true;
        }
    }
}
 
cs


소스는 전체를 첨부해둡니다.
아래를 참고하세요.


반응형