기타 ETC/C#
C# 그라디언트 판넬 컨트롤 만들기
엘제이떠블유
2020. 3. 24. 13:31
C# 그라디언트 판넬 컨트롤 만들기 Gradient Panel in Windows form App
1. 폼을 만든다.
2. 클래스를 만들어서 다음과 같이 코딩한다.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Monitor0._2.UI_Forms
{
class GradientPanel : Panel
{
public Color ColorTop { get; set; }
public Color ColorBottom { get; set; }
protected override void OnPaint(PaintEventArgs e)
{
LinearGradientBrush lgb = new LinearGradientBrush(this.ClientRectangle, this.ColorTop, this.ColorBottom,90f);
Graphics g = e.Graphics;
g.FillRectangle(lgb, this.ClientRectangle);
base.OnPaint(e);
}
}
}
3 다시 빌드한다. (Rebuild)
4. 도구상자에 GradientPanel이 추가됐다. GradientPanel를 폼에 추가한다.
그리고 속성에서 ColorBottom, ColorTop를 아무 색깔이나 설정한다.