Tải bản đầy đủ - 0 (trang)
Appendix D. Component and Control Survey

Appendix D. Component and Control Survey

Tải bản đầy đủ - 0trang

Components

WhatfollowsisabriefsurveyofthestandardWindowsForms

2.0components,listedinalphabeticalorder.



BackgroundWorker



SeeChapter18:MultithreadedUserInterfaces.



BindingNavigator



SeeChapter16:DataBindingBasicsandChapter17:Applied

DataBinding.



BindingSource



SeeChapter16andChapter17.



ColorDialog

SeeChapter3:Dialogs.



ErrorProvider

SeeChapter3.



FolderBrowserDialog



SeeChapter3.



FontDialog

SeeChapter3.



HelpProvider

SeeChapter3.



ImageList

ControlslikeTreeViewandListViewcontaintreenodesandlistviewitemswhoseimagescomefromanImageListcomponent.

ImageListmanagesacollectionofimagesofthesamesize,

colordepth,andtransparencycolor(asdeterminedbytheSize,

ColorDepth,andTransparencyColorproperties).Theimages

themselvesarestoredintheImagescollectionandcancontain

anynumberofImageobjects.YoucanedittheImages

collectiondirectlyusingtheImagesCollectionEditor,asshown

inFigureD.1.



FigureD.1.ImagesCollectionEditor



TouseImageListaftertheimageshavebeenpopulatedinthe

editor,youpullthembyindexfromtheImagescollection

property:

intimageIndex=-1;



voidtimer_Tick(objectsender,EventArgse){

++this.imageIndex;

if(this.imageIndex==4)this.imageIndex=0;

this.BackgroundImage=this.imageList.Images[this.imageIndex]

}



What'sniceaboutthiscodeisthatalltherelatedimagescome

fromasingleplace.However,theImageListcomponenthas

somelimitations:

Youcan'teditanimageafterit'sbeenadded;youmust



removetheoldimageandaddtheeditedimage.

Theimagecanhaveonlyafixedsizeofupto256pixelsin

eitherdimension.

TheImagesCollectionEditorisdifficulttouseforimages

largerthan16pixelsineitherdirection,becauseitshows

imagesonlyas16¥16pixelsandsqueezeslargerimages

tofit.

YoumustsetColorDepthandTransparencybeforeadding

imagesforthemtobeapplied.

ImagesareavailableonlyastypeImageandnotdirectlyas

typeIcon,soifyouneedtheIcontypeyoumustconvertit

fromImage.



NotifyIcon

SeeChapter2:Forms.



OpenFileDialog

SeeChapter3.



PageSetupDialog

SeeChapter8:Printing.



PrintDialog



SeeChapter8.



PrintDocument

SeeChapter8.



PrintPreviewDialog

SeeChapter8.



SaveFileDialog

SeeChapter3.



SoundPlayer



SoundPlayerisanenigma:LocatedinSystem.Media,

SoundPlayerisaclassthatcannotbeaddedtotheToolboxand,

consequently,can'tbedroppedontoaforminVS05atdesign

time.However,itisaveryusefulclassthathappenstomakeit

easytoplaysoundfiles:[2]

[2]Beaware,though,thatSoundPlayerisgearedtoplayonly.wavfilesencodedwithpulse-codemodulation

(PCM).



usingSystem.Media;

...

voidsoundPlayerButton_Click(objectsender,EventArgse){

SoundPlayersoundPlayer=



newSoundPlayer(@"C:\WINDOWS\Media\tada.wav");

soundPlayer.Load();

soundPlayer.Play();

}



SoundPlayeralsoprovidessupportforloadingsoundfilesfrom

streamsandURLsbothsynchronouslyandasynchronously,and

forloopingplayback.Additionally,System.Mediaoffers

shortcutsforplayingcommonsystemsoundsusingthe

SystemSoundsclass:

System.Media.SystemSounds.Exclamation.Play();



SystemsoundsincludeAsterisk,Beep,Exclamation,Hand,and

Question.



Timer

SeeChapter18.



ToolTip

SeeChapter3.







Controls

WhatfollowsisabriefsurveyofthestandardWindowsForms

2.0controls,listedinalphabeticalorder.



Button

