C#学习笔记Form Class.docx

上传人:b****5 文档编号:29516599 上传时间:2023-07-24 格式:DOCX 页数:40 大小:40.13KB
下载 相关 举报
C#学习笔记Form Class.docx_第1页
第1页 / 共40页
C#学习笔记Form Class.docx_第2页
第2页 / 共40页
C#学习笔记Form Class.docx_第3页
第3页 / 共40页
C#学习笔记Form Class.docx_第4页
第4页 / 共40页
C#学习笔记Form Class.docx_第5页
第5页 / 共40页
点击查看更多>>
下载资源
资源描述

C#学习笔记Form Class.docx

《C#学习笔记Form Class.docx》由会员分享,可在线阅读,更多相关《C#学习笔记Form Class.docx(40页珍藏版)》请在冰豆网上搜索。

C#学习笔记Form Class.docx

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

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 社交礼仪

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1