1 / 15

Child Window Controls in Windows

Child Window Controls are created by a parent window and used for I/O tasks. They have a consistent look and feel with other applications and can be customized. They allow users to display and select data in standard ways. Learn about the different types of Child Window Controls in Windows and how to create and manipulate them.

winans
Télécharger la présentation

Child Window Controls in Windows

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. WindowsControls ChildWindowControls •Windowscreatedbyaparentwindow •Anapplicationusestheminconjunctionwithparent •NormallyusedforsimpleI/Otasks •Havealookandfeelconsistentwithotherapplication Windows •Properties,appearance,behaviordeterminedbypredefinedControlClassdefinitions –Butbehaviorcanbecustomized –EasytosetthemupascommonWindowsobjects •buttons,scrollbars,etc. •CanalsodefinecustomChildWindowControls

  2. •Allowusertodisplay/selectdatainstandardways •WindowsEnvironmentdoesmostofworkin: –painting/updatingaControl'sscreenarea –determiningwhatuserisdoing •Candothe"dirtywork"forthemainwindow •Arethe"workingcomponents"ofDialogBoxes •WindowsOScontainseachcontrol's“WndProc” –somessagestocontrolsareprocessedinpredefinedways •Parent/childrelationshipwithmainwindow –Canhavehierarchiesofchildwindows –Parentandchildcommunicatebysending/receivingmessages •HavebeenpartofWindowssincethefirstversions •Rosterhasgrownfromsixbasiconestoanassortmentof 20+richandvariedcontrols Some.NETControlClasses •Button •Label(Static) •GroupBox •Panel •CheckBox •RadioButton •HScrollBar •VScrollBar •TextBox(Edit) •PictureBox •ListBox •ComboBox •StatusBar •TabControl •ToolBar

  3. •ToolTip •CheckedListBox •DataGrid •DataGridTextBox •DateTimePicker •LinkLabel •ListView •MonthCalendar •NumericUpDown--spinnerbuttons •ProgressBar •PropertyGrid •RichTextBox •TrackBar •TreeView •Others CreatingaControlin.NET •Tocreateacontrolandmakeitappearonaform: 1.DeclareandInstantiateaControlclassobject ButtonmyButton; myButton=newButton(); 2.InitializetheControlobjectbysettingitsproperties myButton.Location=newPoint(10,10); myButton.Text=“ClickMe”; myButton.BackColor=Color.Red; •//etc. 3. AttachtheControltotheForm(addtoparent’scollectionofControls)…

  4. AttachingControlstoaParentForm •AssumewewanttoaddmyButtonandmyLabelcontrolsto“this”Form •Threewaysofdoingit(assumewe’veinstantiatedthecontrolsmyButtonandmyLabel): 1. myButton.Parent=this; myLabel.Parent=this; 2. this.Controls.Add(myButton); this.Controls.Add(myLabel); 3. this.Controls.AddRange(newControl[]{myButton,myLabel}); •Controlsproperty:thecollectionofcontrolsattachedtotheform •#3isdoneautomaticallybytheVisualStudioDesignerwhenyou “drag”controlsontotheform SomeControlProperties/Methods •Commonpropertiesandmethods –DerivefromclassControl –Textproperty •Specifiesthetextthatappearsonacontrol –TextAlignproperty •Alignmentoftextinsidecontrol –Focus()method •Transferstheinputfocustoacontrol •Thecontrolbecomestheactivecontrol –TabIndexproperty •Determinesorderinwhichcontrolsaregiventhefocuswhenusertabs •AutomaticallysetbyVisualStudio.NETDesigner –Enabledproperty •Indicateacontrol’saccessibilityandusability

  5. •Visibleproperty –Hidecontrolfromuser •OrusemethodHide() •Show()todisplayagain •AnchorandDockproperties –Anchoringcontroltospecificlocation •Constantdistancefromspecifiedlocationwhenparentisresized •DefaultinDesignerisTop-Left –Unanchoredcontrolmovesrelativetoformerposition –Dockingallowscontroltospreaditselfalonganentireside –Bothoptionsrefertotheparentcontainer •Sizeproperty •BackColor,ForeColorproperties •Image,ImageAlign,BackgroundImageproperties ControlPropertiesandLayout BeforeresizeAfterresize Constantdistance toleftandtop sides Anchoringdemonstration.

  6. ControlPropertiesandLayout Darkenedbar indicatestowhich wallcontrolis anchored Clickdown-arrow inAnchorproperty todisplay anchoringwindow ManipulatingtheAnchorpropertyofacontrol. ControlLayout Controlexpandsalong topportionoftheform Dockingdemonstration.

  7. ControlEvents •AllControlsderivefrom System.Windows.Forms.Control –Allinherit50+publicEvents –Somecommonones: EventEventargument ClickEventArgs DoubleClickEventArgs ControlAddedControlEventArgs ControlRemovedControlEventArgs EnterEventArgs LeaveEventArgs MoveEventArgs PaintPaintEventArgs ResizeEventArgs SizeChangedEventArgs AllothermouseeventsMouseEventArgs •EventhandlingdoneaswithFormevents AddingaButtonClickEventHandler •TheButtonClickEventDelegateisEventHandler() myButton.Click+=newEventHandler(myButton_Click); … privatevoidmyButton_Click(objectsender,System.EventArgse) { //Addhandlercodehere } •ThiscodeisinsertedautomaticallywhenyouusetheVisualStudio DesignerPropertiesWindowtoaddaClickeventhandler –OrdoubleclickontheControlinVisualStudioDesigner

  8. ButtonControls •Rectangularobjects,oftenwithlabels •Intendedtotriggeranimmediateaction –Actionistriggeredbyclickingmouseonbutton –Orpressingspacebarifithastheinputfocus •SomeimportantButtonproperties: –Location,Size,BackColor,ForeColor,Cursor,Name,Text,TextAlign,Font,Image,ImageAlign,BackgroundImage,TabIndex, –Lotsofothers LabelControls •Controlsdesignedforthedisplayofstatictext –CalledStaticcontrolsinWin32 –Usercan’tchangethetext •Canbechangedincode •Canalsodisplaygraphics •HavemanyofthesamePropertiesasButtons •Canrespondtoevents,butnotreallymeanttodothat

  9. Button-LabelExampleProgram •FormhasaButtoncontrolwithText:“ClickMe” •FormhasaLabelcontrolthatdisplays“HelloWorld”whenbuttonisclicked –Inresponsetothebutton’sClickevent •CanbepreparedmanuallyfromVisualStudio –Programmermustwritecodetoinstantiatethecontrols,attachthemtotheparentform,setupalltheirproperties,andaddtheButtonClickeventhandler •EasiertousetheVisualStudioDesigner –Dragabuttonandlabelcontrolfromthetoolboxtotheform •Controlsareautomaticallyinstantiated&“attached”totheform –ChangethePropertiesofeachinthePropertywindowofeach –AddtheButtonClickhandlerbydoubleclickingonthebutton •OrusingtheButton’sPropertieswindow(lightningbolt) –Addthefollowingcodeintheskeletonhandler label1.Text=“HelloWorld”; ButtonswithImages •ButtonclasshasanImageProperty –Setthatpropertytodisplayanimageonbackgroundofthebutton •CanbeusedinconjunctionwithTextProperty –Textdisplayedontopoftheimage •Makesureimagefitsinthebutton –Canuseimg.GetThumbNailImage(…)toresizetheimage •Arguments:intw,inth,Image.GetThumbnailImageAbortgt,IntPtrp •Lasttwocanspecifyacallbackfunction&data–usuallysettonulland (IntPtr)0,respectively •Returnsthethumbnailimage –Thiscanbeusedasageneralimageresizingfunction –Alternatively,makethebuttonbethesizeoftheimage •Changethebutton’sSizeproperty •ExampleProgram:Button-Image –DoessameasButton-Label,butnowbuttonhasanimageonit

  10. GroupBoxandPanelControls •ArrangecomponentsonaGUI –GroupBoxescandisplayacaption •Almostalwayscontainothercontrols –RadioButtonsorCheckBoxesareverycommon –Onlyoneactiveatatime •Textpropertydeterminesitscaption –Panelsareusedtogroupothercontrolsagainstabackground •Usefulwhenyouneedacontrolthatdoesn’tdomuch •Ifcontentsofpaneltakeupmorespacethanpanelitself,attachedscrollbarscanautomaticallyappear –SousercanviewadditionalcontrolsinsidethePanel GroupBoxControlProperties GroupBoxDescription Properties Common PropertiesControlsThecontrolsthattheGroupBoxcontains.TextTextdisplayedonthetopportionofthe GroupBox(itscaption).

  11. PanelControlProperties Panel Properties Description Common Properties AutoScroll WhetherscrollbarsappearwhenthePanelistoosmalltoholditscontrols.Defaultisfalse. BorderStyle BorderofthePanel(defaultNone; FixedSingle). Fixed3D otheroptionsare and Controls ThecontrolsthatthePanelcontains. Panelproperties. Panels Controls panel scrollbars CreatingaPanelwithscrollbars. panel insidepanel

  12. GroupBox-PanelExample Program •OrganizesonegroupofbuttonsinaGroupBox –GroupBoxislabeled •OrganizesanothergroupofbuttonsinaPanelthatistoosmalltoviewitsbuttons –AutoScrollPropertyisset=>ScrollbarsautomaticallyappeartopermitusertoviewallthebuttonsinsidethePanel •Clickinganybuttoncausesalabelcontroltoindicatewhichbuttonwasclicked ScrollBars •UsedeverywhereinGUIs •Twopurposes: –Toshift(“scroll”)thevisibleareaofaform/control •Scrollbarisattachedtothecontrol/form •Setparentform/control’sAutoScrollPropertytotrue –Tovaryaparameter •Standalonescrollbar •ScrollbarPropertiesthatcanberead/modified: –SizeandLocationonparentcontrol/form –Range:MaximumandMinimumthumbposition –CurrentValueofthumbposition –Changevalues •SmallChange:Valuechangewhenuserclicksonendarrows •LargeChange:valuechangewhenuserclicksonareabetweenendarrowsandthumb

  13. ScrollBarEvents •TwoeventsraisedbyScrollBarcontrols –ValueChanged--Data:EventArgs •RaisedwhenValuepropertyhaschanged,eitherbyaScrolleventorprogrammatically –Scroll--Data:ScrollEventArgs •Raisedwhenscrollbarthumbhasbeenmoved,eitherbymouseorkeyboard •Providesinformationabouttheevent,includingthenewvalueandtypeofevent •ScrollEventprovidesmoreinformationthanValueChanged •SomeScrollEventArgsProperties: –IntValue –ScrollEventTypeType »EnumerationMembers:SmallDecrement(LorTarrow),SmallIncrement(RorB),LargeDecrement(LorTareas),LargeInccrement(RorB),ThumbTrack(Thumbdown)ThumbPosition(thumbup),EndScroll(scrolloperationdone),Others Scroll-ImageExample •Addstandalonehorizontalandverticalscrollbarstomainform –Positionhorizontalonealongbottomofform –Verticaloneonrightside,leavingspaceonrightfor2labelcontrols •ControlthepositionofanImagewiththescrollbars •Labelcontrolsshowcurrentposition(x,y)ofimage •Events: –Paint:drawimageinitsnewposition –Scrollofhorizontalscrollbar:setnewxvalueofimageposition,changelabel1’stexttocurrentscrollbarValue,&repaint –Scrollofverticalscrollbar:setnewyvalueofimageposition,changelabel2’stexttocurrentscrollbarValue,&repaint –Resize:repositionscrollbarsandresettheirMaximumvalues

  14. RadioButtons&CheckBoxes •Botharepredefined“state”buttonsthatallowusertoselectordeselectagivenoption –Canbesetto“on”or“off”(selected/unselected)state –Foreach,theCheckedPropertyissettofalseifbuttonisunselectedandtrueifselected –IfAutoCheckpropertyistrue,statetoggleswhenuserclicks •RadioButtons –Almostalwaysusedinagroupboxfromwhichonlyonebuttoninthegroupcanbeselectedatatime •Mutuallyexclusiveoptions •Theyareallchildrenofthegroupbox…whichisachildoftheform –Displayedaslittlecircles •Selectedcirclehasadotinside •CheckBoxes –Ifenclosedinagroupbox,anynumberofthemcanbeselected –Displayedaslittleboxes •Selectedboxeshavecheckmarksinthem SomeCheckBoxPropertiesand Events CheckBoxeventsandproperties Description/DelegateandEventArguments CommonProperties Checked WhetherornottheCheckBoxhasbeenchecked. CheckState WhethertheCheckboxischecked(containsablackcheckmark)orunchecked(blank).AnenumerationwithvaluesChecked,UncheckedorIndeterminate. Text TextdisplayedtotherightoftheCheckBox(calledthelabel). CommonEvents (DelegateEventHandler,eventarguments EventArgs) CheckedChanged RaisedeverytimetheCheckboxiseithercheckedorunchecked.Defaulteventwhenthiscontrolisdoubleclickedinthedesigner. CheckStateChanged RaisedwhentheCheckStatepropertychanges.

  15. SomeRadioButtonProperties& Events RadioButtonDescription/DelegateandEventpropertiesandArguments eventsCommonProperties CheckedWhethertheRadioButtonischecked. TextTextdisplayedtotherightofthe CommonEvents(DelegateEventHandler,eventargumentsEventArgs) ClickRaisedwhenuserclicksthecontrol. CheckedChangedRaisedeverytimetheRadioButtonischeckedorunchecked.Defaulteventwhenthiscontrolisdoubleclickedinthedesigner. RadioButton(calledthelabel). Radio-CheckExampleProgram •Drawsopenorfilledrectanglesofdifferent colors •A‘ColorSelection’groupboxcontainingradio buttonsallowsusertoselectacolor •A‘FillRectangle’checkboxdetermineswhethertherectangleisfilledornot

More Related