Introduction to Event Handlers and Windows Forms Applications
Transcript of Introduction to Event Handlers and Windows Forms Applications
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
1/89
INTRODUCTION TO EVENT HANDLEAND WINDOWS FORMS APPLICATIOChapter 03
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
2/89
OBJEC
With this tpi!" the st#$e%ts sh#&$ 'e a'&e t(
C)pare !))a%$*&i%e i%ter+a!es a%$ +r)s*'ase$ i%ter+a!es
Desi,% the #ser i%ter+a!e +r a Wi%$-s app&i!ati%
Create a Wi%$-s Fr)s App&i!ati% pr.e!t #si%, Vis#a& St#$i
Use Vis#a& St#$i t !reate a%$ !%/,#re !%tr& i%sta%!es
Use !%tr&s t !reate the #ser i%ter+a!e +r a Wi%$-s Fr)s Appr.e!t
Create !$e +r a Wi%$-s Fr)s App&i!ati% pr.e!t
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
3/89
COMPARIN COMMANAND FORM*BASED INTER
!))a%$*&i%e i%ter+a!e
It $isp&a1 te2t#a& pr)pts a%$ ,ets e%$ #ser i%p#t %e &i%e at a ti
+r)*'ase$ 4is#a& i%ter+a!e
It is %e i% -hi!h the e%$ #ser i%tera!ts -ith a% app&i!ati% 4ia a !%tai%i%, '#tt%s" te2t '2es" !he!5 '2es" s!r&& 'ars" a%$ the'.e!ts
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
4/89
C))a%$*&i%e i%ter+a!e Fr)*'ase$ 4is#a& i%t
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
5/89
DESININ A USER INTE
Pri%!ip&es + a ,$ #ser i%ter+a!ePrinciple Description
C%tr& The e%$ #ser sh#&$ a&-a1s !%tr& the app&i!ati%" ratther -a1 ar#%$
User*+rie%$&i%ess The i%ter+a!e sh#&$ he&p the e%$ #ser a!!)p&ish tas
atte%ti% t itse&+E2a)p&e T )a%1 $i6ere%t +%ts r i)a,es !a% 'e $istra!ti%
I%t#iti4e%ess The i%ter+a!e sh#&$ +&&- a $ire!t st1&e that pr!ee$sE2a)p&e It a% e%$ #ser %ee$s t !)p&ete !%se!#ti4e stepsa
tas5" the steps sh#&$ 'e ,r#pe$ t,ether a%$ pr
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
6/89
DESININ A USER INTE
Pri%!ip&es + a ,$ #ser i%ter+a!ePrinciple Description
C%siste%!1 The i%ter+a!e sh#&$ 'e !%!ept#a&&1" &i%,#isti!a&&1" 4is#a&&1" a!%siste%tE2a)p&e The +%t st1&e #se$ sh#&$ 'e !%siste%t thr#,h#t the i% The 4is#a& '.e!ts % a +r) sh#&$ ha4e the sa)e r si)i
a%$ si7es
Fee$'a!5 The i%ter+a!e sh#&$ pr4i$e !&ear a%$ i))e$iate +ee$'a!5 tE2a)p&e I+ the #ser a$$s a re!r$ t a /&e" the i%ter+a!e sh#&$ i%+
#ser that the re!r$ -as a$$e$ I+ the e%$ #ser )a5es a% errr -he% e%teri%, $ata" the i%t
sh#&$ !))#%i!ate the !a#se + the errr a%$ s#,,est p
sti%s t the pr'&e)
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
7/89
DESININ A USER INTE
Pri%!ip&es + a ,$ #ser i%ter+a!ePrinciple Description
raphi!s The i%ter+a!e sh#&$ %t 'e !ttere$ -ith ,raphi!s tha#se+#& p#rpseE2a)p&e A% i!% + a stp si,% r a% e2it si,% is a% i%t#iti4e
#se asa '#tt% t e%$ the app&i!ati%
I%p#t The i%ter+a!e sh#&$ )i%i)i7e sit#ati%s i% -hi!h the et s-it!h i%p#t )$es +r) the )#se t the 5e1'ar$a,ai%
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
8/89
User I%ter+a!e
Fi&e %a)e(
Ce%
Nr
Stre
C&e
E2
La'e& pr)pt La'e& t $isp&a1 the i)a,e /&e%a)e
Pi!t#re '2 t $isp&a1 the ,raphi!a& i)a,e
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
9/89
DESININ A USER INTE
!%tr& i%sta%!es
These are 4is#a& '.e!ts !reate$ % a +r)
Pri%!ip&es + !%tr& $esi,%Principle Description
A&i,%)e%t C%tr& i%sta%!es appeari%, i% a !)% sh#&$ 'e a&i,C%tr& i%sta%!es appeari%, i% a r- sh#&$ 'e a&i,%e$
Ba&a%!e C%tr& i%sta%!es sh#&$ 'e $istri'#te$ e4e%&1 ar#%$
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
10/89
DESININ A USER INTE
Pri%!ip&es + !%tr& $esi,%
Principle Description
Apprpriate !&r Use s+t !&rs" s#!h as 'e r ,ra1" +r )st +r)sUse 'ri,ht !&rs" s#!h as re$" %&1 +r e)phasis
The +re,r#%$ a%$ 'a!5,r#%$ !&rs sh#&$ ha4e a$!%trast
Si)i&ar 4is#a& '.e!ts sh#&$ ha4e si)i&ar !&rs
F#%!ti% ,r#pi%, C%tr& i%sta%!es that ha4e a si)i&ar p#rpse sh#&$ 't,ether
C%siste%t si7i%, C%tr& i%sta%!es sh#&$ 'e !%siste%t i% si7eE2a)p&e
Whe% a +r) has )#&tip&e '#tt%s" the1 sh#&$ a&& 'si7e
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
11/89
A pr #ser i%ter+a!e
!%tr& i%st
'a&a%!e$ !%tr& i%st
a&i,%e$ %#)er#s
a$$ #%%e!)p&e2it
'a!5,r#%a%$ ser4e
p#rpse
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
12/89
A% i)pr4e$ #ser i%ter+a!e
a&i,%e$ !%
si)p&i/e$ +
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
13/89
USIN VISUAL STUDCREATE WINDOWS F
APPLIC
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
14/89
Vis#a& Basi! Wi%$-spr.e!t t1pes se&e!te$
Wi%$-s Fr)s App&i!ati%te)p&ate se&e!te$
Sti% %a)e
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
15/89
USIN VISUAL STUDCREATE WINDOWS F
APPLICDi6ere%!es 'et-ee% Wi%$-s Fr)s App&i!ati% pr.e!ts a%$ CApp&i!ati% pr.e!ts(
The %&1 4is#a& parts + a C%s&e App&i!ati% pr.e!t are the te2)essa,es that appear i% a C))a%$ Pr)pt -i%$- Wi%$-s FApp&i!ati% pr.e!ts are ,raphi!a& app&i!ati%s ha4i%, %e r )r-ith -hi!h the e%$ #ser i%tera!ts
C%s&e App&i!ati% pr.e!ts are pr!e$#ra& Wi%$-s Fr)s Apppr.e!ts are e4e%t*$ri4e%
The start#p '.e!t +r a C%s&e App&i!ati% pr.e!t is t1pi!a&&1 a %a)e$ Mai% The start#p '.e!t +r a Wi%$-s Fr)s App&i!ati%t1pi!a&&1 a +r)
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
16/89
USIN VISUAL STUDCREATE WINDOWS F
APPLICThe Anatomy of a Windows Forms Application ProjectP#rpse + the -i%$-s i% the Wi%$-s Fr)s App&i!ati% Pr.e!t
Sti% E2p&rer -i%$-
It is #se$ t )a%a,e the /&es that )a5e #p the sti% a%$ its pr.e!t:s
Wi%$-s Fr)s Desi,%er -i%$-
It is -here a +r)
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
17/89
Sti% E2p&rer
T&'2 Wi%$-
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
18/89
USIN VISUAL STUDCREATE WINDOWS F
APPLICThe Solution Explorer It is #se$ t )a%a,e the /&es i% a sti%
M1 Pr.e!t +&$er
It !%tai%s a% Asse)'&1I%+4' /&e" -hi!h $es!ri'es the asse)'&1" a%$ +'i% a%$ '." -hi!h stre the !)pi&e$ pr.e!t
A Wi%$-s Fr)s App&i!ati% pr.e!ts !%tai%s re+ere%!es t the +&&-
asse)'&ies re&ate$ t +r)s a%$ $ra-i%,( S1ste) %a)espa!e
A&& pr.e!ts" % )atter their t1pe" !%tai% a re+ere%!e t this %a)espa!e
S1ste)Dra-i%, %a)espa!e
It is #se$ '1 Wi%$-s Fr)s App&i!ati% pr.e!ts t re%$er :$ra-; the +r) a%'.e!ts appeari%, % the +r)
S1ste)Wi%$-sFr)s %a)espa!e
It !%tai%s thse !&asses that )a5e #p the 4is#a& +r)s a%$ the '.e!ts !reate
+r)s
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
19/89
Sh- A&& Fi&es'#tt% se&e!te$ Pr.e!t
/&es a
Asse)
Fr) /
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
20/89
USIN VISUAL STUDCREATE WINDOWS F
APPLICThe Windows Forms Designer and the ToolboxFr)s
A -i%$- that )a5es #p a Wi%$-s Fr)s App&i!ati%
T- parts + a +r)(
#ser i%ter+a!e :+r);
It is )a$e #p + a re!ta%,#&ar -i%$- !%tai%i%, s#!h 4is#a& '.e!ts as ''2es !a&&e$ !%tr& i%sta%!es !reate$ +r) !%tr&s appeari%, i% the T
!$e 'ehi%$ the +r)
Wi%$-s Fr)s Desi,%er :4is#a& $esi,%er;
It is a t& #se$ t !reate a +r)
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
21/89
USIN VISUAL STUDCREATE WINDOWS F
APPLICThe Windows Forms Designer and the ToolboxWa1s t a!ti4ate the Wi%$-s Fr)s Desi,%er
= Se&e!t the +r) %a)e i% the Sti% E2p&rer" a%$ the% se&e!t Vie-the )e%# 'ar
> Ri,ht*!&i!5 the +r) %a)e i% the Sti% E2p&rer" a%$ the% se&e!t +r) the !%te2t )e%#
3 D#'&e*!&i!5 the +r) %a)e i% the Sti% E2p&rer
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
22/89
!
"
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
23/89
USIN VISUAL STUDCREATE WINDOWS F
APPLICThe Windows Forms Designer and the Toolboxe%era& !hara!teristi!s + a +r)(
tit&e 'ar :pti%a& a%$ &!ate$ % the tp;
It !a% ha4e a% pti%a& !apti%
The !apti% !a% !%tai% spa!es a%$ ther spe!ia& !hara!ters" h-e4er" tsh#&$ /t % the 4isi'&e tit&e 'ar
!%tr& '2 :pti%a& a%$ &!ate$ a&%, the ri,ht si$e + the tit&e 'ar It has '#tt%s t )i%i)i7e" )a2i)i7e" a%$ restre a )a2i)i7e$ +r) t i
It !a% 'e )a$e 4isi'&e r hi$$e%
Mi%i)i7e '#tt% :&!ate$ % the &e+t)st;
It is #se$ t hi$e the +r)" !a#si%, it t appear as a '#tt% % the tas5'a
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
24/89
USIN VISUAL STUDCREATE WINDOWS F
APPLICThe Windows Forms Designer and the Toolboxe%era& !hara!teristi!s + a +r)(
Restre ? Ma2i)i7e '#tt% :t,,&e a%$ appears as the !e%ter '#tt% i% th
Ma2i)i7e '#tt%
It !a#ses the +r) t )a2i)i7e" th#s /&&i%, the $es5tp
Restre '#tt%
It restres the +r) t its ri,i%a& si7e
C&se '#tt%
It !&ses the +r) r the app&i!ati% itse&+
Me%# :pti%a& a%$ appears 'e&- the +r)
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
25/89
USIN VISUAL STUDCREATE WINDOWS F
APPLICThe Windows Forms Designer and the Toolbox
S1ste)Wi%$-sFr)sFr) !&ass
It s#pprts )eth$s" prperties" a%$ e4e%ts
Meth$s
C&se )eth$
It !&ses the +r)" there'1 #%&a$i%, it +r) )e)r1
Hi$e )eth$
It )a5es a +r) i%4isi'&e" '#t the +r) is %t #%&a$e$ +r) )e)r1
Sh- )eth$
It $isp&a1s a +r)
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
26/89
USIN VISUAL STUDCREATE WINDOWS F
APPLICThe Windows Forms Designer and the Toolbox
S1ste)Wi%$-sFr)sFr) !&ass
Prperties
A!!eptB#tt% prpert1
It !%tai%s the %a)e + a B#tt% !%tr& i%sta%!e
Pressi%, the E%ter 5e1 !a#ses the C&i!5 e4e%t t /re +r the '#tt% $esA!!ept '#tt%
There !a% 'e %&1 %e A!!ept '#tt% per +r)
It is +te% !a&&e$ the De+a#&t '#tt%
Ba!5C&r prpert1
It spe!i/es the +r)
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
27/89
USIN VISUAL STUDCREATE WINDOWS F
APPLICThe Windows Forms Designer and the Toolbox
S1ste)Wi%$-sFr)sFr) !&ass
Prperties
Ma2i)i7eB2 prpert1
I+ set t Tr#e" the Restre?Ma2i)i7e '#tt%s are e%a'&e$
I+ set t Fa&se" the '#tt%s are $isa'&e$
Mi%i)i7eB2 prpert1
It $e/%es -hether the Mi%i)i7e '#tt% is e%a'&e$ r $isa'&e$
Fr)Br$erSt1&e prpert1
It is #se$ t spe!i+1 the appeara%!e + the 'r$er s#rr#%$i%, a +r) a%is resi7a'&e
N%e
N 'r$er s#rr#%$s the +r)
Fi2e$Si%,&e a%$ Fi2e$3D
It !a#ses the +r) t appear -ith a @at a%$ three*$i)e%si%a& 'r$e
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
28/89
USIN VISUAL STUDCREATE WINDOWS F
APPLICThe Windows Forms Designer and the Toolbox
S1ste)Wi%$-sFr)sFr) !&ass
Prperties
Fr)Br$erSt1&e prpert1
Fi2e$Dia&,
It appears the sa)e t the e%$ #ser as the setti%, Fi2e$Si%,&e
It is #se$ t $isp&a1 +r)s that )#st 'e !&se$ 'e+re the e%$ #-ith the ther +r)s i% the app&i!ati%
Si7a'&e
It !%/,#res the +r) s that it !a% 'e resi7e$ '1 $ra,,i%, the +
Fi2e$T&Wi%$- a%$ Si7a'&eT&Wi%$-
It !a#ses the +r) t appear -ith a shrter tit&e 'ar
These are !a&&e$ t& -i%$-s
Appeara%!e is si)i&ar t the appeara%!e + Vis#a& St#$i t& -
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
29/89
USIN VISUAL STUDCREATE WINDOWS F
APPLICThe Windows Forms Designer and the Toolbox
S1ste)Wi%$-sFr)sFr) !&ass
Prperties
Ca%!e&B#tt% prpert1
It !%tai%s the %a)e + the B#tt% !%tr& i%sta%!e $esi,%ate$ as the
Pressi%, the Es!ape 5e1 !a#ses the C&i!5 e4e%t t /re +r the ass!iat
O%&1 %e '#tt% % a +r) !a% 'e $esi,%ate$ as the Ca%!e& '#tt%
I!% prpert1
It !%tai%s the i)a,e that appears i% the #pper*&e+t !r%er + the +r)
Te2t prpert1
It !%tai%s the !apti% that appears i% the +r)
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
30/89
USIN VISUAL STUDCREATE WINDOWS F
APPLICThe Windows Forms Designer and the Toolbox
S1ste)Wi%$-sFr)sFr) !&ass
Prperties
StarPsiti% prpert1
It is #se$ t spe!i+1 -here % the $es5tp the +r) -i&& appear -he%
Ce%terS!ree%
The +r) is $isp&a1e$ i% the !e%ter + the $es5tp Ma%#a
The psiti% + the +r) is $e/%e$ '1 the a%$ prperties
a%$ prperties
It $e/%e the psiti% + the +r) re&ati4e t the $es5tp
O%&1 #se$ -he% the StartPsiti% prpert1 is set t #anual
Vaes are e2presse$ i% pi2e&s
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
31/89
USIN VISUAL STUDCREATE WINDOWS F
APPLICThe Windows Forms Designer and the Toolbox
S1ste)Wi%$-sFr)sFr) !&ass
E4e%ts
La$ e4e%t
It /res -he% a +r) is &a$e$ i%t )e)r1 ea!h ti)e the app&i!ati%
It is #se$ t per+r) i%itia&i7ati% tas5s" s#!h as $isp&a1i%, the !#rre+r)
Fr)C&si%, e4e%t
It /res .#st 'e+re a +r) is #%&a$e$ +r) )e)r1
Me 5e1-r$
It is a spe!ia& i$e%ti/er #se$ t re+ere%!e the !#rre%t i%sta%!e + a +
C&se )eth$ * MeC&se:;
It !&se the !#rre%t +r) i%sta%!e" there'1 e%$i%, the app&i!ati%
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
32/89
USIN VISUAL STUDCREATE WINDOWS F
APPLICThe Windows Forms Designer and the Toolbox
T&'2
It !%tai%s a&& + the 4is#a& t&s :!%tr&s; %e!essar1 t !reate a +r)i%ter+a!e
Creati%, a !%tr& i%sta%!e % a +r)
C&i!5 the $esire$ !%tr& i% the T&'2 The se&e!te$ !%tr& appears hi,$ra, the #t&i%e + the !%tr& i%sta%!e i%t the Wi%$-s Fr)s Desi,%epsiti% a%$ si7e
It is a&s pssi'&e t !reate a !%tr& i%sta%!e '1 $#'&e*!&i!5i%, the !%tT&'2 The !%tr& is !reate$ at the #pper*&e+t !r%er + the +r)" r a$)st re!e%t&1 !reate$ !%tr& i%sta%!e
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
33/89
C))ta' e2
Ta's !
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
34/89
USIN VISUAL STUDCREATE WINDOWS F
APPLIC$ntroduction to the Properties Window
Prpert1
It is #se$ t stre $ata +r a !&ass i%sta%!e :'.e!t;
F#r se!ti%s + the Prperties -i%$-
&ist arr- :appears t the ri,ht + the O'.e!t $rp*$-% '2 at the t
Prperties -i%$-;
It is #se$ t se&e!t a% '.e!t s#!h as a +r) r a !%tr& i%sta%!e !reate$
O'.e!t $rp*$-% '2
It $isp&a1s the !#rre%t&1 se&e!te$ '.e!t
t&'ar area
It !%tai%s '#tt%s #se$ t !ha%,e the r$er i% -hi!h the prperties appse!ti% a%$ -hether t $isp&a1 the prperties r e4e%ts +r the se&e!te$
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
35/89
USIN VISUAL STUDCREATE WINDOWS F
APPLIC$ntroduction to the Properties Window
F#r se!ti%s + the Prperties -i%$-
&ist se!ti%
Na)e !)%
It !%tai%s the %a)e + ea!h prpert1
Vae !)%
It !%tai%s the !#rre%t 4ae assi,%e$ t a prpert1 Des!ripti% se!ti% :appears at the 'tt) + the -i%$-;
It !%tai%s a 'rie+ $es!ripti% + the se&e!te$ prpert1
It !a% 'e hi$$e%
Cate,ri7e$ '#tt%
The prperties are r,a%i7e$ 'ase$ % the p#rpse + the prpert1
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
36/89
USIN VISUAL STUDCREATE WINDOWS F
APPLIC$ntroduction to the Properties Window
A&pha'eti! '#tt%
The prperties appear srte$ i% as!e%$i%, a&pha'eti! r$er
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
37/89
Disp&a1 prperties'1 !ate,r1
Disp&a1 prpertiesa&pha'eti!a&&1
Disp&a1 pr
O'.e!t $rp
Disp&a1 e4e
T&'ar
List se!ti%
Vae !)Na)e !)%
Des!ripti% se!ti%
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
38/89
USIN VISUAL STUDCREATE WINDOWS F
APPLIC%on&guring Textual and 'ierarchical Properties
te2t#a& 4ae
The prpert1 is e$ite$ '1 t1pi%, the $esire$ 4ae i% the Vae !)
E2a)p&e
(ameprpert1 stre a te2t#a& 4ae
Hierar!hi!a& The 4aes are set #si%, a $ri&&*$-% i%ter+a!e
E2a)p&e
)ocationprpert1 has *a%$+prperties
Si,eprpert1 has Widtha%$ 'eightprperties
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
39/89
L!ati% prpert1e2pa%$e$
Hierar!hi!a& prpert1!&&apse$
Hierar!hi!a& prperties i% the Prperties -i%$-
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
40/89
USIN VISUAL STUDCREATE WINDOWS F
APPLIC%on&guring Textual and 'ierarchical Properties
Prperties i%4&4i%, !&r
Vaes are set #si%, a !&r pa&ette
E2a)p&e
Ba!5C&r prpert1
FreC&r prpert1
C#st) ta' It is #se$ t !reate !#st) !&rs
We' ta'
Lists thse !&r s#pprte$ '1 the We'
S1ste) ta'
It !a#ses the !&r + a !%tr& i%sta%!e t
'e the sa)e as the !&r $e/%e$ '1 a
!))% Wi%$-s s1ste) prpert1
Three !&rpa&ette ta's
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
41/89
USIN VISUAL STUDCREATE WINDOWS F
APPLIC%on&guring Textual and 'ierarchical Properties
S)e prperties ha4e a /2e$ set + 4aes +r) -hi!h %e
4ae !a% 'e se&e!te$
The $esire$ 4ae is se&e!te$ +r) a $rp*$-% &ist
E2a)p&e
Si7eM$e prpert1
Pi!t#reB2 prpert1
C&i!5 t$rp*$
Drp*$-% &ist
S S S
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
42/89
USIN VISUAL STUDCREATE WINDOWS F
APPLIC%on&guring Textual and 'ierarchical Properties
S)e prperties sh- the $ia&, '2
E2a)p&e
F%t prpert1
It $isp&a1 a $ia&, '2" a&&-i%, the pr,ra))er t se&e!t the t1a%$ +%t attri'#tes
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
43/89
USIN VISUAL STUD
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
44/89
USIN VISUAL STUDCREATE WINDOWS F
APPLIC%on&guring Textual and 'ierarchical Properties
S)e prperties ha4e a 4is#a& e$itr a&&-i%, a pr,ra))er t setprpert1
E2a)p&e
Te2tA&i,% prepert1
La'e& prpert1
Prpert1a% e%#)
C&i!5 tharr- tthe 4is#
Vis#a& E
Wi%$-s Fr)sDesi,%er a!ti4e
+r)Mai% se&e!te$ i%O'.e!t $rp*$-% '2
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
45/89
Setti%, prperties +r a +r)
, . p
Fr)Br$erSt1&eprpert1
Si7i%, ha%$&esappear
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
46/89
USIN VISUAL STUDIO TO CREACONFIURE CONTROL INS
T&'2 a%$ Wi%$-s Fr)s Desi,%er It is #se$ t,ether t !reate !%tr& i%sta%!es % a +r)
%reating and Deleting %ontrol $nstancesT- -a1s + !reati%, the !%tr& i%sta%!e % the +r)(
I% the T&'2" $#'&e*!&i!5 the $esire$ !%tr& I% the T&'2" !&i!5 the $esire$ !%tr& M4e the )#se pi%ter t t
Fr)s Desi,%er The )#se pi%ter !ha%,es t a !rsshair a&%, -itthe !%tr& C&i!5 a%$ $ra, the )#se t $e/%e the i%itia& si7e a%$ p!%tr& i%sta%!e Re&ease the )#se t !reate the !%tr& i%sta%!e apsiti%
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
47/89
USIN VISUAL STUDIO TO CREACONFIURE CONTROL INS
%reating and Deleting %ontrol $nstancesDe&eti%, a !%tr& i%sta%!e(
C&i!5 the !%tr& i%sta%!e i% the Wi%$-s Fr)s Desi,%er a%$ the% pDe&ete 5e1
Ri,ht*!&i!5 a !%tr& i%sta%!e t se&e!t it" a%$ the% !&i!5 De&ete +r) )e%# that appears
#o-ing and .esi,ing %ontrol $nstancesWa1s t )4e a%$ resi7e the se&e!te$ !%tr& i%sta%!e(
Pressi%, the arr- 5e1s )4es the se&e!te$ !%tr& i%sta%!e i% the $arr-
H&$i%, $-% the C%tr& 5e1 -hi&e pressi%, the arr- 5e1s )4es t!%tr& i%sta%!e i% the $ire!ti% + the arr-
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
48/89
USIN VISUAL STUDIO TO CREACONFIURE CONTROL INS
#o-ing and .esi,ing %ontrol $nstancesWa1s t )4e a%$ resi7e the se&e!te$ !%tr& i%sta%!e(
H&$i%, $-% the Shi+t 5e1 -hi&e pressi%, the arr- 5e1s resi7es thei%sta%!e
The )#se !a% 'e #se$ t $ra, the si7i%, ha%$&es" -hi!h are the s)appear ar#%$ the se&e!te$ !%tr& i%sta%!e
Si7i%, ha%$&e $ %t appear i+ the AutoSi,e prpert1 is set t True
The 'eight a%$ Width prperties !a% a&s 'e set #si%, the Prpertthere'1 resi7i%, the !%tr& i%sta%!e
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
49/89
USIN VISUAL STUDIO TO CREACONFIURE CONTROL INS
Wor/ing with #ultiple %ontrol $nstancesWa1s t se&e!t )#&tip&e !%tr& i%sta%!es(
Usi%, the Pi%ter t& i% the T&'2" $ra, a re!ta%,#&ar re,i% )ar5!%tr& i%sta%!es t 'e se&e!te$
Whi&e h&$i%, $-% the Shi+t 5e1" !&i!5 ea!h !%tr& i%sta%!e t se&e!
Aligning #ultiple %ontrol $nstancesFr)at )e%#
It has )e%# ite)s #se$ t a&i,% the se&e!te$ !%tr& i%sta%!es a%$ a-hi&e the Wi%$-s Fr)s Desi,%er is a!ti4e
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
50/89
USIN VISUAL STUDIO TO CREACONFIURE CONTROL INS
Aligning #ultiple %ontrol $nstancesDi6ere%t a&i,%)e%t !))a%$s appeari%, % the Fr)at )e%#(
A&i,% !))a%$
It a&i,%s the &e+t" ri,ht" tp" r 'tt) )ar,i%s + the se&e!te$ !%tr& i%sthe psiti% + the a!ti4e !%tr& i%sta%!e
Ma5e Sa)e Si7e !))a%$
As its %a)e i)p&ies" it resi7es the se&e!te$ !%tr& i%sta%!es t )at!h th
a!ti4e !%tr& i%sta%!e
Hri7%ta& Spa!i%, a%$ Verti!a& Spa!i%, !))a%$s
It a&i,% the !%tr& i%sta%!es -ith the +r) hri7%ta&&1 r 4erti!a&&1
Ce%ter i% Fr) !))a%$
It !e%ters the se&e!te$ !%tr& i%sta%!es 'et-ee% either the tp a%$ 'ttthe +r) r the &e+t a%$ ri,ht )ar,i%s
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
51/89
USIN VISUAL STUDIO TO CREACONFIURE CONTROL INS
Aligning #ultiple %ontrol $nstancesS%ap &i%es
It a&&-s %e !%tr& i%sta%!e t 'e a&i,%e$ -ith a%ther
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
52/89
C%tr i%sta%!e
'ei%, a&i,%e$
Verti!a&s%ap &i%e
Hri7%ta&s%ap &i%e
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
53/89
INTRODUCTION TO VSTUDIO CON
C%tr&s(Pi!t#reB2 !%tr&
It $isp&a1s ,raphi!a& i)a,es
La'e& !%tr&
It $isp&a1s te2t
B#tt% !%tr&
It per+r)s a spe!i/! tas5 -he% !&i!5e$ '1 the e%$ #serOpe%Fi&eDia&, !%tr&
It $isp&a1s a $ia&, '2" a&&-i%, the e%$ #ser t se&e!t a /&e t pe%
T&Tip !%tr&
It $isp&a1s a% i%+r)ati%a& pp*#p )essa,e -he% the )#se h4er!%tr& i%sta%!e +r a +e- se!%$s
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
54/89
INTRODUCTION TO VSTUDIO CON
The System0Windows0Forms0%ontrol %lass It is the 'ase !&ass +r a&& 4is#a& !%tr&s
C%tr& C&ass
It s#pp&ies the 'asi! +#%!ti%a&it1 t ,et i%p#t +r) the 5e1'ar$ a%$t $isp&a1 #tp#t
S1ste)Wi%$-sFr)s
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
55/89
S1ste)Wi%$-sFr)sC%tr&
S1ste)Wi%$-sFr)sB#tt%Base
S1ste)Wi%$-sFr)sB#tt%
S1ste)Wi%$-sFr)sLa'e&
S1ste)Wi%$-sFr)sPi!t#reB2
S1ste)Wi%$-sFr)sC))%Dia&,
S1ste)Wi%$-sFr)sFi&eDia&,
S1ste)Wi%$-sFr)sOpe%Fi&eDia&,
Hierar!hi!a& r,a%i7ati% + !%tr& !&asses
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
56/89
INTRODUCTION TO VSTUDIO CON
1nderstanding the (ame PropertyR#&es +r %a)i%, i$e%ti/ers(
M#st 'e,i% -ith a &etter a%$ !%tai% %&1 &etters" $i,its" a%$ the #%$!hara!ter
It )#st 'e #%i9#e
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
57/89
INTRODUCTION TO VSTUDIO CON
1nderstanding the (ame PropertyC%tr& a%$ +r) pre/2es
%ontrol Pre&x
B#tt% 't%
La'e& &'&
Ope%Fi&eDia&, +$
Pi!t#reB2 pi!
T&Tip tip
Fr) +r)
INTRODUCTION TO V
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
58/89
INTRODUCTION TO VSTUDIO CON
1nderstanding the (ame PropertyC))% Errrs
Prperties Wi%$- errr $ia&, '2
C&i!5 t !&&apse
Detai&s se!ti%
INTRODUCTION TO V
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
59/89
INTRODUCTION TO VSTUDIO CON
#embers of the %ontrol %lassS1%ta2
S1ste)Wi%$-sFr)sC%tr& !&ass
Meth$s
Hi$e )eth$
It )a5es the !%tr& i%sta%!e i%4isi'&e
Sh- )eth$
It )a5es the !%tr& i%sta%!e 4isi'&e
Prperties
Fre!&r a%$ Ba!5C&r prperties
It $e/%e the te2t !&r a%$ !&r appeari%, 'ehi%$ the te2t" respe!ti4e&1
INTRODUCTION TO V
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
60/89
INTRODUCTION TO VSTUDIO CON
#embers of the %ontrol %lassPrperties
E%a'&e prpert1
It stres 4aes True r False" i%$i!ati%, -hether the !%tr& i%sta%!e -e%$ #ser i%tera!ti%
Hei,ht a%$ Wi$th prperties
It stre the si7e + the !%tr& i%sta%!e
A#tSi7e prpert1
I+ set t Tr#e" the !%tr& i%sta%!e is resi7e$ 'ase$ % its !%te%ts
Mi%i)#)Si7e prpert1
It $e/%es the )i%i)#) si7e + the !%tr& i%sta%!e
Ma2i)#)Si7e prpert1
It $e/%es the )a2i)#) si7e + the !%tr& i%sta%!e
INTRODUCTION TO V
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
61/89
INTRODUCTION TO VSTUDIO CON
#embers of the %ontrol %lassPrperties
L!ati% prpert1
It is #se$ t set the psiti% + the !%tr& i%sta%!e % the +r)
Na)e prpert1
It is #se$ t #%i9#e&1 i$e%ti+1 the !%tr& i%sta%!e
Te2t prpert1
It !%tai%s the te2t that appears i% the 4isi'&e re,i% + the !%tr& i%sta%
Visi'&e prpert1
It stres the 4aes True r False a%$ i%$i!ates -hether the !%tr& i%str hi$$e% +r) the e%$ #ser
INTRODUCTION TO V
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
62/89
INTRODUCTION TO VSTUDIO CON
#embers of the %ontrol %lassE4e%ts
C&i!5 e4e%t
It /res -he% the e%$ #ser !&i!5s the )#se % a !%tr& i%sta%!e
The )abel %ontrol
S1%ta2S1ste)Wi%$-sFr)sLa'e& !&ass
INTRODUCTION TO V
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
63/89
INTRODUCTION TO VSTUDIO CON
The )abel %ontrolPrperties
B$erSt1&e prpert1
It !a% 'e set t %e + three !%sta%t 4aes
N%e
N 'r$er s#rr#%$s the &a'e&
Fi2e$Si%,&e
A @at 'r$er s#rr#%$ the &a'e&Fi2e$3D
The !%tr& i%sta%!e appears re!esse$
F%t prpert1
It $e/%es the t1pe+a!e a%$ the si7e + the te2t appeari%, i% the &a'e&
Te2tA&i,% prpert1
It $eter)i%es h- the te2t#a& !hara!ters are a&i,%e$ i%si$e the re,i% +
INTRODUCTION TO V
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
64/89
INTRODUCTION TO VSTUDIO CON
The 2utton %ontrolS1%ta2
S1ste)Wi%$-sFr)sB#tt% !&ass
Prperties
" " Hei,ht" a%$ Wi$th prperties
It $e/%e its psiti% a%$ si7e % the +r)
E%a'&e$ prpert1
I+ set t True" Wi%$-s /res a C&i!5 e4e%t -he% the e%$ #ser !&i!5s the '
I+ set t False" the '#tt% te2t appears sha$e$" a%$ C&i!5 e4e%ts are %t
F&atSt1&e prpert1
F&at
The '#tt% appears @at % the +r)
INTRODUCTION TO V
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
65/89
INTRODUCTION TO VSTUDIO CON
The 2utton %ontrol F&atSt1&e prpert1
Pp#p
The '#tt% appears raise$ -he% the )#se pi%ter h4ers 4er the ti)e
Sta%$ar$
The '#tt% appears raise$ 6 the +r)
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
66/89
INTRODUCTION TO VSTUDIO CON
The 2utton %ontrol Te2t prpert1
It !%tai%s the te2t that appears i% the '#tt%
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
67/89
INTRODUCTION TO VSTUDIO CON
The Picture2ox %ontrol It !a% $isp&a1 JPE" 'it)ap" a%$ ther i)a,e +r)ats
S1%ta2
S1ste)Wi%$-sFr)sPi!t#reB2 !&ass
Prperties
Br$erSt1&e prpert1
It $e/%es the appeara%!e + the 'r$er s#rr#%$i%, the !%tr& i%sta%!e
I)a,e prpert1
It !%tai%s the i)a,e $isp&a1e$ i% the !%tr& i%sta%!e
I)a,eL!ati% prpert1
It !%tai%s the %a)e + the $is5 /&e -here the i)a,e is stre$
INTRODUCTION TO V
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
68/89
INTRODUCTION TO VSTUDIO CON
The Picture2ox %ontrolPrperties Si7eM$e prpert1
It $e/%es h- the i)a,e appears i%si$e the re,i% + the !%tr& i%sta%!e
Nr)a&
The i)a,e appears at the #pper*&e+t !r%er + the !%tr& i%sta%!e a%$ is %t resi
Stret!hI)a,e
It !a#ses the i)a,e t 'e resi7e$ s#!h that it /&&s the re,i% + the !%tr& i%sta%
A#tSi7e The !%tr& i%sta%!e resi7es t /t the i)a,e
Ce%terI)a,e
It !a#ses the i)a,e t 'e !e%tere$ i% the !%tr& i%sta%!e
E4e%ts
C&i!5 e4e%t
A Pi!t#reB2 !%tr& i%sta%!e !a% 'e )a$e t -r5 as i+ it -ere a B#tt% !%tr& i%sta
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
69/89
I)a,e appears atits a!t#a& si7e
Usi%, the Si7eM$e prpert1 t s!a&e i)a,es
I)a,e is stret!he$ t/&& the !%tr& i%sta%!e
C%trresi7e
I)a,i% !%
INTRODUCTION TO V
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
70/89
INTRODUCTION TO VSTUDIO CON
The 3penFileDialog %ontrol It $isp&a1s a $ia&, '2" a&&-i%, the e%$ #ser t se&e!t a /&e t
INTRODUCTION TO V
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
71/89
INTRODUCTION TO VSTUDIO CON
The 3penFileDialog %ontrolMeth$ a%$ prpert1 %ee$e$ t #se the Ope%Fi&eDia&, !%tr&(
Sh-Dia&, )eth$
It $isp&a1s the $ia&, '2 t the e%$ #ser
Fi&eNa)e prpert1
It stres the /&e%a)e se&e!te$ '1 the e%$ #ser
State)e%t sh-i%, h- t $isp&a1 a% Ope%Fi&eDia&, !%tr& i%sta%+$I)a,es" a%$ the% -rite the /&e%a)e t the C%s&e -i%$-
ofd$mages0ShowDialog45
System0%onsole0Write)ine4ofd$mages0File(ame5
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
72/89
I%4isi'&e !%tr& i%sta%!esappear i% a resi7a'&e !)p%e%t
Tra1 'e&- the +r)
CREATIN CODE
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
73/89
CREATIN CODE WINDOWS FORMS APPLIC
$ntroduction to %lass 2loc/s and Partial %lassesState)e%ts sh-i%, the str#!t#re + a +r) %a)e$ +r)Mai% -ith a+r)Mai%4'
Public %lass frm#ain
6 statements
End %lass
Di6ere%!e 'et-ee% a C&ass a%$ M$#&e '&!5s( A M$#&e '&!5 !a% ha4e a pr!e$#re %a)e$ Mai% )ar5i%, the app&
pi%t A C&ass '&!5 !a% ha4e a pr!e$#re %a)e$ Mai%" it is %t the e%tr1 pi%t
O'.e!ts are !reate$ +r) te)p&ates !a&&e$ !&asses" a%$ )#&tip&e '.ei%sta%!es; !a% 'e !reate$ +r) the sa)e !&ass Be!a#se a +r) is a +r)s :'.e!ts; !a% 'e !reate$ +r) the sa)e !&ass M$#&es -r5 i%
CREATIN CODE
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
74/89
CREATIN CODE WINDOWS FORMS APPLIC
$ntroduction to %lass 2loc/s and Partial %lassespartia& !&ass It is a !&ass that is sp&it a!rss )#&tip&e ph1si!a& /&es
T- reas%s -h1 partia& !&asses are #se+#&(
S#ppse that se4era& $e4e&pers -ere !reati%, a !)p&e2 !&ass Usi%!&asses" ea!h $e4e&per !#&$ -r5 -ith a separate ph1si!a& /&e" a&&
ther $e4e&pers t -r5 % the ther parts + the !&ass !%tai%e$ i%Whe% $e4e&p)e%t is !)p&ete" a&& + the /&es that are part + the !!)p&ete$
Vis#a& St#$i a%$ Wi%$-s Fr)s Desi,%er #se partia& !&asses Vis#athe !&ass +r a +r) i%t t- /&es O%e /&e is )a%a,e$ e%tire&1 '1 thFr)s Desi,%er De4e&per*!reate$ !$e appears i% the ther /&e Th!$e pre4e%ts a!!i$e%ta& )$i/!ati% r !rr#pti% + !$e ,e%eratWi%$-s Fr)s Desi,%er
CREATIN CODE
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
75/89
CREATIN CODE WINDOWS FORMS APPLIC
$ntroduction to %lass 2loc/s and Partial %lassesState)e%ts sh-i%, the str#!t#re + the +r)Mai%Desi,%er4' /&e(Partial Public %lass frm#ain
$nherits System0Windows0Forms0Form
6 Windows Forms Designer generated code0
End %lass
Partia& 5e1-r$
It $e%tes that the !&ass is a partia& !&ass
The pre!e$i%, !&ass $e!&arati% a&s !%tai%s the +&&-i%, $nherits s
$nherits System0Windows0Forms0Form
CREATIN CODE
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
76/89
CREATIN CODE WINDOWS FORMS APPLIC
$ntroduction to %lass 2loc/s and Partial %lasses$eri4e$ !&ass It !a% i%herit the )e)'ers + a%ther !&ass !a&&e$ the 'ase !&ass
The pre!e$i%, state)e%t i%$i!ates that the !&ass %a)e$ frm#ain i%h'ase System0Windows0Forms0Form !&ass
A#t)ati!a&&1 ,e%erate$!$e appears i% the+r)Mai%Desi,%er4' /&e
Sh- A&& F'#tt% se&
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
77/89
Pr!e$#res
+r/
CREATIN CODE
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
78/89
CREATIN CODE WINDOWS FORMS APPLIC
$ntroduction to E-ent 'andlerse4e%t ha%$&er It is a pr!e$#re !%tai%i%, %e r )re Vis#a& Basi! state)e%ts tha
e2e!#tes -he% the e%$ #ser per+r)s a% a!ti%" s#!h as !&i!5i%, a '
C$e se,)e%t sh-i%, a %lic/ e4e%t ha%$&er +r a 2utton !%tr%a)e$ btnDemo(
Pri-ate Sub btnDemo7%lic/4 2y8al sender As System03bj2y8al e As System0E-entArgs5 'andles btnDemo0%lic
End Sub
Ha%$&es !&a#se
It )ar5s a pr!e$#re as a% e4e%t ha%$&er
User !&i!5s aApp&i!ati%
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
79/89
'#tt% /ri%, a%e4e%t
Wi%$-s !a&&se4e%t*ha%$&i%,
pr!e$#re
E4e%t*ha%$&i%,pr!e$#re/%ishes
App&i!ati%starts
App&i!ati% -aits+r a% e4e%t t
/re
CREATIN CODE
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
80/89
WINDOWS FORMS APPLIC
$ntroduction to E-ent 'andlersT- -a1s t !reate e4e%t ha%$&ers a#t)ati!a&&1( D#'&e*!&i!5i%, a !%tr& i%sta%!e i% the Wi%$-s Fr)s Desi,%er a!
C$e E$itr a%$ !reates the e4e%t ha%$&er +r !%tr&
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
81/89
C&ass Na)e $rp*$-%'2 $isp&a1s the +r)a%$ !%tr& i%sta%!es
B#tt% !%tr&i%sta%!e se&e!te$
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
82/89
E4e%ts app&iB#tt% !%trMeth$ Na)
CREATIN CODE
-
7/24/2019 Introduction to Event Handlers and Windows Forms Applications
83/89
WINDOWS FORMS APPLIC
1sing Assignment Statements to .ead and Write Propertassi,%)e%t state)e%t It is )a$e #p + a &e+t si$e a%$ a ri,ht si$e" separate$ '1 a% e9#a& si
The e2pressi% % the ri,ht si$e is e4aate$" a%$ the res#&t is stree2pressi% % the &e+t si$e
E2a)p&e(
A &itera& stri%, 4ae appears % the ri,ht si$e #si%, the +&&-i%,
#e0Text : ;8isual 2asic