Jumat, 23 Agustus 2013

Font Dialog Box Control in Windows Forms

While working on windows-based application, you might have to change the font size, style or related to font. Just like MS-Word there should be a font dialog box to differentiate some text from common text in the file. This can be done using Font Dialog box shown in following image:


To add this box just drag-n-drop font dialog control from the toolbox. Add a textbox and a button on the form with text property “change font”. Button will used to show the font dialog box and then all the changes made in dialog box will appear in the text box.

By default a textbox has Microsoft Sans Serif as font, Regular as font style and 8 as font size. Now change these values as
  • Font = Monotype Corsiva
  • FontStyle = Bold
  • FontSize = 12
from the font dialog box and then click on ok button. We can see the text has been changed in our textbox as in following diagram.


Following code has to be written in the click event of button to perform these simple task:
private void changeFont_Click(object sender, EventArgs e)
{
fontDialog1.ShowDialog();
textBox1.Font = fontDialog1.Font;
}

FileDialogBox Control

Tidak ada komentar:

Posting Komentar