Buttons,suchastheoneinFigureD.2,areusedtotrigger

actionsonforms.



FigureD.2.AButtonControlinAction



Whenabuttonispressed,theClickeventistriggered:

voidbutton1_Click(objectsender,System.EventArgse){

MessageBox.Show("Ouch!");

}



Inaddition,buttonscanbedesignatedasaform'sAcceptButton

orCancelButton.Thesedesignationsspecifythatthebuttonis

automaticallyclickedwhentheuserpressestheEnterkey

(AcceptButton)ortheEsckey(CancelButton).



CheckBox



CheckBoxobjects,showninFigureD.3,aremostoftenusedto

indicatetheanswertoayes/noquestion.



FigureD.3.ACheckBoxControlinAction



Checkboxesnormallyhavetwostates:checkedorunchecked.

Testingthestateofthecheckboxisassimpleasretrievingthe

valueoftheCheckedproperty:



if(this.checkBox.Checked)MessageBox.Show("Checkboxchecked!



Checkboxesalsosupportamodeinwhichtheyhavethree

states:checked,unchecked,andindeterminate.Youenablethis

modebysettingtheThreeStateBooleanpropertytotrue,which

causesCheckBoxtostartinanindeterminatestateand,asa

userclicksit,togglebetweenthechecked,unchecked,and

indeterminatestates.



CheckedListBox

ACheckedListBox,showninFigureD.4,isanextensionofthe

ListBoxthatallowsuserstochoosemultipleitemsinthelistby

checkingboxes.



FigureD.4.ACheckedListBoxControlinAction



Youcandetectwhenanitemiseithercheckedoruncheckedby

handlingtheItemCheckevent:



voidcheckedListBox_ItemCheck(objectsender,ItemCheckEventArgs

MessageBox.Show("Itemchecked:"+e.CurrentValue.ToString())

}



Whenmultiplelistitemselectioniscommon,checkingoneor

morecheckboxesiseasier,andmoreintuitive,totheuserthan

Ctrl+Shift+left-clicking.Inallotherways,thecheckedlistbox

isidenticaltothestandardlistbox.



ComboBox

TheComboBoxcontrol,showninFigureD.5,isahybridofalist

boxandatextbox.



FigureD.5.AComboBoxControlinAction



Thetextboxpartofthecontrolallowsuserstoenterdata

directlyintothecontrol.Whentheuserclicksonthedown

button,alistofitemsisshownthatuserscanpickfrom.Likea

TextBox,aComboBoxcanbeconfiguredtoallowfree-form

entryofinformationortoallowuserstoselectonlyitemsthat

areinthelistofitemswithinthecontrol.Becausethecontrolis

partTextBoxandpartListBox,it'snotsurprisingthatitcandoa

littleofboth.Aswithtext-orientedcontrols,themostcommon

taskisusuallyretrievingthetext:

MessageBox.Show(this.comboBox.Text);



Aswiththelistbox,youcanhandletheeventwhenthe

selectedindexchanges:



voidcomboBox_SelectedIndexChanged(objectsender,EventArgse)

MessageBox.Show(

"SelectedItem:"+this.comboBox.SelectedItem.ToString());

}



ContextMenuStrip



SeeChapter2andChapter4:Layout.



DataGridView



SeeChapter16andChapter17.



DateTimePicker

ThepurposeoftheDateTimePickercontrol,showninFigure

D.6,istodisplayausereditabledateortimeorboth.



FigureD.6.ADateTimePickerControlinAction



Tohelpcontrolthedatesandtimesthataredisplayed,the

controlallowsuserstospecifyaminimumandmaximumdate

andtime.Tospecifywhethertoshoweitherthedateorthe

timeportionofthecurrentdate/time,youcanchooseaformat

forthetextinthecontrol:

this.dateTimePicker.Format=DateTimePickerFormat.Short;



ShortandLongspecifydifferentdateformats,andTime

specifiesatimeformat.Usually,ifyouareusingthecontrolfor

times,youwillwanttoenabletheupanddownbuttonsby

specifyingtrueforShowUpDown,asshowninFigureD.7.



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Appendix D. Component and Control Survey

Tải bản đầy đủ ngay(0 tr)

×