728x90
반응형
728x170
▶ MainForm.cs
using System.Drawing;
using System.Drawing.Text;
using System.Linq;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
#region 이벤트를 설정한다.
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)
{
e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
string headerList = "Title\tPrice\t# Pages\tYear";
string[] lineArray =
{
"WPF 3d\t$34.95\t430\t2018",
"The C# Helper Top 100\t$24.95\t380\t2017",
"Interview Puzzles Dissected\t$15.95\t300\t2016",
"C# 24-Hour Trainer, Second Edition\t$45.00\t600\t2015",
"Beginning Software Engineering\t$45.00\t480\t2015",
"Essential Algorithms\t$60.00\t624\t2013",
"Beginning Database Design Solutions\t$44.99\t552\t2008",
"Powers of Two\t$2.04\t8\t16",
};
using(StringFormat stringFormat = new StringFormat())
{
float[] tabArray = { 320, 75, 75 };
stringFormat.SetTabStops(0, tabArray);
float margin = 10;
float y = 10;
using(Font font = new Font("Times New Roman", 15, FontStyle.Bold))
{
e.Graphics.DrawString(headerList, font, Brushes.Blue, margin, y, stringFormat);
}
y += 1.4f * Font.Height;
e.Graphics.DrawLine(Pens.Blue, margin, y, margin + tabArray.Sum() + 50, y);
y += 5;
using(Font font = new Font("Times New Roman", 15))
{
foreach(string line in lineArray)
{
e.Graphics.DrawString(line, font, Brushes.Black, margin, y, stringFormat);
y += 1.2f * Font.Height;
}
}
}
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] Cursor 클래스 : 애니메이션 커서 사용하기 (0) | 2019.01.14 |
---|---|
[C#/WINFORM] ListView 클래스 : 커스텀 아이콘 사용하기 (0) | 2019.01.14 |
[C#/WINFORM] Cursor 클래스 : 사용자 정의 커서 사용하기 (0) | 2019.01.14 |
[C#/WINFORM] 사용자가 스크롤바 최대값을 선택할 수 있게 하기 (0) | 2019.01.14 |
[C#/WINFORM] StringFormat 클래스 : Alignment 속성을 사용해 문자열 정렬하기 (0) | 2019.01.14 |
[C#/WINFORM] PictureBox 클래스 : 버튼 모방하기 (0) | 2019.01.14 |
[C#/WINFORM] 극 좌표(Polar Coordinates)에서 곡선 그리기 (0) | 2019.01.14 |
[C#/WINFORM] RichTextBox 클래스 : 내용에 따라 크기 맞추기 (0) | 2019.01.14 |
[C#/WINFORM] TextBox 클래스 : 텍스트에 따라 크기 맞추기 (0) | 2019.01.14 |
[C#/WINFORM] 문단 그리기 (0) | 2019.01.14 |
댓글을 달아 주세요