반응형
c# -- ColorDialog 사용하기, label 글자 크기 변경하기
참고: https://docs.microsoft.com/ko-kr/dotnet/api/system.windows.forms.colordialog?view=netframework-4.7.2
https://www.c-sharpcorner.com/article/colordialog-in-C-Sharp/
https://www.dotnetperls.com/font
https://www.c-sharpcorner.com/uploadfile/mahesh/label-in-C-Sharp/
< 실행 결과 >
< 소스 >
--
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Drawing; | |
using System.Windows.Forms; | |
namespace color_dialog_test | |
{ | |
public partial class Form1 : Form | |
{ | |
private ColorDialog _colorDialog = new ColorDialog(); | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
//this.label1.Font = new Font(this.label1.Font.Name, 50); | |
using (Font fnt = new Font(this.label1.Font.Name, 30)) | |
{ | |
this.label1.Font = fnt; | |
} | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
if (_colorDialog.ShowDialog() == DialogResult.OK) | |
{ | |
Console.WriteLine($"selected foreground color = {_colorDialog.Color}"); | |
((Button)sender).BackColor = _colorDialog.Color; | |
this.label1.ForeColor = _colorDialog.Color; | |
} | |
} | |
private void button2_Click(object sender, EventArgs e) | |
{ | |
if (_colorDialog.ShowDialog() == DialogResult.OK) | |
{ | |
//Console.WriteLine($"selected foreground color = {_colorDialog.Color}"); | |
((Button)sender).BackColor = _colorDialog.Color; | |
this.label1.BackColor = _colorDialog.Color; | |
} | |
} | |
} | |
} |
반응형
'C#' 카테고리의 다른 글
c# -- 객체 이니셜라이저 (object initializer) (0) | 2019.03.27 |
---|---|
C# -- comboBox 이미지 item 그리기 (0) | 2019.03.26 |
C# -- property (속성) 사용법 (0) | 2019.03.16 |
C# -- GraphicsPath HitTest & PathTypes (0) | 2019.03.05 |
C# -- GraphicsPath.Flatten() 사용하기 (0) | 2019.02.23 |