728x90
728x170
▶ MainForm.cs
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 그래픽스 경로 1
/// </summary>
private GraphicsPath graphicsPath1;
/// <summary>
/// 그래픽스 경로 2
/// </summary>
private GraphicsPath graphicsPath2;
/// <summary>
/// 영역 2
/// </summary>
private Region region2;
/// <summary>
/// 사각형 3
/// </summary>
private Rectangle rectangle3;
/// <summary>
/// 그래픽스 경로 1 내부 위치 여부
/// </summary>
private bool inGraphicsPath1 = false;
/// <summary>
/// 영역 2 내부 위치 여부
/// </summary>
private bool inRegion2 = false;
/// <summary>
/// 사각형 3 내부 위치 여부
/// </summary>
private bool inRectangle3 = false;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
this.graphicsPath1 = new GraphicsPath();
this.graphicsPath1.AddLine(50 , 50 , 170, 50 );
this.graphicsPath1.AddLine(170, 50 , 170, 140);
this.graphicsPath1.AddLine(170, 140, 50 , 170);
this.graphicsPath1.CloseFigure();
this.graphicsPath2 = new GraphicsPath();
this.graphicsPath2.AddLine(200, 50 , 380, 50 );
this.graphicsPath2.AddLine(380, 50 , 380, 140);
this.graphicsPath2.AddLine(380, 140, 470, 140);
this.graphicsPath2.AddLine(470, 140, 470, 200);
this.graphicsPath2.AddLine(470, 200, 320, 200);
this.graphicsPath2.AddLine(320, 200, 320, 140);
this.graphicsPath2.AddLine(320, 140, 200, 140);
this.graphicsPath2.CloseFigure();
this.region2 = new Region(graphicsPath2);
this.rectangle3 = new Rectangle(50, 290, 260, 200);
MouseMove += Form_MouseMove;
Paint += Form_Paint;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 폼 마우스 이동시 처리하기 - Form_MouseMove(sender, e)
/// <summary>
/// 폼 마우스 이동시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_MouseMove(object sender, MouseEventArgs e)
{
Graphics graphics = CreateGraphics();
try
{
if(this.inGraphicsPath1)
{
if(!this.graphicsPath1.IsVisible(e.X, e.Y))
{
graphics.FillPath(Brushes.White, this.graphicsPath1);
graphics.DrawPath(Pens.Black, this.graphicsPath1);
this.inGraphicsPath1 = false;
return;
}
}
else
{
if(this.graphicsPath1.IsVisible(e.X, e.Y))
{
graphics.FillPath(Brushes.LightBlue, this.graphicsPath1);
graphics.DrawPath(Pens.Black, this.graphicsPath1);
this.inGraphicsPath1 = true;
return;
}
}
if(this.inRegion2)
{
if(!this.region2.IsVisible(e.X, e.Y))
{
graphics.FillRegion(Brushes.White, this.region2);
graphics.DrawPath(Pens.Black, this.graphicsPath2);
this.inRegion2 = false;
return;
}
}
else
{
if(this.region2.IsVisible(e.X, e.Y))
{
graphics.FillRegion(Brushes.Pink, this.region2);
graphics.DrawPath(Pens.Black, this.graphicsPath2);
this.inRegion2 = true;
return;
}
}
if(this.inRectangle3)
{
if(!this.rectangle3.Contains(e.X, e.Y))
{
graphics.FillRectangle(Brushes.White, this.rectangle3);
graphics.DrawRectangle(Pens.Black, this.rectangle3);
this.inRectangle3 = false;
return;
}
}
else
{
if(this.rectangle3.Contains(e.X, e.Y))
{
graphics.FillRectangle(Brushes.LightGreen, this.rectangle3);
graphics.DrawRectangle(Pens.Black, this.rectangle3);
this.inRectangle3 = true;
return;
}
}
}
finally
{
graphics.Dispose();
}
}
#endregion
#region 폼 페인트시 처리하기 - Form_Paint(sender, e)
/// <summary>
/// 폼 페인트시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Paint(object sender, PaintEventArgs e)
{
Graphics graphics = e.Graphics;
graphics.FillRectangle(Brushes.White, ClientRectangle);
graphics.DrawPath(Pens.Black, graphicsPath1);
graphics.DrawPath(Pens.Black, graphicsPath2);
graphics.DrawRectangle(Pens.Black, rectangle3);
}
#endregion
}
}
728x90
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM/.NET5] WaveOutEvent 클래스 : 오디오 파일 재생하기 (기능 개선) (0) | 2021.12.26 |
---|---|
[C#/WINFORM/.NET5] WaveOutEvent 클래스 : 오디오 파일 재생하기 (0) | 2021.12.26 |
[C#/WINFORM/.NET5] 마이크 입력 스펙트로그램 표시하기 (0) | 2021.12.18 |
[C#/WINFORM] 사운드 필터링 사용하기 (0) | 2021.12.09 |
[C#/WINFORM] NativeWindow 클래스 : 마우스 캡처 변경시 이벤트 전달하기 (0) | 2021.12.06 |
[C#/WINFORM] 특정 영역에서 마우스 커서 설정하기 (0) | 2021.12.06 |
[C#/WINFORM] 마우스 드래그 대상 이미지 표시하기 (0) | 2021.12.06 |
[C#/WINFORM] 카카오 링크를 사용해 나에게 카카오톡 메시지 보내기 (기능 개선) (0) | 2021.11.24 |
[C#/WINFORM] 누겟 설치 : CefSharp.WinForms (0) | 2021.11.23 |
[C#/WINFORM] 누겟 설치 : CefSharp.Common (0) | 2021.11.23 |