해결하는데 꽤 오랜시간이 걸렸던 Panel fade out 기능 (페이드아웃 페이드인)
핵심 해결 방법 !
1. panel.BackColor = Color.FromArgb(a,b,c,d) 에서 a는 opacity 255일때가 불투명도가 높은 것, 0으로 갈수록 점점 투명해지는 기능
계속적으로 색깔을 바꾸고 싶을 경우에는 패널명.Refresh(); 를 꼭해줘야한다.
2. 시간에 흐름에 따라 색깔을 바꿔주었을 경우 버퍼링 현상이 생기는데
mainform에서 initializecomponent() 다음 줄에 fadeout하고자하는 패널명.SetDoubleBuffered(true);를 추가해줬다.
DateTime ThisMoment = DateTime.Now; // 현재 시간
TimeSpan duration = new TimeSpan(0, 0, 0, 0, 3000); // ms 시간 조정
DateTime AfterWards = ThisMoment.Add(duration);
int aa = 255;
loadingView.Visible = true;
//loadingView.Parent = this;
loadingView.BackColor = Color.FromArgb(128, 128, 255);
Console.WriteLine(loadingView.BackColor);
while (AfterWards >= ThisMoment)
{
ThisMoment = DateTime.Now; // 현재시간 update
aa -= 10;
if (aa >= 0)
{
loadingView.BackColor = Color.FromArgb(aa, 128, 128, 255); //alpha로 opacity 조정
loadingView.Refresh();
//Application.DoEvents();
Thread.Sleep(20);
//loadingView.Show();
//loadingView.BringToFront();
Console.WriteLine(loadingView.BackColor);
}
여기에서 loadingView.Refresh 와 Application.DoEvents(); 는 같은 역할을 수행한다.
https://stackoverflow.com/questions/52659358/changing-form-background-color-rapidly-randomly
Changing Form background color rapidly & randomly
I'm trying to write some code to quickly change the background of the form to random RGB colors, but the program seems to stop presumably until the loop is complete and then it changes color once. ...
stackoverflow.com
'Language > C#' 카테고리의 다른 글
C# loading (0) | 2022.02.16 |
---|---|
C# 다른 폼에서 다른 폼의 컨트롤 제어 (0) | 2022.02.16 |
Custom Scrollbar (0) | 2022.01.20 |
키보드 이벤트 순서 (0) | 2022.01.12 |
컨트롤 이벤트 PreviewKeydown vs Keydown (0) | 2022.01.12 |