본문 바로가기

c#

[c#, control] winform에서 control 깜빡임 방지 2가지 방법

1. SetStyle

1
2
3
4
5
6
7
8
        public Form1()
        {
            InitializeComponent();
 
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
            this.UpdateStyles();
 
        }
cs

 

1번 방법이 안될때.

 

2. CreateParam

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public Form1()
        {
            InitializeComponent();
 
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
            this.UpdateStyles();
 
        }
 
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x02000000;  // Turn on WS_EX_COMPOSITED
                return cp;
            }
        }
cs