FormTest.cs 116 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018
  1. //
  2. // FormTest.cs: Test cases for Form.
  3. //
  4. // Author:
  5. // Ritvik Mayank ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc. (http://www.novell.com)
  8. //
  9. using System;
  10. using System.ComponentModel;
  11. using System.Drawing;
  12. using System.Reflection;
  13. using System.Windows.Forms;
  14. using System.Collections;
  15. using NUnit.Framework;
  16. using CategoryAttribute = NUnit.Framework.CategoryAttribute;
  17. namespace MonoTests.System.Windows.Forms
  18. {
  19. [TestFixture]
  20. public class FormTest : TestHelper
  21. {
  22. [Test]
  23. public void AcceptButton ()
  24. {
  25. Form form = new Form ();
  26. Assert.IsNull (form.AcceptButton, "#A");
  27. MockButton buttonA = new MockButton (true);
  28. Assert.IsFalse (buttonA.IsDefaultButton, "#B1");
  29. form.AcceptButton = buttonA;
  30. Assert.IsNotNull (form.AcceptButton, "#B2");
  31. Assert.AreSame (buttonA, form.AcceptButton, "#B3");
  32. Assert.IsTrue (buttonA.IsDefaultButton, "#B4");
  33. form.AcceptButton = null;
  34. Assert.IsNull (form.AcceptButton, "#C1");
  35. Assert.IsFalse (buttonA.IsDefaultButton, "#C2");
  36. ButtonControl buttonB = new ButtonControl ();
  37. Assert.IsFalse (buttonB.IsDefaultButton, "#D1");
  38. form.AcceptButton = buttonB;
  39. Assert.IsNotNull (form.AcceptButton, "#D2");
  40. Assert.AreSame (buttonB, form.AcceptButton, "#D3");
  41. Assert.IsFalse (buttonA.IsDefaultButton, "#D4");
  42. Assert.IsTrue (buttonB.IsDefaultButton, "#D5");
  43. MockButton buttonC = new MockButton (false);
  44. Assert.IsFalse (buttonC.IsDefaultButton, "#E1");
  45. form.AcceptButton = buttonC;
  46. Assert.IsNotNull (form.AcceptButton, "#E2");
  47. Assert.AreSame (buttonC, form.AcceptButton, "#E3");
  48. Assert.IsFalse (buttonC.IsDefaultButton, "#E4");
  49. Assert.IsFalse (buttonA.IsDefaultButton, "#E5");
  50. Assert.IsFalse (buttonB.IsDefaultButton, "#E6");
  51. }
  52. [Test]
  53. public void bug_82358 ()
  54. {
  55. //Console.WriteLine ("Starting bug_82358");
  56. int sizeable_factor;
  57. int title_bar;
  58. int tool_bar;
  59. int tool_border;
  60. int d3;
  61. int d2;
  62. // WinXP, default theme
  63. sizeable_factor = 2;
  64. title_bar = 26;
  65. tool_bar = 18;
  66. tool_border = 6;
  67. d3 = 10;
  68. d2 = 6;
  69. // WinXP, Win32 theme:
  70. sizeable_factor = 2;
  71. title_bar = 19;
  72. tool_bar = 16;
  73. tool_border = 6;
  74. d3 = 10;
  75. d2 = 6;
  76. Size size = new Size (200, 200);
  77. // Universal theme??
  78. using (Form f = new Form ()) {
  79. f.FormBorderStyle = FormBorderStyle.FixedSingle;
  80. f.Visible = true;
  81. d2 = f.Size.Width - f.ClientSize.Width;
  82. title_bar = f.Size.Height - f.ClientSize.Height - d2;
  83. }
  84. using (Form f = new Form ()) {
  85. f.FormBorderStyle = FormBorderStyle.Sizable;
  86. f.Visible = true;
  87. sizeable_factor = f.Size.Width - f.ClientSize.Width - d2;
  88. }
  89. using (Form f = new Form ()) {
  90. f.ClientSize = size;
  91. f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
  92. //f.Visible = true;
  93. tool_border = f.Size.Width - f.ClientSize.Width;
  94. tool_bar = f.Size.Height - f.ClientSize.Height - tool_border;
  95. }
  96. using (Form f = new Form ()) {
  97. f.FormBorderStyle = FormBorderStyle.Fixed3D;
  98. f.Visible = true;
  99. d3 = f.Size.Width - f.ClientSize.Width;
  100. }
  101. FormBorderStyle style;
  102. //Console.WriteLine ("Universal theme says: d2={0}, d3={1}, title_bar={2}, sizeable_factor={3}, tool_border={4}, tool_bar={5}", d2, d3, title_bar, sizeable_factor, tool_border, tool_bar);
  103. // Changing client size, then FormBorderStyle.
  104. using (Form f = new Form ()) {
  105. style = FormBorderStyle.FixedToolWindow;
  106. //Console.WriteLine ("Created form, size: {0}, clientsize: {1}", f.Size, f.ClientSize);
  107. f.ClientSize = size;
  108. //Console.WriteLine ("Changed ClientSize, size: {0}, clientsize: {1}", f.Size, f.ClientSize);
  109. f.FormBorderStyle = style;
  110. //Console.WriteLine ("Changed FormBorderStyle, size: {0}, clientsize: {1}", f.Size, f.ClientSize);
  111. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
  112. Assert.AreEqual (new Size (size.Width + tool_border, size.Height + tool_border + tool_bar).ToString (), f.Size.ToString (), style.ToString () + "-A2");
  113. f.Visible = true;
  114. //Console.WriteLine ("Made visible, size: {0}, clientsize: {1}", f.Size, f.ClientSize);
  115. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
  116. Assert.AreEqual (new Size (size.Width + tool_border, size.Height + tool_border + tool_bar).ToString (), f.Size.ToString (), style.ToString () + "-A4");
  117. }
  118. using (Form f = new Form ()) {
  119. style = FormBorderStyle.SizableToolWindow;
  120. f.ClientSize = size;
  121. f.FormBorderStyle = style;
  122. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
  123. Assert.AreEqual (new Size (size.Width + tool_border + sizeable_factor, size.Height + tool_border + tool_bar + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-A2");
  124. f.Visible = true;
  125. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
  126. Assert.AreEqual (new Size (size.Width + tool_border + sizeable_factor, size.Height + tool_border + tool_bar + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-A4");
  127. }
  128. using (Form f = new Form ()) {
  129. style = FormBorderStyle.Fixed3D;
  130. f.ClientSize = size;
  131. f.FormBorderStyle = style;
  132. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
  133. Assert.AreEqual (new Size (size.Width + d3, size.Height + title_bar + d3).ToString () , f.Size.ToString (), style.ToString () + "-A2");
  134. f.Visible = true;
  135. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
  136. Assert.AreEqual (new Size (size.Width + d3, size.Height + title_bar + d3).ToString (), f.Size.ToString (), style.ToString () + "-A4");
  137. }
  138. using (Form f = new Form ()) {
  139. style = FormBorderStyle.FixedDialog;
  140. f.ClientSize = size;
  141. f.FormBorderStyle = style;
  142. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
  143. Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-A2");
  144. f.Visible = true;
  145. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
  146. Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-A4");
  147. }
  148. using (Form f = new Form ()) {
  149. style = FormBorderStyle.FixedSingle;
  150. f.ClientSize = size;
  151. f.FormBorderStyle = style;
  152. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
  153. Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-A2");
  154. f.Visible = true;
  155. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
  156. Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-A4");
  157. }
  158. using (Form f = new Form ()) {
  159. style = FormBorderStyle.None;
  160. f.ClientSize = size;
  161. f.FormBorderStyle = style;
  162. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
  163. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-A2");
  164. f.Visible = true;
  165. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
  166. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-A4");
  167. }
  168. using (Form f = new Form ()) {
  169. style = FormBorderStyle.Sizable;
  170. f.ClientSize = size;
  171. f.FormBorderStyle = style;
  172. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
  173. Assert.AreEqual (new Size (size.Width + d2 + sizeable_factor, size.Height + title_bar + d2 + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-A2");
  174. f.Visible = true;
  175. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
  176. Assert.AreEqual (new Size (size.Width + d2 + sizeable_factor, size.Height + title_bar + d2 + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-A4");
  177. }
  178. // Changing size, then FormBorderStyle.
  179. using (Form f = new Form ()) {
  180. style = FormBorderStyle.FixedToolWindow;
  181. f.Size = size;
  182. f.FormBorderStyle = style;
  183. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
  184. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
  185. f.Visible = true;
  186. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
  187. Assert.AreEqual (new Size (size.Width - tool_border, size.Height - tool_border - tool_bar).ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
  188. }
  189. using (Form f = new Form ()) {
  190. style = FormBorderStyle.SizableToolWindow;
  191. f.Size = size;
  192. f.FormBorderStyle = style;
  193. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
  194. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
  195. f.Visible = true;
  196. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
  197. Assert.AreEqual (new Size (size.Width - tool_border - sizeable_factor, size.Height - tool_border - tool_bar - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
  198. }
  199. using (Form f = new Form ()) {
  200. style = FormBorderStyle.Fixed3D;
  201. f.Size = size;
  202. f.FormBorderStyle = style;
  203. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
  204. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
  205. f.Visible = true;
  206. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
  207. Assert.AreEqual (new Size (size.Width - d3, size.Height - title_bar - d3).ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
  208. }
  209. using (Form f = new Form ()) {
  210. style = FormBorderStyle.FixedDialog;
  211. f.Size = size;
  212. f.FormBorderStyle = style;
  213. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
  214. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
  215. f.Visible = true;
  216. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
  217. Assert.AreEqual (new Size (size.Width - d2, size.Height - title_bar - d2).ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
  218. }
  219. using (Form f = new Form ()) {
  220. style = FormBorderStyle.FixedSingle;
  221. f.Size = size;
  222. f.FormBorderStyle = style;
  223. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
  224. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
  225. f.Visible = true;
  226. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
  227. Assert.AreEqual (new Size (size.Width - d2, size.Height - title_bar - d2).ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
  228. }
  229. using (Form f = new Form ()) {
  230. style = FormBorderStyle.None;
  231. f.Size = size;
  232. f.FormBorderStyle = style;
  233. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
  234. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
  235. f.Visible = true;
  236. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
  237. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
  238. }
  239. using (Form f = new Form ()) {
  240. style = FormBorderStyle.Sizable;
  241. f.Size = size;
  242. f.FormBorderStyle = style;
  243. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
  244. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
  245. f.Visible = true;
  246. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
  247. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
  248. }
  249. // Changing FormBorderStyle, then client size
  250. using (Form f = new Form ()) {
  251. style = FormBorderStyle.FixedToolWindow;
  252. f.FormBorderStyle = style;
  253. f.ClientSize = size;
  254. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
  255. Assert.AreEqual (new Size (size.Width + tool_border, size.Height + tool_border + tool_bar).ToString (), f.Size.ToString (), style.ToString () + "-C2");
  256. f.Visible = true;
  257. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
  258. Assert.AreEqual (new Size (size.Width + tool_border, size.Height + tool_border + tool_bar).ToString (), f.Size.ToString (), style.ToString () + "-C4");
  259. }
  260. using (Form f = new Form ()) {
  261. style = FormBorderStyle.SizableToolWindow;
  262. f.FormBorderStyle = style;
  263. f.ClientSize = size;
  264. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
  265. Assert.AreEqual (new Size (size.Width + tool_border + sizeable_factor, size.Height + tool_border + tool_bar + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-C2");
  266. f.Visible = true;
  267. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
  268. Assert.AreEqual (new Size (size.Width + tool_border + sizeable_factor, size.Height + tool_border + tool_bar + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-C4");
  269. }
  270. using (Form f = new Form ()) {
  271. style = FormBorderStyle.Fixed3D;
  272. f.FormBorderStyle = style;
  273. f.ClientSize = size;
  274. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
  275. Assert.AreEqual (new Size (size.Width + d3, size.Height + title_bar + d3).ToString (), f.Size.ToString (), style.ToString () + "-C2");
  276. f.Visible = true;
  277. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
  278. Assert.AreEqual (new Size (size.Width + d3, size.Height + title_bar + d3).ToString (), f.Size.ToString (), style.ToString () + "-C4");
  279. }
  280. using (Form f = new Form ()) {
  281. style = FormBorderStyle.FixedDialog;
  282. f.FormBorderStyle = style;
  283. f.ClientSize = size;
  284. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
  285. Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-C2");
  286. f.Visible = true;
  287. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
  288. Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-C4");
  289. }
  290. using (Form f = new Form ()) {
  291. style = FormBorderStyle.FixedSingle;
  292. f.FormBorderStyle = style;
  293. f.ClientSize = size;
  294. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
  295. Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-C2");
  296. f.Visible = true;
  297. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
  298. Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-C4");
  299. }
  300. using (Form f = new Form ()) {
  301. style = FormBorderStyle.None;
  302. f.FormBorderStyle = style;
  303. f.ClientSize = size;
  304. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
  305. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-C2");
  306. f.Visible = true;
  307. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
  308. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-C4");
  309. }
  310. using (Form f = new Form ()) {
  311. style = FormBorderStyle.Sizable;
  312. f.FormBorderStyle = style;
  313. f.ClientSize = size;
  314. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
  315. Assert.AreEqual (new Size (size.Width + d2 + sizeable_factor, size.Height + title_bar + d2 + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-C2");
  316. f.Visible = true;
  317. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
  318. Assert.AreEqual (new Size (size.Width + d2 + sizeable_factor, size.Height + title_bar + d2 + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-C4");
  319. }
  320. // Changing FormBorderStyle, then size
  321. using (Form f = new Form ()) {
  322. style = FormBorderStyle.FixedToolWindow;
  323. f.FormBorderStyle = style;
  324. f.Size = size;
  325. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D1");
  326. Assert.AreEqual (new Size (size.Width - tool_border, size.Height - tool_border - tool_bar).ToString (), f.ClientSize.ToString (), style.ToString () + "-D2");
  327. f.Visible = true;
  328. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D3");
  329. Assert.AreEqual (new Size (size.Width - tool_border, size.Height - tool_border - tool_bar).ToString (), f.ClientSize.ToString (), style.ToString () + "-D4");
  330. }
  331. using (Form f = new Form ()) {
  332. style = FormBorderStyle.SizableToolWindow;
  333. f.FormBorderStyle = style;
  334. f.Size = size;
  335. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D1");
  336. Assert.AreEqual (new Size (size.Width - tool_border - sizeable_factor, size.Height - tool_border - tool_bar - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-D2");
  337. f.Visible = true;
  338. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D3");
  339. Assert.AreEqual (new Size (size.Width - tool_border - sizeable_factor, size.Height - tool_border - tool_bar - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-D4");
  340. }
  341. using (Form f = new Form ()) {
  342. style = FormBorderStyle.Fixed3D;
  343. f.FormBorderStyle = style;
  344. f.Size = size;
  345. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D1");
  346. Assert.AreEqual (new Size (size.Width - d3, size.Height - title_bar - d3).ToString (), f.ClientSize.ToString (), style.ToString () + "-D2");
  347. f.Visible = true;
  348. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D3");
  349. Assert.AreEqual (new Size (size.Width - d3, size.Height - title_bar - d3).ToString (), f.ClientSize.ToString (), style.ToString () + "-D4");
  350. }
  351. using (Form f = new Form ()) {
  352. style = FormBorderStyle.FixedDialog;
  353. f.FormBorderStyle = style;
  354. f.Size = size;
  355. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D1");
  356. Assert.AreEqual (new Size (size.Width - d2, size.Height - title_bar - d2).ToString (), f.ClientSize.ToString (), style.ToString () + "-D2");
  357. f.Visible = true;
  358. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D3");
  359. Assert.AreEqual (new Size (size.Width - d2, size.Height - title_bar - d2).ToString (), f.ClientSize.ToString (), style.ToString () + "-D4");
  360. }
  361. using (Form f = new Form ()) {
  362. style = FormBorderStyle.FixedSingle;
  363. f.FormBorderStyle = style;
  364. f.Size = size;
  365. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D1");
  366. Assert.AreEqual (new Size (size.Width - d2, size.Height - title_bar - d2).ToString (), f.ClientSize.ToString (), style.ToString () + "-D2");
  367. f.Visible = true;
  368. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D3");
  369. Assert.AreEqual (new Size (size.Width - d2, size.Height - title_bar - d2).ToString (), f.ClientSize.ToString (), style.ToString () + "-D4");
  370. }
  371. using (Form f = new Form ()) {
  372. style = FormBorderStyle.None;
  373. f.FormBorderStyle = style;
  374. f.Size = size;
  375. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-D1");
  376. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D2");
  377. f.Visible = true;
  378. Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-D3");
  379. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D4");
  380. }
  381. using (Form f = new Form ()) {
  382. style = FormBorderStyle.Sizable;
  383. f.FormBorderStyle = style;
  384. f.Size = size;
  385. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D1");
  386. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-D2");
  387. f.Visible = true;
  388. Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D3");
  389. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-D4");
  390. }
  391. // Set clientsize, then change size, then FormBorderStyle.
  392. using (Form f = new Form ()) {
  393. style = FormBorderStyle.FixedToolWindow;
  394. f.ClientSize = f.ClientSize;
  395. f.Size = size;
  396. f.FormBorderStyle = style;
  397. // Here we subtract the Sizable borders (default) then add FixedToolWindow's border.
  398. // Note how now the sizes doesn't change when creating the handle.
  399. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + tool_border, size.Height - title_bar - d2 - sizeable_factor + tool_border + tool_bar).ToString (), f.Size.ToString (), style.ToString () + "-E1");
  400. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
  401. f.Visible = true;
  402. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + tool_border, size.Height - title_bar - d2 - sizeable_factor + tool_border + tool_bar).ToString (), f.Size.ToString (), style.ToString () + "-E3");
  403. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
  404. }
  405. using (Form f = new Form ()) {
  406. style = FormBorderStyle.SizableToolWindow;
  407. f.ClientSize = f.ClientSize;
  408. f.Size = size;
  409. f.FormBorderStyle = style;
  410. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + tool_border + sizeable_factor, size.Height - title_bar - d2 - sizeable_factor + tool_border + tool_bar + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-E1");
  411. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
  412. f.Visible = true;
  413. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + tool_border + sizeable_factor, size.Height - title_bar - d2 - sizeable_factor + tool_border + tool_bar + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-E3");
  414. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
  415. }
  416. using (Form f = new Form ()) {
  417. style = FormBorderStyle.Fixed3D;
  418. f.ClientSize = f.ClientSize;
  419. f.Size = size;
  420. f.FormBorderStyle = style;
  421. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + d3, size.Height - title_bar - d2 - sizeable_factor + title_bar + d3).ToString (), f.Size.ToString (), style.ToString () + "-E1");
  422. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
  423. f.Visible = true;
  424. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + d3, size.Height - title_bar - d2 - sizeable_factor + title_bar + d3).ToString (), f.Size.ToString (), style.ToString () + "-E3");
  425. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
  426. }
  427. using (Form f = new Form ()) {
  428. style = FormBorderStyle.FixedDialog;
  429. f.ClientSize = f.ClientSize;
  430. f.Size = size;
  431. f.FormBorderStyle = style;
  432. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + d2, size.Height - title_bar - d2 - sizeable_factor + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-E1");
  433. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
  434. f.Visible = true;
  435. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + d2, size.Height - title_bar - d2 - sizeable_factor + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-E3");
  436. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
  437. }
  438. using (Form f = new Form ()) {
  439. style = FormBorderStyle.FixedSingle;
  440. f.ClientSize = f.ClientSize;
  441. f.Size = size;
  442. f.FormBorderStyle = style;
  443. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + d2, size.Height - title_bar - d2 - sizeable_factor + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-E1");
  444. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
  445. f.Visible = true;
  446. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + d2, size.Height - title_bar - d2 - sizeable_factor + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-E3");
  447. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
  448. }
  449. using (Form f = new Form ()) {
  450. style = FormBorderStyle.None;
  451. f.ClientSize = f.ClientSize;
  452. f.Size = size;
  453. f.FormBorderStyle = style;
  454. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-E1");
  455. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
  456. f.Visible = true;
  457. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-E3");
  458. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
  459. }
  460. using (Form f = new Form ()) {
  461. style = FormBorderStyle.Sizable;
  462. f.ClientSize = f.ClientSize;
  463. f.Size = size;
  464. f.FormBorderStyle = style;
  465. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + d2 + sizeable_factor, size.Height - title_bar - d2 - sizeable_factor + d2 + sizeable_factor + title_bar).ToString (), f.Size.ToString (), style.ToString () + "-E1");
  466. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
  467. f.Visible = true;
  468. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + d2 + sizeable_factor, size.Height - title_bar - d2 - sizeable_factor + d2 + sizeable_factor + title_bar).ToString (), f.Size.ToString (), style.ToString () + "-E3");
  469. Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
  470. }
  471. }
  472. [Test] // bug 81969
  473. public void StartPositionClosedForm ()
  474. {
  475. using (Form form = new Form ()) {
  476. form.StartPosition = FormStartPosition.CenterParent;
  477. form.Load += new EventHandler (CenterDisposedForm_Load);
  478. form.Show ();
  479. }
  480. using (Form form = new Form ()) {
  481. form.StartPosition = FormStartPosition.CenterScreen;
  482. form.Load += new EventHandler (CenterDisposedForm_Load);
  483. form.Show ();
  484. }
  485. using (Form form = new Form ()) {
  486. form.StartPosition = FormStartPosition.Manual;
  487. form.Load += new EventHandler (CenterDisposedForm_Load);
  488. form.Show ();
  489. }
  490. using (Form form = new Form ()) {
  491. form.StartPosition = FormStartPosition.WindowsDefaultBounds;
  492. form.Load += new EventHandler (CenterDisposedForm_Load);
  493. form.Show ();
  494. }
  495. using (Form form = new Form ()) {
  496. form.StartPosition = FormStartPosition.WindowsDefaultLocation;
  497. form.Load += new EventHandler (CenterDisposedForm_Load);
  498. form.Show ();
  499. }
  500. }
  501. [Test]
  502. [ExpectedException (typeof (ObjectDisposedException))]
  503. public void CenterToParentDisposedForm ()
  504. {
  505. using (FormHandleTest.ProtectedMethodsForm form = new FormHandleTest.ProtectedMethodsForm ()) {
  506. form.Dispose ();
  507. form.PublicCenterToParent ();
  508. }
  509. }
  510. [Test]
  511. [ExpectedException (typeof (ObjectDisposedException))]
  512. public void CenterToScreenDisposedForm ()
  513. {
  514. using (FormHandleTest.ProtectedMethodsForm form = new FormHandleTest.ProtectedMethodsForm ()) {
  515. form.Dispose ();
  516. form.PublicCenterToScreen ();
  517. }
  518. }
  519. [Test]
  520. public void SetStartPositionDisposedForm ()
  521. {
  522. using (FormHandleTest.ProtectedMethodsForm form = new FormHandleTest.ProtectedMethodsForm ()) {
  523. form.Dispose ();
  524. form.StartPosition = FormStartPosition.WindowsDefaultLocation;
  525. }
  526. }
  527. private void CenterDisposedForm_Load (object sender, EventArgs e)
  528. {
  529. ((Form) sender).Close ();
  530. }
  531. [Test]
  532. public void ShowDialogCloseTest ()
  533. {
  534. using (TimeBombedForm f = new TimeBombedForm ()) {
  535. EventLogger log = new EventLogger (f);
  536. f.timer.Interval = 1000;
  537. f.VisibleChanged += new EventHandler (Form_VisibleChanged1);
  538. f.ShowDialog ();
  539. Assert.AreEqual ("VisibleChanged", f.Reason, "#00");
  540. Assert.AreEqual (1, log.CountEvents ("Closing"), "#01");
  541. #if NET_2_0
  542. Assert.AreEqual (1, log.CountEvents ("FormClosing"), "#02");
  543. #endif
  544. Assert.AreEqual (1, log.CountEvents ("HandleDestroyed"), "#03");
  545. Assert.AreEqual (0, log.CountEvents ("Closed"), "#04");
  546. #if NET_2_0
  547. Assert.AreEqual (0, log.CountEvents ("FormClosed"), "#05");
  548. #endif
  549. Assert.AreEqual (0, log.CountEvents ("Disposed"), "#06");
  550. }
  551. using (TimeBombedForm f = new TimeBombedForm ()) {
  552. EventLogger log = new EventLogger (f);
  553. f.ShowDialog ();
  554. Assert.AreEqual ("Bombed", f.Reason, "#A0");
  555. Assert.AreEqual (1, log.CountEvents ("Closing"), "#A1");
  556. #if NET_2_0
  557. Assert.AreEqual (1, log.CountEvents ("FormClosing"), "#A2");
  558. #endif
  559. Assert.AreEqual (1, log.CountEvents ("HandleDestroyed"), "#A3");
  560. Assert.AreEqual (1, log.CountEvents ("Closed"), "#A4");
  561. #if NET_2_0
  562. Assert.AreEqual (1, log.CountEvents ("FormClosed"), "#A5");
  563. #endif
  564. Assert.AreEqual (0, log.CountEvents ("Disposed"), "#A6");
  565. }
  566. using (TimeBombedForm f = new TimeBombedForm ()) {
  567. EventLogger log = new EventLogger (f);
  568. f.VisibleChanged += new EventHandler (Form_VisibleChanged2);
  569. f.ShowDialog ();
  570. Assert.AreEqual ("VisibleChanged", f.Reason, "#B0");
  571. #if NET_2_0
  572. Assert.AreEqual (1, log.CountEvents ("Closing"), "#B1");
  573. Assert.AreEqual (1, log.CountEvents ("FormClosing"), "#B2");
  574. #endif
  575. Assert.AreEqual (1, log.CountEvents ("HandleDestroyed"), "#B3");
  576. #if NET_2_0
  577. Assert.AreEqual (1, log.CountEvents ("Closed"), "#B4");
  578. Assert.AreEqual (1, log.CountEvents ("FormClosed"), "#B5");
  579. #endif
  580. Assert.AreEqual (0, log.CountEvents ("Disposed"), "#B6");
  581. }
  582. using (TimeBombedForm f = new TimeBombedForm ()) {
  583. EventLogger log = new EventLogger (f);
  584. f.DialogResult = DialogResult.None;
  585. f.ShowDialog ();
  586. Assert.AreEqual ("Bombed", f.Reason, "#C0");
  587. Assert.AreEqual (1, log.CountEvents ("Closing"), "#C1");
  588. #if NET_2_0
  589. Assert.AreEqual (1, log.CountEvents ("FormClosing"), "#C2");
  590. #endif
  591. Assert.AreEqual (1, log.CountEvents ("HandleDestroyed"), "#C3");
  592. Assert.AreEqual (1, log.CountEvents ("Closed"), "#C4");
  593. #if NET_2_0
  594. Assert.AreEqual (1, log.CountEvents ("FormClosed"), "#C5");
  595. #endif
  596. Assert.AreEqual (0, log.CountEvents ("Disposed"), "#C6");
  597. Assert.AreEqual (DialogResult.Cancel, f.DialogResult, "#C7");
  598. }
  599. }
  600. void Form_VisibleChanged1 (object sender, EventArgs e)
  601. {
  602. TimeBombedForm f = (TimeBombedForm) sender;
  603. f.Reason = "VisibleChanged";
  604. f.Visible = false;
  605. }
  606. void Form_VisibleChanged2 (object sender, EventArgs e)
  607. {
  608. TimeBombedForm f = (TimeBombedForm) sender;
  609. f.Reason = "VisibleChanged";
  610. f.Visible = false;
  611. f.DialogResult = DialogResult.OK;
  612. Assert.IsFalse (f.Visible);
  613. }
  614. [Test]
  615. public void DialogOwnerTest ()
  616. {
  617. using (Form first = new Form ()) {
  618. using (TimeBombedForm second = new TimeBombedForm ()) {
  619. first.Show ();
  620. second.Load += new EventHandler (second_Load);
  621. second.ShowDialog ();
  622. }
  623. }
  624. }
  625. void second_Load (object sender, EventArgs e)
  626. {
  627. Form second = (Form) sender;
  628. Assert.IsNull (second.Owner, "#1");
  629. }
  630. [Test]
  631. [Category ("NotWorking")]
  632. public void FormStartupPositionChangeTest ()
  633. {
  634. using (Form frm = new Form ())
  635. {
  636. frm.ShowInTaskbar = false;
  637. frm.StartPosition = FormStartPosition.Manual;
  638. frm.Location = new Point (0, 0);
  639. frm.Show ();
  640. // On X there seem to be pending messages in the queue aren't processed
  641. // before Show returns, so process them. Otherwise the Location returns
  642. // something like (5,23)
  643. Application.DoEvents ();
  644. Assert.AreEqual ("{X=0,Y=0}", frm.Location.ToString (), "#01");
  645. frm.StartPosition = FormStartPosition.CenterParent;
  646. Assert.AreEqual ("{X=0,Y=0}", frm.Location.ToString (), "#02");
  647. frm.StartPosition = FormStartPosition.CenterScreen;
  648. Assert.AreEqual ("{X=0,Y=0}", frm.Location.ToString (), "#03");
  649. frm.StartPosition = FormStartPosition.Manual;
  650. Assert.AreEqual ("{X=0,Y=0}", frm.Location.ToString (), "#04");
  651. frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
  652. Assert.AreEqual ("{X=0,Y=0}", frm.Location.ToString (), "#05");
  653. frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
  654. Assert.AreEqual ("{X=0,Y=0}", frm.Location.ToString (), "#06");
  655. }
  656. }
  657. [Test]
  658. public void FormStartupPositionTest ()
  659. {
  660. CreateParams cp;
  661. using (Form frm = new Form ())
  662. {
  663. cp = TestHelper.GetCreateParams (frm);
  664. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$01");
  665. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#01");
  666. frm.StartPosition = FormStartPosition.CenterParent;
  667. cp = TestHelper.GetCreateParams (frm);
  668. Assert.AreEqual (FormStartPosition.CenterParent, frm.StartPosition, "$01");
  669. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#02");
  670. frm.StartPosition = FormStartPosition.CenterScreen;
  671. cp = TestHelper.GetCreateParams (frm);
  672. Assert.AreEqual (FormStartPosition.CenterScreen, frm.StartPosition, "$01");
  673. Assert.AreEqual (new Point (Screen.PrimaryScreen.WorkingArea.Width / 2 - frm.Width / 2, Screen.PrimaryScreen.WorkingArea.Height / 2 - frm.Height / 2).ToString (), new Point (cp.X, cp.Y).ToString (), "#03");
  674. frm.StartPosition = FormStartPosition.Manual;
  675. cp = TestHelper.GetCreateParams (frm);
  676. Assert.AreEqual (FormStartPosition.Manual, frm.StartPosition, "$01");
  677. Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#04");
  678. frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
  679. cp = TestHelper.GetCreateParams (frm);
  680. Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, frm.StartPosition, "$01");
  681. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#05");
  682. frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
  683. cp = TestHelper.GetCreateParams (frm);
  684. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$01");
  685. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#06");
  686. }
  687. using (Form frm = new Form ()) {
  688. frm.Location = new Point (23, 45);
  689. cp = TestHelper.GetCreateParams (frm);
  690. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$A1");
  691. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#A1");
  692. frm.StartPosition = FormStartPosition.CenterParent;
  693. cp = TestHelper.GetCreateParams (frm);
  694. Assert.AreEqual (FormStartPosition.CenterParent, frm.StartPosition, "$A2");
  695. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#A2");
  696. frm.StartPosition = FormStartPosition.CenterScreen;
  697. cp = TestHelper.GetCreateParams (frm);
  698. Assert.AreEqual (FormStartPosition.CenterScreen, frm.StartPosition, "$A3");
  699. Assert.AreEqual (new Point (Screen.PrimaryScreen.WorkingArea.Width / 2 - frm.Width / 2, Screen.PrimaryScreen.WorkingArea.Height / 2 - frm.Height / 2).ToString (), new Point (cp.X, cp.Y).ToString (), "#A3");
  700. frm.StartPosition = FormStartPosition.Manual;
  701. cp = TestHelper.GetCreateParams (frm);
  702. Assert.AreEqual (FormStartPosition.Manual, frm.StartPosition, "$A4");
  703. Assert.AreEqual (new Point (23, 45).ToString (), new Point (cp.X, cp.Y).ToString (), "#A4");
  704. frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
  705. cp = TestHelper.GetCreateParams (frm);
  706. Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, frm.StartPosition, "$A5");
  707. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#A5");
  708. frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
  709. cp = TestHelper.GetCreateParams (frm);
  710. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$A6");
  711. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#A6");
  712. }
  713. }
  714. [Test]
  715. public void MdiFormStartupPositionTest ()
  716. {
  717. CreateParams cp;
  718. using (Form Main = new Form ()) {
  719. Main.IsMdiContainer = true;
  720. Main.ShowInTaskbar = false;
  721. Main.Show ();
  722. using (Form frm = new Form ()) {
  723. frm.MdiParent = Main;
  724. cp = TestHelper.GetCreateParams (frm);
  725. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$01");
  726. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#01");
  727. frm.StartPosition = FormStartPosition.CenterParent;
  728. cp = TestHelper.GetCreateParams (frm);
  729. Assert.AreEqual (FormStartPosition.CenterParent, frm.StartPosition, "$01");
  730. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#02");
  731. frm.StartPosition = FormStartPosition.CenterScreen;
  732. cp = TestHelper.GetCreateParams (frm);
  733. Assert.AreEqual (FormStartPosition.CenterScreen, frm.StartPosition, "$01");
  734. Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#03");
  735. frm.StartPosition = FormStartPosition.Manual;
  736. cp = TestHelper.GetCreateParams (frm);
  737. Assert.AreEqual (FormStartPosition.Manual, frm.StartPosition, "$01");
  738. Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#04");
  739. frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
  740. cp = TestHelper.GetCreateParams (frm);
  741. Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, frm.StartPosition, "$01");
  742. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#05");
  743. frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
  744. cp = TestHelper.GetCreateParams (frm);
  745. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$01");
  746. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#06");
  747. frm.Show ();
  748. }
  749. using (Form frm = new Form ()) {
  750. frm.MdiParent = Main;
  751. frm.Location = new Point (23, 45);
  752. cp = TestHelper.GetCreateParams (frm);
  753. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$A1");
  754. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#A1");
  755. frm.StartPosition = FormStartPosition.CenterParent;
  756. cp = TestHelper.GetCreateParams (frm);
  757. Assert.AreEqual (FormStartPosition.CenterParent, frm.StartPosition, "$A2");
  758. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#A2");
  759. frm.StartPosition = FormStartPosition.CenterScreen;
  760. cp = TestHelper.GetCreateParams (frm);
  761. Assert.AreEqual (FormStartPosition.CenterScreen, frm.StartPosition, "$A3");
  762. Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#A3");
  763. frm.StartPosition = FormStartPosition.Manual;
  764. cp = TestHelper.GetCreateParams (frm);
  765. Assert.AreEqual (FormStartPosition.Manual, frm.StartPosition, "$A4");
  766. Assert.AreEqual (new Point (23, 45).ToString (), new Point (cp.X, cp.Y).ToString (), "#A4");
  767. frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
  768. cp = TestHelper.GetCreateParams (frm);
  769. Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, frm.StartPosition, "$A5");
  770. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#A5");
  771. frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
  772. cp = TestHelper.GetCreateParams (frm);
  773. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$A6");
  774. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#A6");
  775. frm.Show ();
  776. }
  777. using (Form frm = new Form ()) {
  778. frm.MdiParent = Main;
  779. frm.Location = new Point (34, 56);
  780. cp = TestHelper.GetCreateParams (frm);
  781. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$B1");
  782. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#B1");
  783. frm.StartPosition = FormStartPosition.CenterParent;
  784. cp = TestHelper.GetCreateParams (frm);
  785. Assert.AreEqual (FormStartPosition.CenterParent, frm.StartPosition, "$B2");
  786. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#B2");
  787. frm.StartPosition = FormStartPosition.CenterScreen;
  788. cp = TestHelper.GetCreateParams (frm);
  789. Assert.AreEqual (FormStartPosition.CenterScreen, frm.StartPosition, "$B3");
  790. Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#B3");
  791. frm.StartPosition = FormStartPosition.Manual;
  792. cp = TestHelper.GetCreateParams (frm);
  793. Assert.AreEqual (FormStartPosition.Manual, frm.StartPosition, "$B4");
  794. Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#B4");
  795. frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
  796. cp = TestHelper.GetCreateParams (frm);
  797. Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, frm.StartPosition, "$B5");
  798. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#B5");
  799. frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
  800. cp = TestHelper.GetCreateParams (frm);
  801. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$B6");
  802. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#B6");
  803. frm.Show ();
  804. }
  805. Main.Size = new Size (600, 600);
  806. using (Form frm = new Form ()) {
  807. frm.MdiParent = Main;
  808. frm.Location = new Point (34, 56);
  809. cp = TestHelper.GetCreateParams (frm);
  810. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$C1");
  811. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#C1");
  812. frm.StartPosition = FormStartPosition.CenterParent;
  813. cp = TestHelper.GetCreateParams (frm);
  814. Assert.AreEqual (FormStartPosition.CenterParent, frm.StartPosition, "$C2");
  815. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#C2");
  816. frm.StartPosition = FormStartPosition.CenterScreen;
  817. cp = TestHelper.GetCreateParams (frm);
  818. Assert.AreEqual (FormStartPosition.CenterScreen, frm.StartPosition, "$C3");
  819. Assert.AreEqual (new Point (Main.Controls [0].ClientSize.Width / 2 - frm.Width / 2, Main.Controls [0].ClientSize.Height / 2 - frm.Height / 2).ToString (), new Point (cp.X, cp.Y).ToString (), "#C3");
  820. frm.StartPosition = FormStartPosition.Manual;
  821. cp = TestHelper.GetCreateParams (frm);
  822. Assert.AreEqual (FormStartPosition.Manual, frm.StartPosition, "$C4");
  823. Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#C4");
  824. frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
  825. cp = TestHelper.GetCreateParams (frm);
  826. Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, frm.StartPosition, "$C5");
  827. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#C5");
  828. frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
  829. cp = TestHelper.GetCreateParams (frm);
  830. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$C6");
  831. Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#C6");
  832. frm.Show ();
  833. }
  834. }
  835. }
  836. [Test]
  837. public void ParentedFormStartupPositionTest ()
  838. {
  839. CreateParams cp;
  840. using (Form Main = new Form ()) {
  841. Main.ShowInTaskbar = false;
  842. Main.Show ();
  843. using (Form frm = new Form ()) {
  844. frm.TopLevel = false;
  845. Main.Controls.Add (frm);
  846. cp = TestHelper.GetCreateParams (frm);
  847. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$01");
  848. Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#01");
  849. frm.StartPosition = FormStartPosition.CenterParent;
  850. cp = TestHelper.GetCreateParams (frm);
  851. Assert.AreEqual (FormStartPosition.CenterParent, frm.StartPosition, "$02");
  852. Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#02");
  853. frm.StartPosition = FormStartPosition.CenterScreen;
  854. cp = TestHelper.GetCreateParams (frm);
  855. Assert.AreEqual (FormStartPosition.CenterScreen, frm.StartPosition, "$03");
  856. Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#03");
  857. frm.StartPosition = FormStartPosition.Manual;
  858. cp = TestHelper.GetCreateParams (frm);
  859. Assert.AreEqual (FormStartPosition.Manual, frm.StartPosition, "$04");
  860. Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#04");
  861. frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
  862. cp = TestHelper.GetCreateParams (frm);
  863. Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, frm.StartPosition, "$05");
  864. Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#05");
  865. frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
  866. cp = TestHelper.GetCreateParams (frm);
  867. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$06");
  868. Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#06");
  869. frm.Show ();
  870. }
  871. using (Form frm = new Form ()) {
  872. frm.TopLevel = false;
  873. Main.Controls.Add (frm);
  874. frm.Location = new Point (23, 45);
  875. cp = TestHelper.GetCreateParams (frm);
  876. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$A1");
  877. Assert.AreEqual (new Point (23, 45).ToString (), new Point (cp.X, cp.Y).ToString (), "#A1");
  878. frm.StartPosition = FormStartPosition.CenterParent;
  879. cp = TestHelper.GetCreateParams (frm);
  880. Assert.AreEqual (FormStartPosition.CenterParent, frm.StartPosition, "$A2");
  881. Assert.AreEqual (new Point (23, 45).ToString (), new Point (cp.X, cp.Y).ToString (), "#A2");
  882. frm.StartPosition = FormStartPosition.CenterScreen;
  883. cp = TestHelper.GetCreateParams (frm);
  884. Assert.AreEqual (FormStartPosition.CenterScreen, frm.StartPosition, "$A3");
  885. Assert.AreEqual (new Point (23, 45).ToString (), new Point (cp.X, cp.Y).ToString (), "#A3");
  886. frm.StartPosition = FormStartPosition.Manual;
  887. cp = TestHelper.GetCreateParams (frm);
  888. Assert.AreEqual (FormStartPosition.Manual, frm.StartPosition, "$A4");
  889. Assert.AreEqual (new Point (23, 45).ToString (), new Point (cp.X, cp.Y).ToString (), "#A4");
  890. frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
  891. cp = TestHelper.GetCreateParams (frm);
  892. Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, frm.StartPosition, "$A5");
  893. Assert.AreEqual (new Point (23, 45).ToString (), new Point (cp.X, cp.Y).ToString (), "#A5");
  894. frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
  895. cp = TestHelper.GetCreateParams (frm);
  896. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$A6");
  897. Assert.AreEqual (new Point (23, 45).ToString (), new Point (cp.X, cp.Y).ToString (), "#A6");
  898. frm.Show ();
  899. }
  900. using (Form frm = new Form ()) {
  901. frm.TopLevel = false;
  902. Main.Controls.Add (frm);
  903. frm.Location = new Point (34, 56);
  904. cp = TestHelper.GetCreateParams (frm);
  905. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$B1");
  906. Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#B1");
  907. frm.StartPosition = FormStartPosition.CenterParent;
  908. cp = TestHelper.GetCreateParams (frm);
  909. Assert.AreEqual (FormStartPosition.CenterParent, frm.StartPosition, "$B2");
  910. Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#B2");
  911. frm.StartPosition = FormStartPosition.CenterScreen;
  912. cp = TestHelper.GetCreateParams (frm);
  913. Assert.AreEqual (FormStartPosition.CenterScreen, frm.StartPosition, "$B3");
  914. Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#B3");
  915. frm.StartPosition = FormStartPosition.Manual;
  916. cp = TestHelper.GetCreateParams (frm);
  917. Assert.AreEqual (FormStartPosition.Manual, frm.StartPosition, "$B4");
  918. Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#B4");
  919. frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
  920. cp = TestHelper.GetCreateParams (frm);
  921. Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, frm.StartPosition, "$B5");
  922. Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#B5");
  923. frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
  924. cp = TestHelper.GetCreateParams (frm);
  925. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$B6");
  926. Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#B6");
  927. frm.Show ();
  928. }
  929. Main.Size = new Size (600, 600);
  930. using (Form frm = new Form ()) {
  931. frm.TopLevel = false;
  932. Main.Controls.Add (frm);
  933. frm.Location = new Point (34, 56);
  934. cp = TestHelper.GetCreateParams (frm);
  935. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$C1");
  936. Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#C1");
  937. frm.StartPosition = FormStartPosition.CenterParent;
  938. cp = TestHelper.GetCreateParams (frm);
  939. Assert.AreEqual (FormStartPosition.CenterParent, frm.StartPosition, "$C2");
  940. Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#C2");
  941. frm.StartPosition = FormStartPosition.CenterScreen;
  942. cp = TestHelper.GetCreateParams (frm);
  943. Assert.AreEqual (FormStartPosition.CenterScreen, frm.StartPosition, "$C3");
  944. Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#C3");
  945. frm.StartPosition = FormStartPosition.Manual;
  946. cp = TestHelper.GetCreateParams (frm);
  947. Assert.AreEqual (FormStartPosition.Manual, frm.StartPosition, "$C4");
  948. Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#C4");
  949. frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
  950. cp = TestHelper.GetCreateParams (frm);
  951. Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, frm.StartPosition, "$C5");
  952. Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#C5");
  953. frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
  954. cp = TestHelper.GetCreateParams (frm);
  955. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$C6");
  956. Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#C6");
  957. frm.Show ();
  958. }
  959. }
  960. }
  961. [Test]
  962. public void UnparentForm ()
  963. {
  964. Form f1 = new Form ();
  965. f1.Show ();
  966. Form f2 = new Form ();
  967. f2.TopLevel = false;
  968. f2.Parent = f1;
  969. Assert.AreSame (f1, f2.Parent, "#1");
  970. f2.Show ();
  971. f2.Parent = null;
  972. Assert.IsNull (f2.Parent, "#2");
  973. }
  974. [Test] // bug #80791
  975. public void ClientSizeTest ()
  976. {
  977. Form form = new Form ();
  978. Assert.IsFalse (form.ClientSize == form.Size);
  979. }
  980. [Test] // bug #80574
  981. [Category ("NotWorking")]
  982. public void FormBorderStyleTest ()
  983. {
  984. Form form = new Form ();
  985. Rectangle boundsBeforeBorderStyleChange = form.Bounds;
  986. Rectangle clientRectangleBeforeBorderStyleChange = form.ClientRectangle;
  987. form.FormBorderStyle = FormBorderStyle.None;
  988. Assert.AreEqual (form.Bounds, boundsBeforeBorderStyleChange, "#A1");
  989. Assert.AreEqual (form.ClientRectangle, clientRectangleBeforeBorderStyleChange, "#A2");
  990. form.Visible = true;
  991. form.FormBorderStyle = FormBorderStyle.Sizable;
  992. boundsBeforeBorderStyleChange = form.Bounds;
  993. clientRectangleBeforeBorderStyleChange = form.ClientRectangle;
  994. form.FormBorderStyle = FormBorderStyle.None;
  995. Assert.IsFalse (form.Bounds == boundsBeforeBorderStyleChange, "#B1");
  996. Assert.AreEqual (form.ClientRectangle, clientRectangleBeforeBorderStyleChange, "#B2");
  997. form.Visible = false;
  998. form.FormBorderStyle = FormBorderStyle.Sizable;
  999. boundsBeforeBorderStyleChange = form.Bounds;
  1000. clientRectangleBeforeBorderStyleChange = form.ClientRectangle;
  1001. form.FormBorderStyle = FormBorderStyle.None;
  1002. Assert.IsFalse (form.Bounds == boundsBeforeBorderStyleChange, "#C1");
  1003. Assert.AreEqual (form.ClientRectangle, clientRectangleBeforeBorderStyleChange, "#C2");
  1004. }
  1005. [Test]
  1006. [Category ("NotWorking")]
  1007. public void MaximizedParentedFormTest ()
  1008. {
  1009. using (Form Main = new Form ()) {
  1010. Form Child = new Form ();
  1011. Child.TopLevel = false;
  1012. Main.Controls.Add (Child);
  1013. Main.ShowInTaskbar = false;
  1014. Main.Show ();
  1015. Child.WindowState = FormWindowState.Maximized;
  1016. Child.Visible = true;
  1017. // The exact negative value depends on the border with, but it should always be < 0.
  1018. Assert.IsTrue (Child.Location.X < 0 && Child.Location.Y < 0, "#A1");
  1019. }
  1020. }
  1021. [Test]
  1022. [Category ("NotWorking")]
  1023. public void ParentedFormEventTest ()
  1024. {
  1025. using (Form Main = new Form ()) {
  1026. Form Child = new Form ();
  1027. Child.TopLevel = false;
  1028. Child.Visible = true;
  1029. Main.ShowInTaskbar = false;
  1030. Main.Show ();
  1031. EventLogger log = new EventLogger (Child);
  1032. Assert.AreEqual (true, Child.Visible, "#A0");
  1033. Main.Controls.Add (Child);
  1034. Assert.AreEqual (true, Child.Visible, "#B0");
  1035. Assert.AreEqual ("ParentChanged;BindingContextChanged;Layout;VisibleChanged;BindingContextChanged;BindingContextChanged", log.EventsJoined (), "#B1");
  1036. }
  1037. }
  1038. [Test]
  1039. [NUnit.Framework.Category ("NotWorking")]
  1040. public void FormCreateParamsStyleTest ()
  1041. {
  1042. Form frm;
  1043. using (frm = new Form ()) {
  1044. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles) TestHelper.GetCreateParams (frm).Style), "#01-Style");
  1045. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles) TestHelper.GetCreateParams (frm).ExStyle), "#01-ExStyle");
  1046. }
  1047. using (frm = new Form ()) {
  1048. frm.AllowDrop = !frm.AllowDrop;
  1049. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#02-Style");
  1050. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#02-ExStyle");
  1051. }
  1052. using (frm = new Form ()) {
  1053. frm.AllowTransparency = !frm.AllowTransparency;
  1054. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#03-Style");
  1055. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_LAYERED, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#03-ExStyle");
  1056. }
  1057. using (frm = new Form ()) {
  1058. frm.Opacity = 0.50;
  1059. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#04-Style");
  1060. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_LAYERED, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#04-ExStyle");
  1061. }
  1062. using (frm = new Form ()) {
  1063. frm.TransparencyKey = Color.Cyan;
  1064. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#05-Style");
  1065. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_LAYERED, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#05-ExStyle");
  1066. }
  1067. using (frm = new Form ()) {
  1068. frm.CausesValidation = !frm.CausesValidation;
  1069. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#06-Style");
  1070. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#06-ExStyle");
  1071. }
  1072. using (frm = new Form ()) {
  1073. frm.ControlBox = !frm.ControlBox;
  1074. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_THICKFRAME | WindowStyles.WS_BORDER | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#07-Style");
  1075. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#07-ExStyle");
  1076. }
  1077. using (frm = new Form ()) {
  1078. frm.Enabled = true;
  1079. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#08-Style");
  1080. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#08-ExStyle");
  1081. }
  1082. using (frm = new Form ()) {
  1083. frm.FormBorderStyle = FormBorderStyle.Fixed3D;
  1084. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#10-Style");
  1085. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CLIENTEDGE | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#10-ExStyle");
  1086. }
  1087. using (frm = new Form ()) {
  1088. frm.FormBorderStyle = FormBorderStyle.FixedDialog;
  1089. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#11-Style");
  1090. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#11-ExStyle");
  1091. }
  1092. using (frm = new Form ()) {
  1093. frm.FormBorderStyle = FormBorderStyle.FixedSingle;
  1094. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#12-Style");
  1095. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#12-ExStyle");
  1096. }
  1097. using (frm = new Form ()) {
  1098. frm.FormBorderStyle = FormBorderStyle.FixedToolWindow;
  1099. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#13-Style");
  1100. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_TOOLWINDOW | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#13-ExStyle");
  1101. }
  1102. using (frm = new Form ()) {
  1103. frm.FormBorderStyle = FormBorderStyle.None;
  1104. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#14-Style");
  1105. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#14-ExStyle");
  1106. }
  1107. using (frm = new Form ()) {
  1108. frm.FormBorderStyle = FormBorderStyle.Sizable;
  1109. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#15-Style");
  1110. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#15-ExStyle");
  1111. }
  1112. using (frm = new Form ()) {
  1113. frm.FormBorderStyle = FormBorderStyle.SizableToolWindow;
  1114. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#16-Style");
  1115. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_TOOLWINDOW | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#16-ExStyle");
  1116. }
  1117. using (frm = new Form ()) {
  1118. frm.HelpButton = !frm.HelpButton;
  1119. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#17-Style");
  1120. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#17-ExStyle");
  1121. }
  1122. using (frm = new Form ()) {
  1123. frm.Icon = null;
  1124. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#18-Style");
  1125. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#18-ExStyle");
  1126. }
  1127. using (frm = new Form ()) {
  1128. frm.Icon = SystemIcons.Asterisk;
  1129. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#19-Style");
  1130. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#19-ExStyle");
  1131. }
  1132. using (frm = new Form ()) {
  1133. frm.IsMdiContainer = !frm.IsMdiContainer;
  1134. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#20-Style");
  1135. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#20-ExStyle");
  1136. }
  1137. using (frm = new Form ()) {
  1138. frm.MaximizeBox = !frm.MaximizeBox;
  1139. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_GROUP | WindowStyles.WS_THICKFRAME | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#21-Style");
  1140. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#21-ExStyle");
  1141. }
  1142. using (frm = new Form ()) {
  1143. frm.MinimizeBox = !frm.MinimizeBox;
  1144. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_THICKFRAME | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#22-Style");
  1145. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#22-ExStyle");
  1146. }
  1147. #if NET_2_0
  1148. using (frm = new Form ()) {
  1149. frm.ShowIcon = !frm.ShowIcon;
  1150. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#23-Style");
  1151. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#23-ExStyle");
  1152. }
  1153. #endif
  1154. using (frm = new Form ()) {
  1155. frm.ShowInTaskbar = !frm.ShowInTaskbar;
  1156. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#24-Style");
  1157. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#24-ExStyle");
  1158. }
  1159. using (frm = new Form ()) {
  1160. frm.TabStop = !frm.TabStop;
  1161. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#25-Style");
  1162. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#25-ExStyle");
  1163. }
  1164. using (frm = new Form ()) {
  1165. frm.TopLevel = !frm.TopLevel;
  1166. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_CHILD, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#26-Style");
  1167. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#26-ExStyle");
  1168. }
  1169. using (frm = new Form ()) {
  1170. frm.Visible = !frm.Visible;
  1171. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#27-Style");
  1172. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#27-ExStyle");
  1173. }
  1174. using (frm = new Form ()) {
  1175. frm.ControlBox = false;
  1176. frm.Text = "";
  1177. Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_THICKFRAME | WindowStyles.WS_BORDER | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#28-Style");
  1178. Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#28-ExStyle");
  1179. }
  1180. }
  1181. [Test]
  1182. public void FormParentedTest ()
  1183. {
  1184. using (Form frm = new Form ()) {
  1185. using (Form frm2 = new Form ()) {
  1186. frm2.TopLevel = false;
  1187. frm.ShowInTaskbar = false;
  1188. frm2.ShowInTaskbar = false;
  1189. frm2.Visible = true;
  1190. frm.Visible = true;
  1191. EventLogger log = new EventLogger (frm);
  1192. EventLogger log2 = new EventLogger (frm2);
  1193. frm.Controls.Add (frm2);
  1194. Assert.IsTrue (log2.EventRaised ("ParentChanged"), "#C1");
  1195. Assert.IsTrue (log.EventRaised ("ControlAdded"), "#P1");
  1196. Assert.AreSame (frm, frm2.Parent, "#02");
  1197. }
  1198. }
  1199. }
  1200. [Test]
  1201. public void FormPropertyTest ()
  1202. {
  1203. Form myform = new Form ();
  1204. myform.Visible = true;
  1205. myform.Text = "NewForm";
  1206. myform.Name = "FormTest";
  1207. Assert.IsNull (myform.ActiveMdiChild, "#2");
  1208. Assert.IsFalse (myform.AutoScale, "#3");
  1209. Assert.IsNull (myform.CancelButton, "#6");
  1210. Assert.IsTrue (myform.ControlBox, "#9");
  1211. Assert.IsTrue (myform.DesktopBounds.X > 0, "#10a");
  1212. Assert.IsTrue (myform.DesktopBounds.Y > 0, "#10b");
  1213. Assert.AreEqual (300, myform.DesktopBounds.Height, "#10c");
  1214. Assert.AreEqual (300, myform.DesktopBounds.Width, "#10d");
  1215. Assert.IsTrue (myform.DesktopLocation.X > 0, "#11a");
  1216. Assert.IsTrue (myform.DesktopLocation.Y > 0, "#11b");
  1217. Assert.AreEqual (DialogResult.None, myform.DialogResult, "#12");
  1218. Assert.AreEqual (FormBorderStyle.Sizable, myform.FormBorderStyle, "#13");
  1219. Assert.IsFalse (myform.HelpButton, "#14");
  1220. Assert.AreEqual ("System.Drawing.Icon", myform.Icon.GetType ().ToString (), "#15");
  1221. Assert.IsFalse (myform.IsMdiChild, "#16");
  1222. Assert.IsFalse (myform.IsMdiContainer, "#17");
  1223. Assert.IsFalse (myform.KeyPreview, "#18");
  1224. Assert.IsTrue (myform.MaximizeBox, "#19");
  1225. Assert.AreEqual (0, myform.MaximumSize.Height, "#20a");
  1226. Assert.AreEqual (0, myform.MaximumSize.Width, "#20b");
  1227. Assert.AreEqual (0, myform.MdiChildren.Length, "#21a");
  1228. Assert.AreEqual (1, myform.MdiChildren.Rank, "#21b");
  1229. Assert.IsFalse (myform.MdiChildren.IsSynchronized, "#21c");
  1230. Assert.IsNull (myform.MdiParent, "#22");
  1231. Assert.IsNull (myform.Menu, "#23");
  1232. Assert.IsNull (myform.MergedMenu, "#24");
  1233. Assert.IsTrue (myform.MinimizeBox, "#25");
  1234. Assert.AreEqual (0, myform.MinimumSize.Height, "#26a");
  1235. Assert.AreEqual (0, myform.MinimumSize.Width, "#26b");
  1236. Assert.IsTrue (myform.MinimumSize.IsEmpty, "#26c");
  1237. Assert.IsFalse (myform.Modal, "#27");
  1238. Assert.AreEqual (1, myform.Opacity, "#28");
  1239. Assert.AreEqual (0, myform.OwnedForms.Length, "#29a");
  1240. Assert.AreEqual (1, myform.OwnedForms.Rank, "#29b");
  1241. Assert.IsNull (myform.Owner, "#30");
  1242. Assert.IsTrue (myform.ShowInTaskbar, "#31");
  1243. Assert.AreEqual (300, myform.Size.Height, "#32a");
  1244. Assert.AreEqual (300, myform.Size.Width, "#32b");
  1245. Assert.AreEqual (SizeGripStyle.Auto, myform.SizeGripStyle, "#33");
  1246. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, myform.StartPosition, "#34");
  1247. Assert.IsTrue (myform.TopLevel, "#35");
  1248. Assert.IsFalse (myform.TopMost, "#36");
  1249. Assert.AreEqual (Color.Empty, myform.TransparencyKey, "#37");
  1250. Assert.AreEqual (FormWindowState.Normal, myform.WindowState, "#38");
  1251. Assert.AreEqual (ImeMode.NoControl, myform.ImeMode, "#39");
  1252. myform.Dispose ();
  1253. }
  1254. [Test]
  1255. [Category ("NotWorking")]
  1256. public void ActivateTest ()
  1257. {
  1258. Form myform = new Form ();
  1259. myform.ShowInTaskbar = false;
  1260. myform.Visible = true;
  1261. myform.Text = "NewForm";
  1262. myform.Name = "FormTest";
  1263. myform.Activate ();
  1264. Assert.AreEqual (true, myform.Focus (), "#40");
  1265. myform.Dispose ();
  1266. }
  1267. [Test]
  1268. public void AddOwnedFormTest ()
  1269. {
  1270. Form parent = new Form ();
  1271. parent.ShowInTaskbar = false;
  1272. parent.Text = "NewParent";
  1273. Form ownedForm = new Form ();
  1274. ownedForm.ShowInTaskbar = false;
  1275. ownedForm.Text = "Owned Form";
  1276. parent.AddOwnedForm (ownedForm);
  1277. ownedForm.Show ();
  1278. Assert.AreEqual ("NewParent", ownedForm.Owner.Text, "#41");
  1279. ownedForm.Dispose ();
  1280. parent.Dispose ();
  1281. }
  1282. [Test] // bug #80020
  1283. public void IsHandleCreated ()
  1284. {
  1285. Form main = new Form ();
  1286. main.Name = "main";
  1287. main.IsMdiContainer = true;
  1288. main.ShowInTaskbar = false;
  1289. Assert.IsFalse (main.IsHandleCreated, "#1");
  1290. Form child = new Form ();
  1291. child.MdiParent = main;
  1292. child.WindowState = FormWindowState.Maximized;
  1293. Assert.IsFalse (main.IsHandleCreated, "#2");
  1294. child.Show ();
  1295. Assert.IsFalse (child.IsHandleCreated, "#3");
  1296. Assert.IsFalse (main.IsHandleCreated, "#4");
  1297. main.Show ();
  1298. Assert.IsTrue (child.IsHandleCreated, "#5");
  1299. Assert.IsTrue (main.IsHandleCreated, "#6");
  1300. child.Dispose ();
  1301. main.Dispose ();
  1302. }
  1303. [Test]
  1304. public void RemoveOwnedFormTest ()
  1305. {
  1306. Form myform = new Form ();
  1307. myform.ShowInTaskbar = false;
  1308. myform.Text = "NewForm";
  1309. myform.Name = "FormTest";
  1310. myform.RemoveOwnedForm (myform);
  1311. myform.Show ();
  1312. Assert.AreEqual (null, myform.Owner, "#44");
  1313. myform.Dispose ();
  1314. }
  1315. [Test]
  1316. public void SetDesktopBoundsTest ()
  1317. {
  1318. Form myform = new Form ();
  1319. myform.ShowInTaskbar = false;
  1320. myform.Visible = true;
  1321. myform.Text = "NewForm";
  1322. myform.Name = "FormTest";
  1323. myform.SetDesktopBounds (10, 10, 200 , 200);
  1324. Assert.AreEqual (200, myform.DesktopBounds.Height, "#45");
  1325. myform.Dispose ();
  1326. }
  1327. [Test]
  1328. public void SetDesktopLocationTest ()
  1329. {
  1330. Form myform = new Form ();
  1331. myform.ShowInTaskbar = false;
  1332. myform.Visible = true;
  1333. myform.Text = "NewForm";
  1334. myform.Name = "FormTest";
  1335. myform.SetDesktopLocation (10, 10);
  1336. Assert.AreEqual (10, myform.DesktopLocation.X, "#46");
  1337. myform.Dispose ();
  1338. }
  1339. [Test]
  1340. public void SetDialogResultOutOfRange ()
  1341. {
  1342. Form myform = new Form ();
  1343. myform.ShowInTaskbar = false;
  1344. try {
  1345. myform.DialogResult = (DialogResult) (-1);
  1346. Assert.Fail ("#48");
  1347. } catch (InvalidEnumArgumentException) {
  1348. }
  1349. try {
  1350. myform.DialogResult = (DialogResult) ((int) DialogResult.No + 1);
  1351. Assert.Fail ("#49");
  1352. } catch (InvalidEnumArgumentException) {
  1353. }
  1354. myform.Dispose ();
  1355. }
  1356. void myform_set_dialogresult (object sender, EventArgs e)
  1357. {
  1358. Form f = (Form)sender;
  1359. f.DialogResult = DialogResult.OK;
  1360. }
  1361. void myform_close (object sender, EventArgs e)
  1362. {
  1363. Form f = (Form)sender;
  1364. f.Close();
  1365. }
  1366. [Test]
  1367. public void SetDialogResult ()
  1368. {
  1369. Form myform = new Form ();
  1370. myform.ShowInTaskbar = false;
  1371. myform.Visible = true;
  1372. myform.DialogResult = DialogResult.Cancel;
  1373. Assert.IsTrue (myform.Visible, "A1");
  1374. Assert.IsFalse (myform.IsDisposed, "A2");
  1375. myform.Close ();
  1376. Assert.IsFalse (myform.Visible, "A3");
  1377. Assert.IsTrue (myform.IsDisposed, "A4");
  1378. DialogResult result;
  1379. myform = new Form ();
  1380. myform.ShowInTaskbar = false;
  1381. myform.VisibleChanged += new EventHandler (myform_set_dialogresult);
  1382. result = myform.ShowDialog ();
  1383. Assert.AreEqual (result, DialogResult.OK, "A5");
  1384. Assert.IsFalse (myform.Visible, "A6");
  1385. Assert.IsFalse (myform.IsDisposed, "A7");
  1386. myform.Dispose ();
  1387. myform = new Form ();
  1388. myform.ShowInTaskbar = false;
  1389. myform.VisibleChanged += new EventHandler (myform_close);
  1390. result = myform.ShowDialog ();
  1391. Assert.AreEqual (result, DialogResult.Cancel, "A8");
  1392. Assert.IsFalse (myform.Visible, "A9");
  1393. Assert.IsFalse (myform.IsDisposed, "A10");
  1394. myform.Dispose ();
  1395. }
  1396. [Test]
  1397. public void ShowDialog_Child ()
  1398. {
  1399. Form main = new Form ();
  1400. main.IsMdiContainer = true;
  1401. Form child = new Form ();
  1402. child.MdiParent = main;
  1403. try {
  1404. child.ShowDialog ();
  1405. Assert.Fail ("#1");
  1406. } catch (InvalidOperationException ex) {
  1407. // Forms that are not top level forms cannot be displayed as a
  1408. // modal dialog. Remove the form from any parent form before
  1409. // calling ShowDialog.
  1410. Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
  1411. Assert.IsNull (ex.InnerException, "#3");
  1412. Assert.IsNotNull (ex.Message, "#4");
  1413. }
  1414. Assert.IsNull (child.Owner, "#5");
  1415. child.Dispose ();
  1416. main.Dispose ();
  1417. }
  1418. [Test]
  1419. public void ShowDialog_Disabled ()
  1420. {
  1421. Form form = new Form ();
  1422. form.Enabled = false;
  1423. try {
  1424. form.ShowDialog ();
  1425. Assert.Fail ("#A1");
  1426. } catch (InvalidOperationException ex) {
  1427. // Forms that are not enabled cannot be displayed as a modal
  1428. // dialog. Set the form's enabled property to true before
  1429. // calling ShowDialog.
  1430. Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
  1431. Assert.IsNull (ex.InnerException, "#A3");
  1432. Assert.IsNotNull (ex.Message, "#A4");
  1433. }
  1434. Assert.IsNull (form.Owner, "#A5");
  1435. form.Dispose ();
  1436. Form main = new Form ();
  1437. form = new Form ();
  1438. form.Owner = main;
  1439. form.Enabled = false;
  1440. try {
  1441. form.ShowDialog ();
  1442. Assert.Fail ("#B1");
  1443. } catch (InvalidOperationException) {
  1444. }
  1445. Assert.IsNotNull (form.Owner, "#B2");
  1446. Assert.AreSame (main, form.Owner, "#B3");
  1447. form.Dispose ();
  1448. main.Dispose ();
  1449. }
  1450. [Test]
  1451. [Category ("NotWorking")]
  1452. public void ShowDialog_Owner_Circular ()
  1453. {
  1454. Form main = new Form ();
  1455. Form child = new Form ();
  1456. child.Owner = main;
  1457. try {
  1458. main.ShowDialog (child);
  1459. Assert.Fail ("#1");
  1460. } catch (ArgumentException ex) {
  1461. // A circular control reference has been made. A control cannot
  1462. // be owned or parented to itself
  1463. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  1464. Assert.IsNull (ex.InnerException, "#3");
  1465. Assert.IsNotNull (ex.Message, "#4");
  1466. Assert.IsNull (ex.ParamName, "#5");
  1467. }
  1468. Assert.IsNull (main.Owner, "#6");
  1469. main.Dispose ();
  1470. child.Dispose ();
  1471. }
  1472. [Test] // bug #80773
  1473. public void ShowDialog_Owner_Self ()
  1474. {
  1475. Form form = new Form ();
  1476. try {
  1477. form.ShowDialog (form);
  1478. Assert.Fail ("#A1");
  1479. } catch (ArgumentException ex) {
  1480. // Forms cannot own themselves or their owners
  1481. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
  1482. Assert.IsNull (ex.InnerException, "#A3");
  1483. Assert.IsNotNull (ex.Message, "#A4");
  1484. Assert.IsNotNull (ex.ParamName, "#A5");
  1485. Assert.AreEqual ("owner", ex.ParamName, "#A6");
  1486. }
  1487. Assert.IsNull (form.Owner, "#A7");
  1488. form.Dispose ();
  1489. Form main = new Form ();
  1490. form = new Form ();
  1491. form.Owner = main;
  1492. try {
  1493. form.ShowDialog (form);
  1494. Assert.Fail ("#B1");
  1495. } catch (ArgumentException) {
  1496. }
  1497. Assert.IsNotNull (form.Owner);
  1498. Assert.AreSame (main, form.Owner, "#B2");
  1499. form.Dispose ();
  1500. main.Dispose ();
  1501. }
  1502. [Test]
  1503. public void ShowDialog_Visible ()
  1504. {
  1505. Form form = new Form ();
  1506. form.ShowInTaskbar = false;
  1507. form.Visible = true;
  1508. try {
  1509. form.ShowDialog ();
  1510. Assert.Fail ("#A1");
  1511. } catch (InvalidOperationException ex) {
  1512. // Forms that are already visible cannot be displayed as a modal
  1513. // dialog. Set the form's visible property to false before
  1514. // calling ShowDialog.
  1515. Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
  1516. Assert.IsNull (ex.InnerException, "#A3");
  1517. Assert.IsNotNull (ex.Message, "#A4");
  1518. }
  1519. Assert.IsNull (form.Owner, "#A5");
  1520. form.Dispose ();
  1521. Form main = new Form ();
  1522. form = new Form ();
  1523. form.Owner = main;
  1524. form.Visible = true;
  1525. try {
  1526. form.ShowDialog ();
  1527. Assert.Fail ("#B1");
  1528. } catch (InvalidOperationException) {
  1529. }
  1530. Assert.IsNotNull (form.Owner, "#B2");
  1531. Assert.AreSame (main, form.Owner, "#B3");
  1532. form.Dispose ();
  1533. main.Dispose ();
  1534. }
  1535. [Test] // bug #80604
  1536. public void VisibleOnLoad ()
  1537. {
  1538. MockForm form = new MockForm ();
  1539. form.CloseOnLoad = true;
  1540. Application.Run (form);
  1541. Assert.IsTrue (form.VisibleOnLoad, "#1");
  1542. form.Dispose ();
  1543. form = new MockForm ();
  1544. form.ShowInTaskbar = false;
  1545. form.Show ();
  1546. Assert.IsTrue (form.VisibleOnLoad, "#2");
  1547. form.Dispose ();
  1548. }
  1549. [Test] // bug #80052
  1550. [Category ("NotWorking")]
  1551. public void Location ()
  1552. {
  1553. //
  1554. // CenterParent
  1555. //
  1556. Form formA = new Form ();
  1557. formA.ShowInTaskbar = false;
  1558. formA.StartPosition = FormStartPosition.CenterParent;
  1559. formA.Location = new Point (151, 251);
  1560. formA.Show ();
  1561. Assert.AreEqual (FormStartPosition.CenterParent, formA.StartPosition, "#A1");
  1562. Assert.IsFalse (formA.Location.X == 151, "#A2");
  1563. Assert.IsFalse (formA.Location.Y == 251, "#A3");
  1564. formA.Location = new Point (311, 221);
  1565. Assert.AreEqual (FormStartPosition.CenterParent, formA.StartPosition, "#A4");
  1566. Assert.AreEqual (311, formA.Location.X, "#A5");
  1567. Assert.AreEqual (221, formA.Location.Y, "#A6");
  1568. formA.Dispose ();
  1569. //
  1570. // CenterScreen
  1571. //
  1572. Form formB = new Form ();
  1573. formB.ShowInTaskbar = false;
  1574. formB.StartPosition = FormStartPosition.CenterScreen;
  1575. formB.Location = new Point (151, 251);
  1576. formB.Show ();
  1577. Assert.AreEqual (FormStartPosition.CenterScreen, formB.StartPosition, "#B1");
  1578. Assert.IsFalse (formB.Location.X == 151, "#B2");
  1579. Assert.IsFalse (formB.Location.Y == 251, "#B3");
  1580. formB.Location = new Point (311, 221);
  1581. Assert.AreEqual (FormStartPosition.CenterScreen, formB.StartPosition, "#B4");
  1582. Assert.AreEqual (311, formB.Location.X, "#B5");
  1583. Assert.AreEqual (221, formB.Location.Y, "#B6");
  1584. formB.Dispose ();
  1585. //
  1586. // Manual
  1587. //
  1588. Form formC = new Form ();
  1589. formC.ShowInTaskbar = false;
  1590. formC.StartPosition = FormStartPosition.Manual;
  1591. formC.Location = new Point (151, 251);
  1592. formC.Show ();
  1593. Assert.AreEqual (FormStartPosition.Manual, formC.StartPosition, "#C1");
  1594. Assert.AreEqual (151, formC.Location.X, "#C2");
  1595. Assert.AreEqual (251, formC.Location.Y, "#C3");
  1596. formC.Location = new Point (311, 221);
  1597. Assert.AreEqual (FormStartPosition.Manual, formC.StartPosition, "#C4");
  1598. Assert.AreEqual (311, formC.Location.X, "#C5");
  1599. Assert.AreEqual (221, formC.Location.Y, "#C6");
  1600. formC.Dispose ();
  1601. //
  1602. // WindowsDefaultBounds
  1603. //
  1604. Form formD = new Form ();
  1605. formD.ShowInTaskbar = false;
  1606. formD.StartPosition = FormStartPosition.WindowsDefaultBounds;
  1607. formD.Location = new Point (151, 251);
  1608. formD.Show ();
  1609. Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, formD.StartPosition, "#D1");
  1610. Assert.IsFalse (formD.Location.X == 151, "#D2");
  1611. Assert.IsFalse (formD.Location.Y == 251, "#D3");
  1612. formD.Location = new Point (311, 221);
  1613. Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, formD.StartPosition, "#D4");
  1614. Assert.AreEqual (311, formD.Location.X, "#D5");
  1615. Assert.AreEqual (221, formD.Location.Y, "#D6");
  1616. formD.Dispose ();
  1617. //
  1618. // WindowsDefaultLocation
  1619. //
  1620. Form formE = new Form ();
  1621. formE.ShowInTaskbar = false;
  1622. formE.Location = new Point (151, 251);
  1623. formE.Show ();
  1624. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, formE.StartPosition, "#E1");
  1625. Assert.IsFalse (formE.Location.X == 151, "#E2");
  1626. Assert.IsFalse (formE.Location.Y == 251, "#E3");
  1627. formE.Location = new Point (311, 221);
  1628. Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, formE.StartPosition, "#E4");
  1629. Assert.AreEqual (311, formE.Location.X, "#E5");
  1630. Assert.AreEqual (221, formE.Location.Y, "#E6");
  1631. formE.Dispose ();
  1632. }
  1633. [Test]
  1634. public void Opacity ()
  1635. {
  1636. Form frm;
  1637. using (frm = new Form ()) {
  1638. Assert.AreEqual (1.0f, frm.Opacity, "#01-opacity");
  1639. frm.Opacity = 0.50;
  1640. Assert.AreEqual (0.50f, frm.Opacity, "#02-opacity");
  1641. frm.Opacity = -0.1f;
  1642. Assert.AreEqual (0, frm.Opacity, "#03-opacity");
  1643. frm.Opacity = 1.1f;
  1644. Assert.AreEqual (1, frm.Opacity, "#04-opacity");
  1645. }
  1646. }
  1647. [Test]
  1648. public void DisposeOwnerTest ()
  1649. {
  1650. Form f1 = new Form ();
  1651. Form f2 = new Form ();
  1652. f2.Owner = f1;
  1653. f1.Dispose ();
  1654. Assert.IsNull (f2.Owner, "1");
  1655. Assert.AreEqual (0, f1.OwnedForms.Length, "2");
  1656. }
  1657. [Test]
  1658. [ExpectedException (typeof (ObjectDisposedException))]
  1659. public void AccessDisposedForm ()
  1660. {
  1661. Form myform = new Form ();
  1662. myform.ShowInTaskbar = false;
  1663. myform.Show ();
  1664. myform.Close (); // this should result in the form being disposed
  1665. myform.Show (); // and this line should result in the ODE being thrown
  1666. }
  1667. class MyForm : Form
  1668. {
  1669. public void DoDestroyHandle ()
  1670. {
  1671. DestroyHandle();
  1672. }
  1673. public void DoRecreateHandle ()
  1674. {
  1675. RecreateHandle();
  1676. }
  1677. }
  1678. int handle_destroyed_count;
  1679. void handle_destroyed (object sender, EventArgs e)
  1680. {
  1681. handle_destroyed_count++;
  1682. }
  1683. [Test]
  1684. public void DestroyHandleTest ()
  1685. {
  1686. handle_destroyed_count = 0;
  1687. MyForm f1 = new MyForm ();
  1688. f1.HandleDestroyed += new EventHandler (handle_destroyed);
  1689. f1.Show ();
  1690. f1.DoDestroyHandle ();
  1691. Assert.AreEqual (1, handle_destroyed_count, "1");
  1692. MyForm f2 = new MyForm ();
  1693. f2.HandleDestroyed += new EventHandler (handle_destroyed);
  1694. f2.Show ();
  1695. f2.DoRecreateHandle ();
  1696. Assert.AreEqual (2, handle_destroyed_count, "2");
  1697. f1.Dispose ();
  1698. f2.Dispose ();
  1699. }
  1700. [Test]
  1701. public void FormClose ()
  1702. {
  1703. Form myform = new Form ();
  1704. myform.ShowInTaskbar = false;
  1705. Assert.IsFalse (myform.Visible, "A1");
  1706. Assert.IsFalse (myform.IsDisposed, "A2");
  1707. myform.Close ();
  1708. #if NET_2_0
  1709. Assert.IsTrue (myform.IsDisposed, "A3");
  1710. #else
  1711. Assert.IsFalse (myform.Visible, "A4");
  1712. Assert.IsFalse (myform.IsDisposed, "A5");
  1713. myform.Show ();
  1714. Assert.IsTrue (myform.Visible, "A6");
  1715. Assert.IsFalse (myform.IsDisposed, "A7");
  1716. myform.Close ();
  1717. Assert.IsFalse (myform.Visible, "A8");
  1718. Assert.IsTrue (myform.IsDisposed, "A9");
  1719. #endif
  1720. }
  1721. [Test]
  1722. public void FormClose2 ()
  1723. {
  1724. WMCloseWatcher f = new WMCloseWatcher ();
  1725. f.ShowInTaskbar = false;
  1726. f.close_count = 0;
  1727. Assert.IsFalse (f.Visible, "A1");
  1728. f.Close ();
  1729. Assert.AreEqual (0, f.close_count, "A2");
  1730. #if NET_2_0
  1731. Assert.IsTrue (f.IsDisposed, "A3");
  1732. #else
  1733. f.Show ();
  1734. f.Close ();
  1735. Assert.AreEqual (1, f.close_count, "A4");
  1736. #endif
  1737. }
  1738. class WMCloseWatcher : Form {
  1739. public int close_count;
  1740. protected override void WndProc (ref Message msg) {
  1741. if (msg.Msg == 0x0010 /* WM_CLOSE */) {
  1742. close_count ++;
  1743. }
  1744. base.WndProc (ref msg);
  1745. }
  1746. }
  1747. class SwallowOnActivated : Form {
  1748. protected override void OnActivated (EventArgs e)
  1749. {
  1750. // do nothing
  1751. }
  1752. protected override void OnCreateControl () {
  1753. base.OnCreateControl ();
  1754. }
  1755. }
  1756. class EnterTest : Button {
  1757. protected override void OnEnter (EventArgs e)
  1758. {
  1759. on_enter = true;
  1760. base.OnEnter (e);
  1761. }
  1762. public bool on_enter;
  1763. }
  1764. [Test]
  1765. public void OnActivateEventHandlingTest1 ()
  1766. {
  1767. // if (TestHelper.RunningOnUnix) {
  1768. // Assert.Ignore ("Relies on form.Show() synchronously generating WM_ACTIVATE");
  1769. // }
  1770. SwallowOnActivated f = new SwallowOnActivated ();
  1771. f.ShowInTaskbar = false;
  1772. EnterTest c = new EnterTest ();
  1773. f.Controls.Add (c);
  1774. f.Show ();
  1775. Assert.IsTrue (c.on_enter, "1");
  1776. f.Dispose ();
  1777. }
  1778. #if NET_2_0
  1779. [Test]
  1780. public void FormClosingEvents ()
  1781. {
  1782. // Standard Close
  1783. Form f = new Form ();
  1784. string events = string.Empty;
  1785. f.Closing += new CancelEventHandler (delegate (Object obj, CancelEventArgs e) { events += ("Closing;"); });
  1786. f.FormClosing += new FormClosingEventHandler (delegate (Object obj, FormClosingEventArgs e) { events += string.Format ("FormClosing [Reason:{0} - Cancel:{1}]", e.CloseReason, e.Cancel); });
  1787. f.Show ();
  1788. f.Close ();
  1789. Assert.AreEqual ("Closing;FormClosing [Reason:UserClosing - Cancel:False]", events, "A1");
  1790. }
  1791. [Test]
  1792. public void FormClosingEventsCancel ()
  1793. {
  1794. // Shows that setting Cancel in Closing flows through to FormClosing
  1795. Form f = new Form ();
  1796. string events = string.Empty;
  1797. f.Closing += new CancelEventHandler (delegate (Object obj, CancelEventArgs e) { events += ("Closing;"); e.Cancel = true; });
  1798. f.FormClosing += new FormClosingEventHandler (delegate (Object obj, FormClosingEventArgs e) { events += string.Format("FormClosing [Reason:{0} - Cancel:{1}]", e.CloseReason, e.Cancel); e.Cancel = false; });
  1799. f.Show ();
  1800. f.Close ();
  1801. Assert.AreEqual ("Closing;FormClosing [Reason:UserClosing - Cancel:True]", events, "A1");
  1802. }
  1803. [Test]
  1804. public void FormClosedEvents ()
  1805. {
  1806. // Standard Closed
  1807. Form f = new Form ();
  1808. string events = string.Empty;
  1809. f.Closed += new EventHandler (delegate (Object obj, EventArgs e) { events += ("Closed;"); });
  1810. f.FormClosed += new FormClosedEventHandler (delegate (Object obj, FormClosedEventArgs e) { events += string.Format ("FormClosed [Reason:{0}]", e.CloseReason); });
  1811. f.Show ();
  1812. f.Close ();
  1813. Assert.AreEqual ("Closed;FormClosed [Reason:UserClosing]", events, "A1");
  1814. }
  1815. [Test]
  1816. public void ShowWithOwner ()
  1817. {
  1818. Form f = new Form ();
  1819. Button b = new Button ();
  1820. f.Controls.Add (b);
  1821. Form f2 = new Form ();
  1822. f2.Show (f);
  1823. Assert.AreSame (f, f2.Owner, "A1");
  1824. f2.Close ();
  1825. f2 = new Form ();
  1826. f2.Show (b);
  1827. Assert.AreSame (f, f2.Owner, "A2");
  1828. f2.Close ();
  1829. Button b2 = new Button ();
  1830. f2 = new Form ();
  1831. f2.Show (b2);
  1832. Assert.AreEqual (null, f2.Owner, "A3");
  1833. f2.Close ();
  1834. f2 = new Form ();
  1835. f2.Show (null);
  1836. Assert.AreEqual (null, f2.Owner, "A4");
  1837. f2.Close ();
  1838. f.Dispose ();
  1839. }
  1840. [Test]
  1841. [ExpectedException (typeof (InvalidOperationException))]
  1842. public void ShowWithOwnerIOE ()
  1843. {
  1844. using (Form f = new Form ()) {
  1845. f.Show (f);
  1846. }
  1847. }
  1848. [Test] // Bug #79959, #80574, #80791
  1849. [Category ("NotWorking")]
  1850. public void BehaviorResizeOnBorderStyleChanged ()
  1851. {
  1852. // Marked NotWorking because the ClientSize is dependent on the WM.
  1853. // The values below match XP Luna to make sure our behavior is the same.
  1854. Form f = new Form ();
  1855. f.ShowInTaskbar = false;
  1856. f.Show ();
  1857. Assert.AreEqual (true, f.IsHandleCreated, "A0");
  1858. Assert.AreEqual (new Size (300, 300), f.Size, "A1");
  1859. Assert.AreEqual (new Size (292, 266), f.ClientSize, "A2");
  1860. f.FormBorderStyle = FormBorderStyle.Fixed3D;
  1861. Assert.AreEqual (new Size (302, 302), f.Size, "A3");
  1862. Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4");
  1863. f.FormBorderStyle = FormBorderStyle.FixedDialog;
  1864. Assert.AreEqual (new Size (298, 298), f.Size, "A5");
  1865. Assert.AreEqual (new Size (292, 266), f.ClientSize, "A6");
  1866. f.FormBorderStyle = FormBorderStyle.FixedSingle;
  1867. Assert.AreEqual (new Size (298, 298), f.Size, "A7");
  1868. Assert.AreEqual (new Size (292, 266), f.ClientSize, "A8");
  1869. f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
  1870. Assert.AreEqual (new Size (298, 290), f.Size, "A9");
  1871. Assert.AreEqual (new Size (292, 266), f.ClientSize, "A0");
  1872. f.FormBorderStyle = FormBorderStyle.None;
  1873. Assert.AreEqual (new Size (292, 266), f.Size, "A11");
  1874. Assert.AreEqual (new Size (292, 266), f.ClientSize, "A12");
  1875. f.FormBorderStyle = FormBorderStyle.SizableToolWindow;
  1876. Assert.AreEqual (new Size (300, 292), f.Size, "A13");
  1877. Assert.AreEqual (new Size (292, 266), f.ClientSize, "A14");
  1878. f.FormBorderStyle = FormBorderStyle.Sizable;
  1879. Assert.AreEqual (new Size (300, 300), f.Size, "A15");
  1880. Assert.AreEqual (new Size (292, 266), f.ClientSize, "A16");
  1881. f.Close ();
  1882. }
  1883. [Test] // Bug #80574, #80791
  1884. [Category ("NotWorking")]
  1885. public void BehaviorResizeOnBorderStyleChangedNotVisible ()
  1886. {
  1887. // Marked NotWorking because the ClientSize is dependent on the WM.
  1888. // The values below match XP Luna to make sure our behavior is the same.
  1889. Form f = new Form ();
  1890. f.ShowInTaskbar = false;
  1891. Assert.AreEqual (false, f.IsHandleCreated, "A0");
  1892. Assert.AreEqual (new Size (300, 300), f.Size, "A1");
  1893. Assert.AreEqual (new Size (292, 266), f.ClientSize, "A2");
  1894. f.FormBorderStyle = FormBorderStyle.Fixed3D;
  1895. Assert.AreEqual (new Size (300, 300), f.Size, "A3");
  1896. Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4");
  1897. f.FormBorderStyle = FormBorderStyle.FixedDialog;
  1898. Assert.AreEqual (new Size (300, 300), f.Size, "A5");
  1899. Assert.AreEqual (new Size (292, 266), f.ClientSize, "A6");
  1900. f.FormBorderStyle = FormBorderStyle.FixedSingle;
  1901. Assert.AreEqual (new Size (300, 300), f.Size, "A7");
  1902. Assert.AreEqual (new Size (292, 266), f.ClientSize, "A8");
  1903. f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
  1904. Assert.AreEqual (new Size (300, 300), f.Size, "A9");
  1905. Assert.AreEqual (new Size (292, 266), f.ClientSize, "A0");
  1906. f.FormBorderStyle = FormBorderStyle.None;
  1907. Assert.AreEqual (new Size (300, 300), f.Size, "A11");
  1908. Assert.AreEqual (new Size (292, 266), f.ClientSize, "A12");
  1909. f.FormBorderStyle = FormBorderStyle.SizableToolWindow;
  1910. Assert.AreEqual (new Size (300, 300), f.Size, "A13");
  1911. Assert.AreEqual (new Size (292, 266), f.ClientSize, "A14");
  1912. f.FormBorderStyle = FormBorderStyle.Sizable;
  1913. Assert.AreEqual (new Size (300, 300), f.Size, "A15");
  1914. Assert.AreEqual (new Size (292, 266), f.ClientSize, "A16");
  1915. }
  1916. [Test] // Bug #80574, #80791
  1917. [Category ("NotWorking")]
  1918. public void MoreBehaviorResizeOnBorderStyleChangedNotVisible ()
  1919. {
  1920. // Marked NotWorking because the ClientSize is dependent on the WM.
  1921. // The values below match XP Luna to make sure our behavior is the same.
  1922. Form f = new Form ();
  1923. f.ShowInTaskbar = false;
  1924. f.Show ();
  1925. f.Hide ();
  1926. Assert.AreEqual (true, f.IsHandleCreated, "A0");
  1927. f.FormBorderStyle = FormBorderStyle.Sizable;
  1928. Assert.AreEqual (new Size (300, 300), f.Size, "A1");
  1929. Assert.AreEqual (new Size (292, 266), f.ClientSize, "A2");
  1930. f.FormBorderStyle = FormBorderStyle.None;
  1931. Assert.AreEqual (new Size (292, 266), f.Size, "A3");
  1932. Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4");
  1933. }
  1934. #endif
  1935. [Test] // bug #438866
  1936. public void MinMaxSize ()
  1937. {
  1938. Form f = new Form ();
  1939. f.MinimumSize = new Size (200, 200);
  1940. f.MaximumSize = new Size (150, 150);
  1941. Assert.AreEqual (new Size (150, 150), f.MinimumSize, "A1");
  1942. Assert.AreEqual (new Size (150, 150), f.MaximumSize, "A2");
  1943. f.MinimumSize = new Size (200, 200);
  1944. Assert.AreEqual (new Size (200, 200), f.MinimumSize, "A3");
  1945. Assert.AreEqual (new Size (200, 200), f.MaximumSize, "A4");
  1946. f.Dispose ();
  1947. }
  1948. [Test] // Bug #81582
  1949. [Category ("NotWorking")]
  1950. public void GotFocusWithoutCallingOnLoadBase ()
  1951. {
  1952. NoOnLoadBaseForm f = new NoOnLoadBaseForm ();
  1953. f.Show ();
  1954. Assert.AreEqual (true, f.got_focus_called, "H1");
  1955. f.Dispose ();
  1956. }
  1957. private class NoOnLoadBaseForm : Form
  1958. {
  1959. public bool got_focus_called = false;
  1960. public NoOnLoadBaseForm ()
  1961. {
  1962. TreeView tv = new TreeView ();
  1963. tv.GotFocus += new EventHandler (tv_GotFocus);
  1964. Controls.Add (tv);
  1965. }
  1966. void tv_GotFocus (object sender, EventArgs e)
  1967. {
  1968. got_focus_called = true;
  1969. }
  1970. protected override void OnLoad (EventArgs e)
  1971. {
  1972. }
  1973. }
  1974. [Test] // bug #339641
  1975. public void ChildFocused ()
  1976. {
  1977. // if (TestHelper.RunningOnUnix) {
  1978. // Assert.Ignore ("Relies on form.Show() synchronously generating WM_ACTIVATE");
  1979. // }
  1980. using (Form f = new TimeBombedForm ()) {
  1981. TreeView tv = new TreeView ();
  1982. EventLogger log = new EventLogger (tv);
  1983. tv.GotFocus += new EventHandler (tv_GotFocus);
  1984. f.Activated += new EventHandler (f_Activated);
  1985. f.Controls.Add (tv);
  1986. f.Show ();
  1987. Assert.IsTrue (log.EventRaised ("GotFocus"), "#01");
  1988. }
  1989. }
  1990. void f_Activated (object sender, EventArgs e)
  1991. {
  1992. //Console.WriteLine (" ACTIVATED");
  1993. //Console.WriteLine (Environment.StackTrace);
  1994. }
  1995. void tv_GotFocus (object sender, EventArgs e)
  1996. {
  1997. //Console.WriteLine (Environment.StackTrace);
  1998. }
  1999. [Test] // bug #80773
  2000. public void DontSetOwnerOnShowDialogException ()
  2001. {
  2002. Form f = new Form ();
  2003. f.ShowInTaskbar = false;
  2004. try { f.ShowDialog (f); }
  2005. catch { }
  2006. Assert.AreEqual (null, f.Owner, "H1");
  2007. f.Dispose ();
  2008. }
  2009. [Test]
  2010. public void MinimumWindowSize ()
  2011. {
  2012. Form f = new Form ();
  2013. f.ShowInTaskbar = false;
  2014. f.Show ();
  2015. f.Size = new Size (0, 0);
  2016. Assert.AreEqual (SystemInformation.MinimumWindowSize, f.Size);
  2017. f.Dispose ();
  2018. }
  2019. [Test]
  2020. public void Bug82470 ()
  2021. {
  2022. Form f = new Form ();
  2023. f.Load += new EventHandler (Form_LoadAndHide);
  2024. f.Show ();
  2025. Assert.AreEqual (true, f.Visible, "A1");
  2026. f.Dispose ();
  2027. }
  2028. private void Form_LoadAndHide (object sender, EventArgs e)
  2029. {
  2030. ((Form)sender).Visible = false;
  2031. }
  2032. #if NET_2_0
  2033. [Test]
  2034. public void AutoSizeGrowOnly ()
  2035. {
  2036. Form f = new Form ();
  2037. f.ShowInTaskbar = false;
  2038. f.AutoSize = true;
  2039. Button b = new Button ();
  2040. b.Size = new Size (200, 200);
  2041. b.Location = new Point (200, 200);
  2042. f.Controls.Add (b);
  2043. f.Show ();
  2044. Assert.AreEqual (new Size (403, 403), f.ClientSize, "A1");
  2045. f.Controls.Remove (b);
  2046. Assert.AreEqual (new Size (403, 403), f.ClientSize, "A2");
  2047. f.Dispose ();
  2048. }
  2049. [Test]
  2050. public void AutoSizeReset ()
  2051. {
  2052. Form f = new Form ();
  2053. f.ShowInTaskbar = false;
  2054. Button b = new Button ();
  2055. b.Size = new Size (200, 200);
  2056. b.Location = new Point (200, 200);
  2057. f.Controls.Add (b);
  2058. f.Show ();
  2059. Size start_size = f.ClientSize;
  2060. f.AutoSize = true;
  2061. Assert.AreEqual (new Size (403, 403), f.ClientSize, "A1");
  2062. f.AutoSize = false;
  2063. Assert.AreEqual (start_size, f.ClientSize, "A2");
  2064. f.Close ();
  2065. }
  2066. [Test]
  2067. public void AutoSizeGrowAndShrink ()
  2068. {
  2069. Form f = new Form ();
  2070. f.ShowInTaskbar = false;
  2071. f.AutoSize = true;
  2072. f.AutoSizeMode = AutoSizeMode.GrowAndShrink;
  2073. f.Show ();
  2074. // Make sure form shrunk
  2075. Assert.IsTrue (f.ClientSize.Width < 150, "A1");
  2076. Assert.IsTrue (f.ClientSize.Height < 150, "A1-2");
  2077. Button b = new Button ();
  2078. b.Size = new Size (200, 200);
  2079. b.Location = new Point (0, 0);
  2080. f.Controls.Add (b);
  2081. Assert.AreEqual (new Size (203, 203), f.ClientSize, "A2");
  2082. f.Dispose ();
  2083. }
  2084. [Test]
  2085. public void GetScaledBoundsTest ()
  2086. {
  2087. if (TestHelper.RunningOnUnix)
  2088. Assert.Ignore ("Depends on WM decoration sizes, values correspond to windows");
  2089. ScaleForm c = new ScaleForm ();
  2090. Rectangle r = new Rectangle (100, 200, 300, 400);
  2091. Assert.AreEqual (new Rectangle (100, 200, 584, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A1");
  2092. Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A2");
  2093. Assert.AreEqual (new Rectangle (100, 200, 584, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A3");
  2094. Assert.AreEqual (new Rectangle (100, 200, 300, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A4");
  2095. Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A5");
  2096. Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A6");
  2097. Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (1f, 1f), BoundsSpecified.All), "A6-2");
  2098. Assert.AreEqual (new Rectangle (100, 200, 584, 764), c.PublicGetScaledBounds (r, new SizeF (2f, 2f), BoundsSpecified.All), "A7");
  2099. Assert.AreEqual (new Rectangle (100, 200, 868, 1128), c.PublicGetScaledBounds (r, new SizeF (3f, 3f), BoundsSpecified.All), "A8");
  2100. Assert.AreEqual (new Rectangle (100, 200, 1152, 1492), c.PublicGetScaledBounds (r, new SizeF (4f, 4f), BoundsSpecified.All), "A9");
  2101. Assert.AreEqual (new Rectangle (100, 200, 158, 218), c.PublicGetScaledBounds (r, new SizeF (.5f, .5f), BoundsSpecified.All), "A10");
  2102. }
  2103. [Test]
  2104. public void MethodScaleControl ()
  2105. {
  2106. if (TestHelper.RunningOnUnix)
  2107. Assert.Ignore ("Depends on WM decoration sizes, values correspond to windows");
  2108. ScaleForm f = new ScaleForm ();
  2109. f.Location = new Point (5, 10);
  2110. Assert.AreEqual (new Rectangle (5, 10, 300, 300), f.Bounds, "A1");
  2111. f.PublicScaleControl (new SizeF (2.0f, 2.0f), BoundsSpecified.All);
  2112. Assert.AreEqual (new Rectangle (5, 10, 584, 564), f.Bounds, "A2");
  2113. f.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Location);
  2114. Assert.AreEqual (new Rectangle (5, 10, 584, 564), f.Bounds, "A3");
  2115. f.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Size);
  2116. Assert.AreEqual (new Rectangle (5, 10, 300, 300), f.Bounds, "A4");
  2117. f.PublicScaleControl (new SizeF (2.5f, 2.5f), BoundsSpecified.Size);
  2118. Assert.AreEqual (new Rectangle (5, 10, 726, 696), f.Bounds, "A5");
  2119. f.PublicScaleControl (new SizeF (.3f, .3f), BoundsSpecified.Size);
  2120. Assert.AreEqual (new Rectangle (5, 10, 229, 234), f.Bounds, "A6");
  2121. f.Dispose ();
  2122. }
  2123. private class ScaleForm : Form
  2124. {
  2125. public Rectangle PublicGetScaledBounds (Rectangle bounds, SizeF factor, BoundsSpecified specified)
  2126. {
  2127. return base.GetScaledBounds (bounds, factor, specified);
  2128. }
  2129. public void PublicScaleControl (SizeF factor, BoundsSpecified specified)
  2130. {
  2131. base.ScaleControl (factor, specified);
  2132. }
  2133. }
  2134. #endif
  2135. [Test]
  2136. public void Bug325436 ()
  2137. {
  2138. Form f = new Form ();
  2139. f.ShowInTaskbar = false;
  2140. f.ClientSize = new Size (320, 40);
  2141. f.ControlBox = false;
  2142. f.FormBorderStyle = FormBorderStyle.None;
  2143. f.MaximizeBox = false;
  2144. f.MinimizeBox = false;
  2145. f.Show ();
  2146. Assert.AreEqual (new Size (320, 40), f.ClientSize, "A1");
  2147. f.Dispose ();
  2148. f = new Form ();
  2149. f.ShowInTaskbar = false;
  2150. f.ControlBox = false;
  2151. f.FormBorderStyle = FormBorderStyle.None;
  2152. f.MaximizeBox = false;
  2153. f.MinimizeBox = false;
  2154. f.ClientSize = new Size(320, 40);
  2155. f.Show ();
  2156. Assert.AreEqual (new Size (320, 40), f.ClientSize, "A2");
  2157. f.Dispose ();
  2158. }
  2159. #if NET_2_0
  2160. #region PreferredSize
  2161. [Test]
  2162. public void PreferredSize ()
  2163. {
  2164. PreferredSizeForm form = new PreferredSizeForm ();
  2165. form.AutoSize = true;
  2166. Control control = new Control ();
  2167. form.Controls.Add (control);
  2168. control.Size = new Size (500, 500);
  2169. form.Test ();
  2170. form.Controls.Clear ();
  2171. form.Test2 ();
  2172. }
  2173. private class PreferredSizeForm : Form
  2174. {
  2175. public void Test ()
  2176. {
  2177. Assert.AreEqual (SizeFromClientSize (new Size (503, 503)), PreferredSize, "1");
  2178. }
  2179. public void Test2 ()
  2180. {
  2181. Assert.AreEqual (SizeFromClientSize (new Size (0, 0)), PreferredSize, "1");
  2182. }
  2183. }
  2184. #endregion
  2185. #endif
  2186. private class MockForm : Form
  2187. {
  2188. public bool CloseOnLoad {
  2189. get { return _closeOnLoad; }
  2190. set { _closeOnLoad = value; }
  2191. }
  2192. public bool VisibleOnLoad {
  2193. get { return _visibleOnLoad; }
  2194. }
  2195. protected override void OnLoad(EventArgs e) {
  2196. base.OnLoad(e);
  2197. _visibleOnLoad = Visible;
  2198. if (CloseOnLoad)
  2199. Close ();
  2200. }
  2201. private bool _closeOnLoad;
  2202. private bool _visibleOnLoad;
  2203. }
  2204. private class MockButton : Button
  2205. {
  2206. public MockButton (bool notify)
  2207. {
  2208. _notify = notify;
  2209. }
  2210. public bool Notify {
  2211. get { return _notify; }
  2212. set { _notify = value; }
  2213. }
  2214. public bool IsDefaultButton
  2215. {
  2216. get { return base.IsDefault; }
  2217. set { base.IsDefault = value; }
  2218. }
  2219. public override void NotifyDefault (bool value)
  2220. {
  2221. if (Notify)
  2222. base.NotifyDefault (value);
  2223. }
  2224. private bool _notify;
  2225. }
  2226. private class ButtonControl : IButtonControl
  2227. {
  2228. public DialogResult DialogResult {
  2229. get { return _dialogResult; }
  2230. set { _dialogResult = value; }
  2231. }
  2232. public bool IsDefaultButton {
  2233. get { return _isDefault; }
  2234. }
  2235. public void NotifyDefault (bool value)
  2236. {
  2237. _isDefault = value;
  2238. }
  2239. public void PerformClick ()
  2240. {
  2241. }
  2242. private bool _isDefault;
  2243. private DialogResult _dialogResult = DialogResult.None;
  2244. }
  2245. #if NET_2_0
  2246. [Test]
  2247. public void RestoreBounds ()
  2248. {
  2249. Form f = new Form ();
  2250. f.Show ();
  2251. Assert.AreEqual (new Size (300, 300), f.RestoreBounds.Size, "A1");
  2252. // Move the form
  2253. f.Location = new Point (0, 0);
  2254. Assert.AreEqual (new Rectangle (0, 0, 300, 300), f.RestoreBounds, "A2");
  2255. // Resize the form
  2256. f.Size = new Size (250, 250);
  2257. Assert.AreEqual (new Rectangle (0, 0, 250, 250), f.RestoreBounds, "A3");
  2258. // Minimize the form
  2259. f.WindowState = FormWindowState.Minimized;
  2260. Assert.AreEqual (new Rectangle (0, 0, 250, 250), f.RestoreBounds, "A4");
  2261. // Move the form (while minimized)
  2262. f.Location = new Point (10, 10);
  2263. Assert.AreEqual (new Rectangle (10, 10, 250, 250), f.RestoreBounds, "A5");
  2264. // Resize the form (while minimized)
  2265. f.Size = new Size (275, 275);
  2266. Assert.AreEqual (new Rectangle (10, 10, 275, 275), f.RestoreBounds, "A6");
  2267. // Maximize the form
  2268. f.WindowState = FormWindowState.Maximized;
  2269. Assert.AreEqual (new Rectangle (10, 10, 275, 275), f.RestoreBounds, "A7");
  2270. // Move the form (while maximized)
  2271. f.Location = new Point (20, 20);
  2272. Assert.AreEqual (new Rectangle (20, 20, 275, 275), f.RestoreBounds, "A8");
  2273. // Resize the form (while maximized)
  2274. f.Size = new Size (285, 285);
  2275. Assert.AreEqual (new Rectangle (20, 20, 285, 285), f.RestoreBounds, "A9");
  2276. f.Dispose ();
  2277. }
  2278. [Test] // Bug 353827
  2279. public void AutoScaleModeTest ()
  2280. {
  2281. Form f = new Form ();
  2282. // AutoScale starts off true
  2283. Assert.AreEqual (true, f.AutoScale, "A1");
  2284. // Setting AutoScaleMode turns AutoScale off
  2285. f.AutoScaleMode = AutoScaleMode.Font;
  2286. Assert.AreEqual (false, f.AutoScale, "A2");
  2287. Assert.AreEqual (AutoScaleMode.Font, f.AutoScaleMode, "A3");
  2288. // Changing Font resets AutoScaleBaseSize..
  2289. f.Font = new Font ("Arial", 10);
  2290. Assert.AreEqual (RoundSizeF (Form.GetAutoScaleSize (f.Font)), f.AutoScaleBaseSize, "A4");
  2291. f.Font = new Font ("Arial", 12);
  2292. Assert.AreEqual (RoundSizeF (Form.GetAutoScaleSize (f.Font)), f.AutoScaleBaseSize, "A5");
  2293. // ..Until AutoScaleBaseSize is explicitly set
  2294. f.AutoScaleBaseSize = new Size (5, 13);
  2295. Assert.AreEqual (new Size (5, 13), f.AutoScaleBaseSize, "A6");
  2296. f.Font = new Font ("Arial", 14F);
  2297. Assert.IsTrue (RoundSizeF (Form.GetAutoScaleSize (f.Font)) != f.AutoScaleBaseSize, "A5");
  2298. f.Dispose ();
  2299. }
  2300. private Size RoundSizeF (SizeF sizef)
  2301. {
  2302. return new Size ((int)Math.Round (sizef.Width), (int)Math.Round (sizef.Height));
  2303. }
  2304. [Test] // Bug 354669
  2305. public void AutoScaleDetails ()
  2306. {
  2307. ProtectedForm f = new ProtectedForm ();
  2308. f.Show ();
  2309. f.SuspendLayout ();
  2310. // First AutoScaleMode shouldn't reset AutoScaleDimensions
  2311. f.AutoScaleDimensions = new SizeF (3F, 3F);
  2312. f.AutoScaleMode = AutoScaleMode.Font;
  2313. Assert.AreEqual (new SizeF (3F, 3F), f.AutoScaleDimensions, "A1");
  2314. // Subsequent calls will reset it to 0, 0
  2315. f.AutoScaleMode = AutoScaleMode.Dpi;
  2316. Assert.AreEqual (SizeF.Empty, f.AutoScaleDimensions, "A2");
  2317. f.ResumeLayout ();
  2318. // CurrentAutoScaleDimensions should be nonzero
  2319. Assert.IsFalse (f.CurrentAutoScaleDimensions == SizeF.Empty, "A3");
  2320. // AutoScaleDimensions and CurrentAutoScaleDimensions should match after ResumeLayout
  2321. Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A4");
  2322. // CurrentAutoScaleDimensions should match AutoScaleDimensions for AutoScaleMode.None
  2323. f.SuspendLayout ();
  2324. f.AutoScaleMode = AutoScaleMode.None;
  2325. f.AutoScaleDimensions = new SizeF (5F, 5F);
  2326. Assert.AreEqual (new SizeF (5F, 5F), f.AutoScaleDimensions, "A5");
  2327. Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A6");
  2328. // ResumeLayout changes nothing
  2329. f.ResumeLayout ();
  2330. Assert.AreEqual (new SizeF (5F, 5F), f.AutoScaleDimensions, "A7");
  2331. Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A8");
  2332. // AutoScaleFactor should be ~2,2 if PerformAutoScale hasn't run
  2333. f.ClientSize = new Size (150, 150);
  2334. f.SuspendLayout ();
  2335. f.AutoScaleMode = AutoScaleMode.Dpi;
  2336. f.AutoScaleDimensions = new SizeF (f.CurrentAutoScaleDimensions.Width / 2F, f.CurrentAutoScaleDimensions.Height / 2F);
  2337. f.ClientSize = new Size (200, 200);
  2338. Assert.AreEqual (new Size (2, 2), RoundSizeF (f.GetPublicAutoScaleFactor ()), "A9");
  2339. // AutoScaleFactor should be 1 after ResumeLayout
  2340. f.ResumeLayout ();
  2341. Assert.AreEqual (new SizeF (1F, 1F), f.GetPublicAutoScaleFactor (), "A10");
  2342. Assert.AreEqual (new Size (400, 400), f.ClientSize, "A11");
  2343. // PerformAutoScale happens immediately when layout not suspended
  2344. f.ClientSize = new Size (125, 125);
  2345. f.AutoScaleDimensions = new SizeF (f.CurrentAutoScaleDimensions.Width / 2F, f.CurrentAutoScaleDimensions.Height / 2F);
  2346. Assert.AreEqual (new Size (250, 250), f.ClientSize, "A12");
  2347. f.Dispose ();
  2348. }
  2349. private class ProtectedForm : Form
  2350. {
  2351. public SizeF GetPublicAutoScaleFactor ()
  2352. {
  2353. return AutoScaleFactor;
  2354. }
  2355. }
  2356. [Test] // Bug #355703
  2357. public void AutoScaleSticks ()
  2358. {
  2359. Form f = new Form ();
  2360. f.AutoScale = false;
  2361. Assert.AreEqual (false, f.AutoScale, "A1");
  2362. f.AutoScale = true;
  2363. Assert.AreEqual (true, f.AutoScale, "A2");
  2364. f.AutoScaleMode = AutoScaleMode.None;
  2365. Assert.AreEqual (false, f.AutoScale, "A3");
  2366. }
  2367. #endif
  2368. [Test] // Bug #359098
  2369. public void AutoScaleBounds ()
  2370. {
  2371. AutoScaleForm a = new AutoScaleForm (false);
  2372. a.Show ();
  2373. Assert.AreEqual (new Size (213, 121), a.ClientSize, "A0");
  2374. Assert.AreEqual (new Rectangle ( 5, 107, 132, 9), new Rectangle (a.hScrollBar1.Location, a.hScrollBar1.Size), "A1");
  2375. Assert.AreEqual (new Rectangle (151, 74, 60, 44), new Rectangle (a.treeView1.Location, a.treeView1.Size), "A2");
  2376. Assert.AreEqual (new Rectangle (197, 21, 9, 39), new Rectangle (a.vScrollBar1.Location, a.vScrollBar1.Size), "A3");
  2377. Assert.AreEqual (new Rectangle (139, 21, 54, 49), new Rectangle (a.listView1.Location, a.listView1.Size), "A4");
  2378. Assert.AreEqual (new Rectangle ( 70, 5, 65, 37), new Rectangle (a.textBox2.Location, a.textBox2.Size), "A5");
  2379. Assert.AreEqual (new Rectangle (139, 5, 70, 0), new Rectangle (a.comboBox1.Location, new Size (a.comboBox1.Width, 0)), "A6");
  2380. Assert.AreEqual (new Rectangle ( 5, 77, 43, 13), new Rectangle (a.button2.Location, a.button2.Size), "A7");
  2381. Assert.AreEqual (new Rectangle ( 70, 44, 65, 37), new Rectangle (a.richTextBox1.Location, a.richTextBox1.Size), "A8");
  2382. Assert.AreEqual (new Rectangle ( 53, 86, 21, 7), new Rectangle (a.label1.Location,a.label1.Size), "A9");
  2383. Assert.AreEqual (new Rectangle ( 65, 84, 58, 0), new Rectangle (a.textBox1.Location, new Size (a.textBox1.Width, 0)), "A10");
  2384. Assert.AreEqual (new Rectangle ( 5, 63, 43, 13), new Rectangle (a.button1.Location, a.button1.Size), "A11");
  2385. Assert.AreEqual (new Rectangle ( 5, 5, 60, 47), new Rectangle (a.listBox1.Location, a.listBox1.Size), "A12");
  2386. a.Dispose ();
  2387. #if NET_2_0
  2388. a = new AutoScaleForm (true);
  2389. a.Show ();
  2390. Assert.AreEqual (new Size (184, 104), a.ClientSize, "B0");
  2391. Assert.AreEqual (new Rectangle ( 4, 92, 114, 16), new Rectangle (a.hScrollBar1.Location, a.hScrollBar1.ClientSize), "B1");
  2392. Assert.AreEqual (new Rectangle (130, 64, 50, 36), new Rectangle (a.treeView1.Location, a.treeView1.ClientSize), "B2");
  2393. Assert.AreEqual (new Rectangle (170, 18, 16, 34), new Rectangle (a.vScrollBar1.Location, a.vScrollBar1.ClientSize), "B3");
  2394. Assert.AreEqual (new Rectangle (120, 18, 44, 40), new Rectangle (a.listView1.Location, a.listView1.ClientSize), "B4");
  2395. Assert.AreEqual (new Rectangle ( 60, 4, 54, 30), new Rectangle (a.textBox2.Location, a.textBox2.ClientSize), "B5");
  2396. Assert.AreEqual (new Rectangle (120, 4, 62, 0), new Rectangle (a.comboBox1.Location, new Size (a.comboBox1.ClientSize.Width, 0)), "B6");
  2397. Assert.AreEqual (new Rectangle ( 4, 66, 38, 12), new Rectangle (a.button2.Location, a.button2.ClientSize), "B7");
  2398. Assert.AreEqual (new Rectangle ( 60, 38, 54, 30), new Rectangle (a.richTextBox1.Location, a.richTextBox1.ClientSize), "B8");
  2399. Assert.AreEqual (new Rectangle ( 46, 74, 18, 6), new Rectangle (a.label1.Location,a.label1.ClientSize), "B9");
  2400. Assert.AreEqual (new Rectangle ( 56, 72, 48, 0), new Rectangle (a.textBox1.Location, new Size (a.textBox1.ClientSize.Width, 0)), "B10");
  2401. Assert.AreEqual (new Rectangle ( 4, 54, 38, 12), new Rectangle (a.button1.Location, a.button1.ClientSize), "B11");
  2402. Assert.AreEqual (new Rectangle ( 4, 4, 50, 39), new Rectangle (a.listBox1.Location, a.listBox1.ClientSize), "B12");
  2403. a.Dispose ();
  2404. #endif
  2405. }
  2406. [Test]
  2407. public void SettingIconToNull ()
  2408. {
  2409. Form form = new Form ();
  2410. Assert.IsNotNull (form.Icon, "1");
  2411. form.Icon = null;
  2412. Assert.IsNotNull (form.Icon, "2");
  2413. }
  2414. [Test]
  2415. [Category ("NotWorking")]
  2416. public void MinimizedWindowSize ()
  2417. {
  2418. Form form = new Form ();
  2419. form.WindowState = FormWindowState.Minimized;
  2420. form.Show ();
  2421. Assert.AreEqual (SystemInformation.MinimizedWindowSize, form.Size, "1");
  2422. form.Close ();
  2423. form = new Form ();
  2424. form.Show ();
  2425. form.WindowState = FormWindowState.Minimized;
  2426. Assert.AreEqual (SystemInformation.MinimizedWindowSize, form.Size, "2");
  2427. form.Close ();
  2428. }
  2429. }
  2430. public class TimeBombedForm : Form
  2431. {
  2432. public Timer timer;
  2433. public bool CloseOnPaint;
  2434. public string Reason;
  2435. public TimeBombedForm ()
  2436. {
  2437. timer = new Timer ();
  2438. timer.Interval = 500;
  2439. timer.Tick += new EventHandler (timer_Tick);
  2440. timer.Start ();
  2441. }
  2442. void timer_Tick (object sender, EventArgs e)
  2443. {
  2444. Reason = "Bombed";
  2445. Close ();
  2446. }
  2447. protected override void OnPaint (PaintEventArgs pevent)
  2448. {
  2449. base.OnPaint (pevent);
  2450. if (CloseOnPaint) {
  2451. Reason = "OnPaint";
  2452. Close ();
  2453. }
  2454. }
  2455. }
  2456. public class AutoScaleForm : Form
  2457. {
  2458. public ListBox listBox1 = new ListBox ();
  2459. public ComboBox comboBox1 = new ComboBox ();
  2460. public Button button1 = new Button ();
  2461. public Button button2 = new Button ();
  2462. public Label label1 = new Label ();
  2463. public TextBox textBox1 = new TextBox ();
  2464. public TextBox textBox2 = new TextBox ();
  2465. public RichTextBox richTextBox1 = new RichTextBox ();
  2466. public ListView listView1 = new ListView ();
  2467. public TreeView treeView1 = new TreeView ();
  2468. public VScrollBar vScrollBar1 = new VScrollBar ();
  2469. public HScrollBar hScrollBar1 = new HScrollBar ();
  2470. public AutoScaleForm (bool use_new_auto_scale)
  2471. {
  2472. ShowInTaskbar = false;
  2473. SuspendLayout ();
  2474. listBox1.IntegralHeight = false;
  2475. listBox1.SetBounds (8, 8, 104, 82);
  2476. comboBox1.SetBounds (240, 8, 121, 21);
  2477. button1.SetBounds (8, 108, 75, 23);
  2478. button2.SetBounds (8, 132, 75, 23);
  2479. label1.SetBounds (92, 148, 35, 13);
  2480. textBox1.SetBounds (112, 144, 100, 20);
  2481. textBox2.Multiline = true;
  2482. textBox2.SetBounds (120, 8, 112, 64);
  2483. richTextBox1.SetBounds (120, 76, 112, 64);
  2484. listView1.SetBounds (240, 36, 92, 84);
  2485. treeView1.SetBounds (260, 128, 104, 76);
  2486. vScrollBar1.SetBounds (340, 36, 16, 68);
  2487. hScrollBar1.SetBounds (8, 184, 228, 16);
  2488. ClientSize = new Size (368, 209);
  2489. Controls.AddRange ( new Control [] { listBox1, comboBox1, button1, button2, label1, textBox1,
  2490. textBox2, richTextBox1, listView1, treeView1, vScrollBar1, hScrollBar1 } );
  2491. if (use_new_auto_scale) {
  2492. #if NET_2_0
  2493. AutoScaleMode = AutoScaleMode.Dpi;
  2494. SizeF s = CurrentAutoScaleDimensions;
  2495. AutoScaleDimensions = new SizeF (s.Width * 2, s.Height * 2);
  2496. #endif
  2497. }
  2498. else {
  2499. AutoScale = true;
  2500. SizeF s = Form.GetAutoScaleSize (Font);
  2501. AutoScaleBaseSize = new Size ((int)Math.Round (s.Width) * 2, (int)s.Height * 2);
  2502. }
  2503. ResumeLayout (false);
  2504. PerformLayout ();
  2505. }
  2506. }
  2507. }