Color and Font Dialog Box Lec 4
Color and Font Dialog Box Lec 4
Write a program for creating color dialog box and Font Dialog Box.
Step 1: Create New Windows Form Application “Font and Color DialogBox”
Step 2: Right Click on “Font and Color DialogBox” in solution explorer to add
Windows form as Form1.cs
Step 3: Add the Labels, Buttons, and ColorDialog fontDialog from toolbox on Form1.
Design as shown below:
Step 4: After adding label on the form set its text properties to “This is Label One” we have not
changed its Name property ie label1. Now select label1 and press control key (Ctrl) and drag down
to make copy. Rename its text property to “This is Label Two” again select label1 and press control
key (Ctrl) and drag down to make copy. Rename its text property to “This is Label Three”
Step 5: Now we shall make same size these labels (the size of the labels will be equal to the size
of first selected label)by selecting the below option from align menu after selecting these labels.
Step 6: Now we shall align these labels first center of the form by selecting the below option
from align menu after selecting these labels.
Step 7: Now we shall align these labels within space allocated to these labels on form by
selecting the below option from align menu after selecting these labels.
After selecting these options
Step 9: After adding Button on the form set its text properties to “Change Label One Color” we
have not changed its Name property i.e. Button1. Now select Button1 and press control key (Ctrl)
and drag down to make copy. Rename its text property to “Change Label Two Color” again select
label1 and press control key (Ctrl) and drag down to make copy. Rename its text property to
“Change Label Three Color”. In the same way we have copied three more buttons for font setting
of these three labels.
Step 10: After adding Buttons on the form; select these buttons we shall make same size these
Buttons (the size of the Buttons will be equal to the size of first selected button)by selecting the
below option from align menu after selecting these Buttons.
Step 11: After selecting these six button we set horizontal spacing between these buttons by
following the options as depicted below.
Step 12: In this step we shall add ColorDialog and FontDialog in our Form. These dialog are not
directly added to the form; they are added in the project i.e. (below the form) as depicted below.
Step 11:Adding code in the Code view
After double clicking on Button1(Change Label One Color) We shall write these line for color
dialog show and label1 color change as depicted below.
[copy here]
colorDialog1.ShowDialog();
label1.ForeColor = colorDialog1.Color;
fontDialog1.ShowDialog();
label1.Font = fontDialog1.Font;
We shall do same for Button5 and Button6.