반응형

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/





< 실행 결과 >





< 소스 >

--

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;
}
}
}
}



반응형
Posted by 자유프로그램
,