0% found this document useful (0 votes)
32 views5 pages

Color and Font Dialog Box Lec 4

The document provides steps to create a Windows form application with color and font dialog boxes. It describes how to add labels, buttons, color and font dialog controls to the form and align/size the elements. It also provides code to open the dialogs and set the label colors and fonts based on user selections.

Uploaded by

hasnainmushtaq23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views5 pages

Color and Font Dialog Box Lec 4

The document provides steps to create a Windows form application with color and font dialog boxes. It describes how to add labels, buttons, color and font dialog controls to the form and align/size the elements. It also provides code to open the dialogs and set the label colors and fonts based on user selections.

Uploaded by

hasnainmushtaq23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Lecture Objectives

➢ To understand Alignments on Form


➢ To understand Copy and Size elements
➢ To understand ColorDialog with code
➢ To understand FontDialog with code

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;

We shall do same for Button2 and Button3.


Step 12:Adding code in the Code view
After double clicking on Button4(Change Label One Font) We shall write these line for font
dialog show and label1 font change as depicted below.
.

fontDialog1.ShowDialog();
label1.Font = fontDialog1.Font;
We shall do same for Button5 and Button6.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy