728x90
반응형
Pen vs Pens
Pen → 생성
Pens → 기본 제공 펜
Pen 생성자
Pen(Brush), Pen(Color)
Pen(Brush, Single), Pen(Color, Single)
Pen 해제
Dispose()
Pen과 Pens 사용 예
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Color myColor = Color.FromArgb(255, 0, 0);
Pen newPen = new Pen(myColor);
newPen.Width = 5.0f; // new Pen(myColor, 5.0f);
e.Graphics.DrawLine(newPen, 10, 10, 100, 10);
e.Graphics.DrawLine(Pens.Blue, 10, 20, 100, 20);
newPen.Dispose();
}
}
}
펜 스타일
- DashStyle 속성 사용
public System.Drawing.Drawing2D.DashStyle DashStyle { get; set; }
using System.Drawing.Drawing2D 선언
- DashStyle 열거형 리턴
Custom
Dash
DashDot
DashDotDot
Dot
Solid
- DashDot와 Dot 선 스타일 지정, 너비 3으로 설정
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Pen myPen = new Pen(Color.Black, 3.0f);
myPen.DashStyle = DashStyle.DashDot;
e.Graphics.DrawLine(myPen, 10, 10, 200, 10);
myPen.DashStyle = DashStyle.Dot;
e.Graphics.DrawLine(myPen, 10, 20, 200, 20);
}
}
}
728x90
반응형
'C# > C#으로 살아남기_나우캠퍼스_이태성강사' 카테고리의 다른 글
[C# Winform 9강] 이미지, 비트맵 (0) | 2022.02.11 |
---|---|
[C# Winform 8강] GDI+ Brush (0) | 2022.02.10 |
[C# Winform 6강] GDI+ Color (0) | 2022.02.10 |
[C# Winform 5강] GDI+ Graphics (0) | 2022.02.09 |
[C# Winform 4강] 마우스 (0) | 2022.01.10 |