[C# 윈폼] C# ProgressBar(프로그레스바) 색상 변경하기


안녕하세요.

 

오늘은 C# 윈폼에서 ProgressBar(프로그레스바) 컨트롤 게이지 색상 변경하는 방법에 대해서 알려 드리려고 합니다.

 

처음 프로그레스바 초기 색상은 Green 색상인데, 다른 컬러로 색상 변경하는 방법을 바로 알려드릴게요!


 

먼저, 아래와 같이 빈 윈폼 프로젝트를 생성해 주시기 바랍니다.


빈 윈폼 프로젝트 생성 및 컨트롤 배치



저는 위와 같이 ProgressBar 컨트롤 하나를 배치하였고, 컨트롤의 Name uiPgb_Main 이라고 명명 하였습니다.

 

그럼 이제 ProgressBar 컨트롤의 게이지 색상을 Green이 아닌 다른 색상으로 변경해 보겠습니다.


예제 코드


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

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 Test

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

 

            this.Load += Test_Load;

        }

 

        /// <summary>

        ///  Load 이벤트 핸들러

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        public void Test_Load(object sender, EventArgs e)

        {

            ProgressBarColorChange();

        }

 

        public void ProgressBarColorChange()

        {

            //ProgressBar 색상 변경

            uiPgb_Main.ForeColor = Color.Red;

            uiPgb_Main.Style = ProgressBarStyle.Continuous;

 

            uiPgb_Main.Maximum = 100;

            uiPgb_Main.Minimum = 0;

 

            uiPgb_Main.Value = 60;

        }

    }

}

 

Colored by Color Scripter

cs


Program.cs


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

using System;

using System.Collections.Generic;

using System.Linq;

using System.Threading.Tasks;

using System.Windows.Forms;

 

namespace Test

{

    static class Program

    {

        /// <summary>

        /// 해당 응용 프로그램의  진입점입니다.

        /// </summary>

        [STAThread]

        static void Main()

        {

            //Application.EnableVisualStyles();

            Application.SetCompatibleTextRenderingDefault(false);

            Application.Run(new Form1());

        }

    }

}

 

Colored by Color Scripter

cs


실행 결과



위와 같이 ProgressBar 게이지 색상이 Red로 변경된 것을 확인하실 수 있습니다.


여기서 중요한 것은 Program.cs 에서 Application.EnableVisualStyles(); 이 코드를 주석 처리해 주셔야 Color가 제대로 변경 되는 것을 확인하실 수 있습니다.

 

감사합니다.^^


728x90

이 글을 공유하기

댓글

Designed by JB FACTORY