728x90
반응형
728x170
■ PathGradientBrush 클래스를 사용하는 방법을 보여준다.
▶ MainForm.cs
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
ResizeRedraw = true;
#region 이벤트를 설정한다.
this.Paint += Form_Paint;
#endregion
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 폼 페인트시 처리하기 - Form_Paint(sender, e)
/// <summary>
/// 폼 페인트시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Paint(object sender, PaintEventArgs e)
{
int sideCount = 8;
PointF[] pointArray = new PointF[sideCount];
int centerX = (int)(ClientSize.Width / 2);
int centerY = (int)(ClientSize.Height / 2);
double theta = 0;
double dtheta = 2 * Math.PI / sideCount;
for(int i = 0; i < pointArray.Length; i++)
{
pointArray[i].X = (int)(centerX + centerX * Math.Cos(theta));
pointArray[i].Y = (int)(centerY + centerY * Math.Sin(theta));
theta += dtheta;
}
using(PathGradientBrush brush = new PathGradientBrush(pointArray))
{
brush.CenterColor = Color.White;
brush.SurroundColors = new Color[]
{
Color.Red,
Color.Yellow,
Color.Lime,
Color.Cyan,
Color.Blue,
Color.Magenta
};
e.Graphics.FillPolygon(brush, pointArray);
}
e.Graphics.DrawPolygon(Pens.Black, pointArray);
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] 원과 원의 교차 여부 구하기 (0) | 2018.12.09 |
---|---|
[C#/WINFORM] 직선과 원의 교차 여부 구하기 (0) | 2018.12.09 |
[C#/WINFORM] 타원 버튼 그리기 (0) | 2018.12.09 |
[C#/WINFORM] 피코버 별난 끌개 프랙탈(Pickover Strange Attractor Fractal) 그리기 (0) | 2018.12.09 |
[C#/WINFORM] Graphics 클래스 : TextRenderingHint 속성을 사용해 폰트 안티-알리아싱 설정하기 (0) | 2018.12.09 |
[C#/WINFORM] 비교차 스타 그리기 (0) | 2018.12.09 |
[C#/WINFORM] GroupBox 클래스 : 체크 그룹 박스 사용하기 (0) | 2018.12.09 |
[C#/WINFORM] ToolStripButton 클래스 : 라디오 버튼 사용하기 (0) | 2018.12.09 |
[C#/WINFORM] ListView 클래스 : 그룹 사용하기 (0) | 2018.12.08 |
[C#/WINFORM] 임의의 선으로 채워진 텍스트 그리기 (0) | 2018.12.08 |
댓글을 달아 주세요