How To Style Text In C#
In This C# Tutorial We Will See How To Change A Label Font Name, Size, Color, Style Using CSharp Programming Language
Part 1
Part 2
Source Code :
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 WindowsFormsApplication1
{
public partial class Text_Style : Form
{
public Text_Style()
{
InitializeComponent();
}
private void Text_Style_Load(object sender, EventArgs e)
{
foreach(FontFamily font in FontFamily.Families)
{
comboBox_Fonts.Items.Add(font.Name.ToString());
}
}
private void comboBox_Fonts_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
lbl_text.Font = new Font(comboBox_Fonts.Text, lbl_text.Font.Size);
}
catch { }
}
private void comboBox_SIZE_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
lbl_text.Font = new Font(lbl_text.Font.FontFamily, float.Parse(comboBox_SIZE.SelectedItem.ToString()));
}
catch
{
}
}
private void BTN_COLOR_Click(object sender, EventArgs e)
{
DialogResult colors = colorDialog1.ShowDialog();
if(colors == DialogResult.OK)
{
lbl_text.ForeColor = colorDialog1.Color;
}
}
private void RD_REGULAR_CheckedChanged(object sender, EventArgs e)
{
lbl_text.Font = new Font(lbl_text.Font.FontFamily, lbl_text.Font.Size, FontStyle.Regular);
}
private void RD_BOLD_CheckedChanged(object sender, EventArgs e)
{
lbl_text.Font = new Font(lbl_text.Font.FontFamily, lbl_text.Font.Size, FontStyle.Bold);
}
private void RD_UNDERLINE_CheckedChanged(object sender, EventArgs e)
{
lbl_text.Font = new Font(lbl_text.Font.FontFamily, lbl_text.Font.Size, FontStyle.Underline);
}
private void RD_STRIKEOUT_CheckedChanged(object sender, EventArgs e)
{
lbl_text.Font = new Font(lbl_text.Font.FontFamily, lbl_text.Font.Size, FontStyle.Strikeout);
}
}
}
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 WindowsFormsApplication1
{
public partial class Text_Style : Form
{
public Text_Style()
{
InitializeComponent();
}
private void Text_Style_Load(object sender, EventArgs e)
{
foreach(FontFamily font in FontFamily.Families)
{
comboBox_Fonts.Items.Add(font.Name.ToString());
}
}
private void comboBox_Fonts_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
lbl_text.Font = new Font(comboBox_Fonts.Text, lbl_text.Font.Size);
}
catch { }
}
private void comboBox_SIZE_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
lbl_text.Font = new Font(lbl_text.Font.FontFamily, float.Parse(comboBox_SIZE.SelectedItem.ToString()));
}
catch
{
}
}
private void BTN_COLOR_Click(object sender, EventArgs e)
{
DialogResult colors = colorDialog1.ShowDialog();
if(colors == DialogResult.OK)
{
lbl_text.ForeColor = colorDialog1.Color;
}
}
private void RD_REGULAR_CheckedChanged(object sender, EventArgs e)
{
lbl_text.Font = new Font(lbl_text.Font.FontFamily, lbl_text.Font.Size, FontStyle.Regular);
}
private void RD_BOLD_CheckedChanged(object sender, EventArgs e)
{
lbl_text.Font = new Font(lbl_text.Font.FontFamily, lbl_text.Font.Size, FontStyle.Bold);
}
private void RD_UNDERLINE_CheckedChanged(object sender, EventArgs e)
{
lbl_text.Font = new Font(lbl_text.Font.FontFamily, lbl_text.Font.Size, FontStyle.Underline);
}
private void RD_STRIKEOUT_CheckedChanged(object sender, EventArgs e)
{
lbl_text.Font = new Font(lbl_text.Font.FontFamily, lbl_text.Font.Size, FontStyle.Strikeout);
}
}
}
=> OutPut :
Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com
atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :