728x90
반응형
728x170
▶ MainForm.cs
using System;
using System.Collections.Generic;
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();
Load += Form_Load;
Paint += Form_Paint;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 폼 로드시 처리하기 - Form_Load(sender, e)
/// <summary>
/// 폼 로드시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Load(object sender, EventArgs e)
{
ResizeRedraw = true;
}
#endregion
#region 폼 페인트시 처리하기 - Form_Paint(sender, e)
/// <summary>
/// 폼 페인트시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Paint(object sender, PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
float centerX = ClientRectangle.Width / 2f;
float centerY = ClientRectangle.Height / 2f;
float radiusX = Math.Min(centerX, centerY) - 10;
float radiusY = radiusX;
DrawCircle
(
e.Graphics,
Pens.Blue,
Pens.Orange,
centerX,
centerY,
radiusX,
radiusY,
100,
12,
0.1f
);
radiusX *= 0.8f;
radiusY *= 0.6f;
DrawCircle
(
e.Graphics,
Pens.Red,
Pens.Black,
centerX,
centerY,
radiusX,
radiusY,
16,
16,
0.1f
);
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 원 그리기 - DrawCircle(graphics, circlePen, tickPen, centerX, centerY, radiusX, radiusY, thetaCount, tickCount, tickFraction)
/// <summary>
/// 원 그리기
/// </summary>
/// <param name="graphics">그래픽스</param>
/// <param name="circlePen">원 펜</param>
/// <param name="tickPen">틱 펜</param>
/// <param name="centerX">중심 X</param>
/// <param name="centerY">중심 Y</param>
/// <param name="radiusX">반경 X</param>
/// <param name="radiusY">반경 Y</param>
/// <param name="thetaCount">세타 카운트</param>
/// <param name="tickCount">틱 카운트</param>
/// <param name="tickFraction">틱 조각</param>
private void DrawCircle
(
Graphics graphics,
Pen circlePen,
Pen tickPen,
float centerX,
float centerY,
float radiusX,
float radiusY,
float thetaCount,
float tickCount,
float tickFraction
)
{
List<PointF> pointList = new List<PointF>();
float deltaTheta = (float)(2 * Math.PI / thetaCount);
float theta = 0;
for(int i = 0; i < thetaCount; i++)
{
float x = (float)(centerX + radiusX * Math.Cos(theta));
float y = (float)(centerY + radiusY * Math.Sin(theta));
pointList.Add(new PointF(x, y));
theta += deltaTheta;
}
graphics.DrawPolygon(circlePen, pointList.ToArray());
deltaTheta = (float)(2 * Math.PI / tickCount);
theta = 0;
float temporaryX = radiusX * (1 - tickFraction);
float temporaryT = radiusY * (1 - tickFraction);
for(int i = 0; i < tickCount; i++)
{
float x1 = (float)(centerX + radiusX * Math.Cos(theta));
float y1 = (float)(centerY + radiusY * Math.Sin(theta));
float x2 = (float)(centerX + temporaryX * Math.Cos(theta));
float y2 = (float)(centerY + temporaryT * Math.Sin(theta));
graphics.DrawLine(tickPen, x1, y1, x2, y2);
theta += deltaTheta;
}
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] 호(arc) 그리기/이동하기/수정하기 (0) | 2020.07.12 |
---|---|
[C#/WINFORM] 호(arc) 위의 마우스 위치 여부 구하기 (0) | 2020.07.12 |
[C#/WINFORM] 안티-알리아싱으로 그리는 경우 투명도 사용하기 (0) | 2020.07.11 |
[C#/WINFORM] 이미지 나선 그리기 (0) | 2020.07.10 |
[C#/WINFORM] Graphics 클래스 : DrawCurve 메소드를 사용해 곡선 그리기 (0) | 2020.07.09 |
[C#/WINFORM] Bitmap 클래스 : 투명한 구멍을 갖는 비트맵 만들기 (0) | 2020.07.05 |
[C#/WINFORM] PictureBox 클래스 : 사용자 그리기 및 확대/축소하기 (0) | 2020.07.05 |
[C#/WINFORM] PictureBox 클래스 : 사용자 선 그리기 (0) | 2020.07.05 |
[C#/WINFORM] CommonOpenFileDialog 클래스 : 표준 윈도우즈 대화 상자를 사용해 폴더 선택하기 (0) | 2020.07.05 |
[C#/WINFORM] ListView 클래스 : 항목 인덱스 구하기 (0) | 2020.06.08 |
댓글을 달아 주세요