C#学习笔记Form Class.docx
- 文档编号:29516599
- 上传时间:2023-07-24
- 格式:DOCX
- 页数:40
- 大小:40.13KB
C#学习笔记Form Class.docx
《C#学习笔记Form Class.docx》由会员分享,可在线阅读,更多相关《C#学习笔记Form Class.docx(40页珍藏版)》请在冰豆网上搜索。
C#学习笔记FormClass
2014-2-22
FormClass
Representsawindowordialogboxthatmakesupanapplication'suserinterface.
Namespace:
System.Windows.Forms
Assembly:
System.Windows.Forms (inSystem.Windows.Forms.dll)
Syntax:
publicclassForm:
ContainerControl
Remarks:
A Form isarepresentationofanywindowdisplayedinyourapplication. The Form classcanbeusedtocreatestandard,tool,borderless,andfloatingwindows. Youcanalsousethe Form classtocreatemodalwindowssuchasadialogbox. Aspecialkindofform,themultiple-documentinterface(MDI)form,cancontainotherformscalledMDIchildforms. AnMDIformiscreatedbysettingthe IsMdiContainer propertyto true. MDIchildformsarecreatedbysettingthe MdiParent propertytotheMDIparentformthatwillcontainthechildform.
Usingthepropertiesavailableinthe Form class,youcandeterminetheappearance,size,color,andwindowmanagementfeaturesofthewindowordialogboxyouarecreating.The Text propertyallowsyoutospecifythecaptionofthewindowinthetitlebar. The Size and DesktopLocation propertiesallowyoutodefinethesizeandpositionofthewindowwhenitisdisplayed. Youcanusethe ForeColor colorpropertytochangethedefaultforegroundcolorofallcontrolsplacedontheform. The FormBorderStyle,MinimizeBox,and MaximizeBox propertiesallowyoutocontrolwhethertheformcanbeminimized,maximized,orresizedatruntime.
Inadditiontoproperties,youcanusethemethodsoftheclasstomanipulateaform. Forexample,youcanusethe ShowDialog methodtoshowaformasamodaldialogbox.Youcanusethe SetDesktopLocation methodtopositiontheformonthedesktop.
Theeventsofthe Form classallowyoutorespondtoactionsperformedontheform. Youcanusethe Activated eventtoperformoperationssuchasupdatingthedatadisplayedinthecontrolsoftheformwhentheformisactivated.
Youcanuseaformasthestartingclassinyourapplicationbyplacingamethodcalled Main intheclass. Inthe Main methodaddcodetocreateandshowtheform. Youwillalsoneedtoaddthe STAThread attributetothe Main methodinorderfortheformtorun. Whenthestartingformisclosed,theapplicationisalsoclosed.
Ifyousetthe Enabled propertyto false beforethe Form isvisible(forexample,setting Enabled tofalseintheMicrosoftVisualStudiodesigner),theminimize,maximize,close,andsystembuttonsremainenabled. Ifyouset Enabled to false afterthe Form isvisible(forexample,whentheLoadeventoccurs),thebuttonsaredisabled.
Properties:
1、AcceptButton:
publicIButtonControl型,GetsorsetsthebuttonontheformthatisclickedwhentheuserpressestheENTERkey.
Remarks:
ThispropertyenablesyoutodesignateadefaultactiontooccurwhentheuserpressestheENTERkeyinyourapplication. Thebuttonassignedtothispropertymustbean IButtonControl thatisonthecurrentformorlocatedwithinacontaineronthecurrentform.
YoucanusethispropertytoallowtheusertoquicklynavigateasimpleformbyallowingthemtosimplypresstheENTERkeywhentheyarefinishedinsteadofmanuallyclickingtheacceptbuttonwiththeirmouse.
TheacceptbuttonmightnotbeactivatedifthecurrentlyselectedcontrolontheforminterceptstheENTERkeyandprocessesit. Forexample,amultilinetextboxcontrolallowstheENTERkeytobepressedwhenitisselectedtoinsertanewlinecharacterinthecontrol.
2、ActiveForm:
publicstaticForm型,Getsthecurrentlyactiveformforthisapplication.or null ifthereisnoactiveform.
Remarks:
Youcanusethismethodtoobtainareferencetothecurrentlyactiveformtoperformactionsontheformoritscontrols.Ifyourapplicationisamultiple-documentinterface(MDI)application,usethe ActiveMdiChild propertytoobtainthecurrentlyactiveMDIchildform.
3、ActiveMdiChild:
publicForm型,Getsthecurrentlyactivemultiple-documentinterface(MDI)childwindow;or null iftherearecurrentlynochildwindowspresent.
Remarks:
YoucanusethismethodtodeterminewhetherthereareanyMDIchildformsopeninyourMDIapplication. YoucanalsousethismethodtoperformoperationsonanMDIchildwindowfromitsMDIparentformorfromanotherformthatisdisplayedinyourapplication.IfthecurrentlyactiveformisnotanMDIchildform,youcanusethe ActiveForm propertytoobtainareferencetoit.
4、AutoScaleBaseSize:
publicvirtualSize型,Getsorsetsthebasesizeusedforautoscalingoftheform.
Remarks:
Important:
Thismemberhasbeenretainedforbackwardcompatibility. Formoreinformationaboutautomaticscaling,see AutomaticScalinginWindowsForms.
Thevalueofthe AutoScaleBaseSize propertyisusedatform-displaytimetocomputethescalingfactorfortheform. Theautoscalingbasesizeisusedbytheformasabaselineforcomparisontothesystem'sfontsizetodeterminehowmuchtoscaletheformwhenautoscalingisused. Ifyouwanttodeterminethesizeaformwillautoscaletobasedonaspecificfont,usethe GetAutoScaleSize method.
Note:
Thevalueofthispropertyisusedwhentheformisinitiallycreated. Oncethepropertyisset,itcannotbechanged.
5、AutoScroll:
publicoverridebool型,Getsorsetsavalueindicatingwhethertheformenablesautoscrolling.Thedefaultis false.
Remarks:
Ifthispropertyissetto true,scrollbarsaredisplayedontheformifanycontrolsarelocatedoutsidetheform'sclientregion. Additionally,whenautoscrollingison,theclientareaoftheformautomaticallyscrollstomakethecontrolwithinputfocusvisible.
Youcanusethispropertytopreventusersfromlosingtheabilitytoviewcontrolswhentheirvideoresolutionsettingsaresettoalowresolution.
6、AutoSize:
publicoverridebool型,Getsorsetsthemodebywhichtheformautomaticallyresizesitself.
AutoSizeModeEnumeration
SpecifieshowacontrolwillbehavewhenitsAutoSizepropertyisenabled.
Namespace:
System.Windows.Forms.
Assembly:
System.Windows.Forms(insystem.windows.forms.dll)
Syntax:
publicenumAutoSizeMode
Membername
Description
GrowAndShrink
Thecontrolgrowsorshrinkstofititscontents.Thecontrolcannotberesizedmanually.
GrowOnly
ThecontrolgrowsasmuchasnecessarytofititscontentsbutdoesnotshrinksmallerthanthevalueofitsSizeproperty.Theformcanberesized,butconnotbemadesosmallthatanyofitscontainedcontrolsarehidden.
Remarks:
SettingtheGrowAndShrinkvalueproducesthesamebehaviorthatyougetforcontrolswiththeAutoSizepropertyenabledbutwhichhavenoAutoSizeModeproperty.TheMinimumSizeandMaximumSizepropertiesarerespected,butthecurrentvalueoftheSizepropertyisignored.
7、AutoSizeMode:
publicAutoSizeMode型,Getsorsetsthemodebywhichtheformautomaticallyresizesitself.Thedefaultis GrowOnly.
Remarks:
Settingthe AutoSizeMode propertytoanewvaluecausestheformtobelaidoutagain.
AformdoesnotautomaticallyresizeintheVisualStudioformsdesigner,regardlessofthevaluesofthe AutoSize and AutoSizeMode properties. Theformcorrectlyresizesitselfatruntimeaccordingtothevaluesofthesetwoproperties. Bycontrast,acustom UserControl automaticallyresizesitselfbothatdesigntimeandatruntime.
8、AutoValidate:
publicoverrideAutoValidate型,Getsorsetsavaluethatindicateswhethercontrolsinthiscontainerwillbeautomaticallyvalidatedwhenthefocuschanges.Thedefaultis Inherit.
9、BackColor:
publicoverrideColor型,Getsorsetsthebackgroundcolorforthecontrol.Thedefaultisthevalueofthe DefaultBackColor property.
10、CancelButton:
publicIButtonControl型,GetsorsetsthebuttoncontrolthatisclickedwhentheuserpressestheESCkey.
Remarks:
ThecancelbuttonforaformisthebuttoncontrolthatisclickedwhenevertheuserpressestheESCkey. ThebuttonassignedtothispropertymustbeanIButtonControl thatisonthecurrentformorlocatedwithinacontaineronthecurrentform.
ThispropertyallowsyoutodesignateadefaultactiontooccurwhentheuserpressestheESCkeyinyourapplication. YoucanusethispropertytoallowtheusertoquicklynavigateasimpleformbyallowingthemtosimplypresstheESCkeytocloseawindowwithoutcommittingchangesinsteadofmanuallyclickingthecancelbuttonwiththeirmouse.
CancelButton maynotworkifanothercontrolontheforminterceptstheESCkey. Forexample,ifyouhavea ComboBox openonyourform,ESCwillclosethe ComboBox insteadofclosingtheForm.
The IButtonControl objectassignedto CancelButton mustbevisibleontheform,orelsepressingtheESCkeywillhavenoeffect.
11、ClientSize:
publicSize型,Getsorsetsthesizeoftheclientareaoftheform.
Remarks:
Thesizeoftheclientareaoftheformisthesizeoftheformexcludingthebordersandthetitlebar. Theclientareaofaformistheareawithinaformwherecontrolscanbeplaced. Youcanusethispropertytogettheproperdimensionswhenperforminggraphicsoperationsorwhensizingandpositioningcontrolsontheform. Togetthesizeoftheentireform,usethe Size propertyorusetheindividualproperties Height and Width.
Note:
Youcannotcurrentlybindtothispropertyusingapplicationsettings. Formoreinformationonapplicationsettings,see ApplicationSettingsOverview.
12、ControlBox:
publicbool型,Getsorsetsavalueindicatingwhetheracontrolboxisdisplayedinthecaptionbaroftheform. Thedefaultis true.
Remarks:
Ifthe ControlBox propertyissetto true,thecontrolboxisdisplayedintheupper-leftcornerofthecaptionbar. Thecontrolboxiswheretheusercanclicktoaccessthesystemmenu.Ifyouset ControlBox to false,andalsosetthe Location property,the Size propertyofFormwillnotupdatetoreflectthatthenon-c
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C#学习笔记Form Class C# 学习 笔记 Form