FormTest.cs 116 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032
  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]
  1949. public void MinSizeIssue ()
  1950. {
  1951. Form f = new Form ();
  1952. f.MinimumSize = new Size (100, 100);
  1953. f.Show ();
  1954. Assert.AreEqual (new Size (300, 300), f.Size, "A1");
  1955. f.Dispose ();
  1956. }
  1957. [Test] // Bug #81582
  1958. [Category ("NotWorking")]
  1959. public void GotFocusWithoutCallingOnLoadBase ()
  1960. {
  1961. NoOnLoadBaseForm f = new NoOnLoadBaseForm ();
  1962. f.Show ();
  1963. Assert.AreEqual (true, f.got_focus_called, "H1");
  1964. f.Dispose ();
  1965. }
  1966. private class NoOnLoadBaseForm : Form
  1967. {
  1968. public bool got_focus_called = false;
  1969. public NoOnLoadBaseForm ()
  1970. {
  1971. TreeView tv = new TreeView ();
  1972. tv.GotFocus += new EventHandler (tv_GotFocus);
  1973. Controls.Add (tv);
  1974. }
  1975. void tv_GotFocus (object sender, EventArgs e)
  1976. {
  1977. got_focus_called = true;
  1978. }
  1979. protected override void OnLoad (EventArgs e)
  1980. {
  1981. }
  1982. }
  1983. [Test] // bug #339641
  1984. public void ChildFocused ()
  1985. {
  1986. // if (TestHelper.RunningOnUnix) {
  1987. // Assert.Ignore ("Relies on form.Show() synchronously generating WM_ACTIVATE");
  1988. // }
  1989. using (Form f = new TimeBombedForm ()) {
  1990. TreeView tv = new TreeView ();
  1991. EventLogger log = new EventLogger (tv);
  1992. tv.GotFocus += new EventHandler (tv_GotFocus);
  1993. f.Activated += new EventHandler (f_Activated);
  1994. f.Controls.Add (tv);
  1995. f.Show ();
  1996. Assert.IsTrue (log.EventRaised ("GotFocus"), "#01");
  1997. }
  1998. }
  1999. void f_Activated (object sender, EventArgs e)
  2000. {
  2001. //Console.WriteLine (" ACTIVATED");
  2002. //Console.WriteLine (Environment.StackTrace);
  2003. }
  2004. void tv_GotFocus (object sender, EventArgs e)
  2005. {
  2006. //Console.WriteLine (Environment.StackTrace);
  2007. }
  2008. [Test] // bug #80773
  2009. public void DontSetOwnerOnShowDialogException ()
  2010. {
  2011. Form f = new Form ();
  2012. f.ShowInTaskbar = false;
  2013. try { f.ShowDialog (f); }
  2014. catch { }
  2015. Assert.AreEqual (null, f.Owner, "H1");
  2016. f.Dispose ();
  2017. }
  2018. [Test]
  2019. public void MinimumWindowSize ()
  2020. {
  2021. Form f = new Form ();
  2022. f.ShowInTaskbar = false;
  2023. f.Show ();
  2024. f.Size = new Size (0, 0);
  2025. Assert.AreEqual (SystemInformation.MinimumWindowSize, f.Size);
  2026. f.Dispose ();
  2027. }
  2028. [Test]
  2029. public void Bug82470 ()
  2030. {
  2031. Form f = new Form ();
  2032. f.Load += new EventHandler (Form_LoadAndHide);
  2033. f.Show ();
  2034. Assert.AreEqual (true, f.Visible, "A1");
  2035. f.Dispose ();
  2036. }
  2037. private void Form_LoadAndHide (object sender, EventArgs e)
  2038. {
  2039. ((Form)sender).Visible = false;
  2040. }
  2041. #if NET_2_0
  2042. [Test]
  2043. public void AutoSizeGrowOnly ()
  2044. {
  2045. Form f = new Form ();
  2046. f.ShowInTaskbar = false;
  2047. f.AutoSize = true;
  2048. Button b = new Button ();
  2049. b.Size = new Size (200, 200);
  2050. b.Location = new Point (200, 200);
  2051. f.Controls.Add (b);
  2052. f.Show ();
  2053. Assert.AreEqual (new Size (403, 403), f.ClientSize, "A1");
  2054. f.Controls.Remove (b);
  2055. Assert.AreEqual (new Size (403, 403), f.ClientSize, "A2");
  2056. f.Dispose ();
  2057. }
  2058. [Test]
  2059. public void AutoSizeReset ()
  2060. {
  2061. Form f = new Form ();
  2062. f.ShowInTaskbar = false;
  2063. Button b = new Button ();
  2064. b.Size = new Size (200, 200);
  2065. b.Location = new Point (200, 200);
  2066. f.Controls.Add (b);
  2067. f.Show ();
  2068. Size start_size = f.ClientSize;
  2069. f.AutoSize = true;
  2070. Assert.AreEqual (new Size (403, 403), f.ClientSize, "A1");
  2071. f.AutoSize = false;
  2072. Assert.AreEqual (start_size, f.ClientSize, "A2");
  2073. f.Close ();
  2074. }
  2075. [Test]
  2076. public void AutoSizeGrowAndShrink ()
  2077. {
  2078. Form f = new Form ();
  2079. f.ShowInTaskbar = false;
  2080. f.AutoSize = true;
  2081. f.AutoSizeMode = AutoSizeMode.GrowAndShrink;
  2082. f.Show ();
  2083. // Make sure form shrunk
  2084. Assert.IsTrue (f.ClientSize.Width < 150, "A1");
  2085. Assert.IsTrue (f.ClientSize.Height < 150, "A1-2");
  2086. Button b = new Button ();
  2087. b.Size = new Size (200, 200);
  2088. b.Location = new Point (0, 0);
  2089. f.Controls.Add (b);
  2090. Assert.AreEqual (new Size (203, 203), f.ClientSize, "A2");
  2091. f.Dispose ();
  2092. }
  2093. [Test]
  2094. public void GetScaledBoundsTest ()
  2095. {
  2096. if (TestHelper.RunningOnUnix)
  2097. Assert.Ignore ("Depends on WM decoration sizes, values correspond to windows");
  2098. ScaleForm c = new ScaleForm ();
  2099. Rectangle r = new Rectangle (100, 200, 300, 400);
  2100. Assert.AreEqual (new Rectangle (100, 200, 584, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A1");
  2101. Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A2");
  2102. Assert.AreEqual (new Rectangle (100, 200, 584, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A3");
  2103. Assert.AreEqual (new Rectangle (100, 200, 300, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A4");
  2104. Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A5");
  2105. Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A6");
  2106. Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (1f, 1f), BoundsSpecified.All), "A6-2");
  2107. Assert.AreEqual (new Rectangle (100, 200, 584, 764), c.PublicGetScaledBounds (r, new SizeF (2f, 2f), BoundsSpecified.All), "A7");
  2108. Assert.AreEqual (new Rectangle (100, 200, 868, 1128), c.PublicGetScaledBounds (r, new SizeF (3f, 3f), BoundsSpecified.All), "A8");
  2109. Assert.AreEqual (new Rectangle (100, 200, 1152, 1492), c.PublicGetScaledBounds (r, new SizeF (4f, 4f), BoundsSpecified.All), "A9");
  2110. Assert.AreEqual (new Rectangle (100, 200, 158, 218), c.PublicGetScaledBounds (r, new SizeF (.5f, .5f), BoundsSpecified.All), "A10");
  2111. }
  2112. [Test]
  2113. public void MethodScaleControl ()
  2114. {
  2115. if (TestHelper.RunningOnUnix)
  2116. Assert.Ignore ("Depends on WM decoration sizes, values correspond to windows");
  2117. ScaleForm f = new ScaleForm ();
  2118. f.Location = new Point (5, 10);
  2119. Assert.AreEqual (new Rectangle (5, 10, 300, 300), f.Bounds, "A1");
  2120. f.PublicScaleControl (new SizeF (2.0f, 2.0f), BoundsSpecified.All);
  2121. Assert.AreEqual (new Rectangle (5, 10, 584, 564), f.Bounds, "A2");
  2122. f.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Location);
  2123. Assert.AreEqual (new Rectangle (5, 10, 584, 564), f.Bounds, "A3");
  2124. f.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Size);
  2125. Assert.AreEqual (new Rectangle (5, 10, 300, 300), f.Bounds, "A4");
  2126. f.PublicScaleControl (new SizeF (2.5f, 2.5f), BoundsSpecified.Size);
  2127. Assert.AreEqual (new Rectangle (5, 10, 726, 696), f.Bounds, "A5");
  2128. f.PublicScaleControl (new SizeF (.3f, .3f), BoundsSpecified.Size);
  2129. Assert.AreEqual (new Rectangle (5, 10, 229, 234), f.Bounds, "A6");
  2130. f.Dispose ();
  2131. }
  2132. private class ScaleForm : Form
  2133. {
  2134. public Rectangle PublicGetScaledBounds (Rectangle bounds, SizeF factor, BoundsSpecified specified)
  2135. {
  2136. return base.GetScaledBounds (bounds, factor, specified);
  2137. }
  2138. public void PublicScaleControl (SizeF factor, BoundsSpecified specified)
  2139. {
  2140. base.ScaleControl (factor, specified);
  2141. }
  2142. }
  2143. #endif
  2144. [Test]
  2145. public void Bug325436 ()
  2146. {
  2147. Form f = new Form ();
  2148. f.ShowInTaskbar = false;
  2149. f.ClientSize = new Size (320, 40);
  2150. f.ControlBox = false;
  2151. f.FormBorderStyle = FormBorderStyle.None;
  2152. f.MaximizeBox = false;
  2153. f.MinimizeBox = false;
  2154. f.Show ();
  2155. Assert.AreEqual (new Size (320, 40), f.ClientSize, "A1");
  2156. f.Dispose ();
  2157. f = new Form ();
  2158. f.ShowInTaskbar = false;
  2159. f.ControlBox = false;
  2160. f.FormBorderStyle = FormBorderStyle.None;
  2161. f.MaximizeBox = false;
  2162. f.MinimizeBox = false;
  2163. f.ClientSize = new Size(320, 40);
  2164. f.Show ();
  2165. Assert.AreEqual (new Size (320, 40), f.ClientSize, "A2");
  2166. f.Dispose ();
  2167. }
  2168. #if NET_2_0
  2169. #region PreferredSize
  2170. [Test]
  2171. public void PreferredSize ()
  2172. {
  2173. PreferredSizeForm form = new PreferredSizeForm ();
  2174. form.AutoSize = true;
  2175. Control control = new Control ();
  2176. form.Controls.Add (control);
  2177. control.Size = new Size (500, 500);
  2178. form.Test ();
  2179. form.Controls.Clear ();
  2180. form.Test2 ();
  2181. }
  2182. private class PreferredSizeForm : Form
  2183. {
  2184. public void Test ()
  2185. {
  2186. Assert.AreEqual (SizeFromClientSize (new Size (503, 503)), PreferredSize, "1");
  2187. }
  2188. public void Test2 ()
  2189. {
  2190. Assert.AreEqual (SizeFromClientSize (new Size (0, 0)), PreferredSize, "1");
  2191. }
  2192. }
  2193. #endregion
  2194. #endif
  2195. private class MockForm : Form
  2196. {
  2197. public bool CloseOnLoad {
  2198. get { return _closeOnLoad; }
  2199. set { _closeOnLoad = value; }
  2200. }
  2201. public bool VisibleOnLoad {
  2202. get { return _visibleOnLoad; }
  2203. }
  2204. protected override void OnLoad(EventArgs e) {
  2205. base.OnLoad(e);
  2206. _visibleOnLoad = Visible;
  2207. if (CloseOnLoad)
  2208. Close ();
  2209. }
  2210. private bool _closeOnLoad;
  2211. private bool _visibleOnLoad;
  2212. }
  2213. private class MockButton : Button
  2214. {
  2215. public MockButton (bool notify)
  2216. {
  2217. _notify = notify;
  2218. }
  2219. public bool Notify {
  2220. get { return _notify; }
  2221. set { _notify = value; }
  2222. }
  2223. public bool IsDefaultButton
  2224. {
  2225. get { return base.IsDefault; }
  2226. set { base.IsDefault = value; }
  2227. }
  2228. public override void NotifyDefault (bool value)
  2229. {
  2230. if (Notify)
  2231. base.NotifyDefault (value);
  2232. }
  2233. private bool _notify;
  2234. }
  2235. private class ButtonControl : IButtonControl
  2236. {
  2237. public DialogResult DialogResult {
  2238. get { return _dialogResult; }
  2239. set { _dialogResult = value; }
  2240. }
  2241. public bool IsDefaultButton {
  2242. get { return _isDefault; }
  2243. }
  2244. public void NotifyDefault (bool value)
  2245. {
  2246. _isDefault = value;
  2247. }
  2248. public void PerformClick ()
  2249. {
  2250. }
  2251. private bool _isDefault;
  2252. private DialogResult _dialogResult = DialogResult.None;
  2253. }
  2254. #if NET_2_0
  2255. [Test]
  2256. public void RestoreBounds ()
  2257. {
  2258. Form f = new Form ();
  2259. f.Show ();
  2260. Assert.AreEqual (new Size (300, 300), f.RestoreBounds.Size, "A1");
  2261. // Move the form
  2262. f.Location = new Point (0, 0);
  2263. Assert.AreEqual (new Rectangle (0, 0, 300, 300), f.RestoreBounds, "A2");
  2264. // Resize the form
  2265. f.Size = new Size (250, 250);
  2266. Assert.AreEqual (new Rectangle (0, 0, 250, 250), f.RestoreBounds, "A3");
  2267. // Minimize the form
  2268. f.WindowState = FormWindowState.Minimized;
  2269. Assert.AreEqual (new Rectangle (0, 0, 250, 250), f.RestoreBounds, "A4");
  2270. // Move the form (while minimized)
  2271. f.Location = new Point (10, 10);
  2272. Assert.AreEqual (new Rectangle (10, 10, 250, 250), f.RestoreBounds, "A5");
  2273. // Resize the form (while minimized)
  2274. f.Size = new Size (275, 275);
  2275. Assert.AreEqual (new Rectangle (10, 10, 275, 275), f.RestoreBounds, "A6");
  2276. // Maximize the form
  2277. f.WindowState = FormWindowState.Maximized;
  2278. Assert.AreEqual (new Rectangle (10, 10, 275, 275), f.RestoreBounds, "A7");
  2279. // Move the form (while maximized)
  2280. f.Location = new Point (20, 20);
  2281. Assert.AreEqual (new Rectangle (20, 20, 275, 275), f.RestoreBounds, "A8");
  2282. // Resize the form (while maximized)
  2283. f.Size = new Size (285, 285);
  2284. Assert.AreEqual (new Rectangle (20, 20, 285, 285), f.RestoreBounds, "A9");
  2285. f.Dispose ();
  2286. }
  2287. [Test] // Bug 353827
  2288. public void AutoScaleModeTest ()
  2289. {
  2290. Form f = new Form ();
  2291. // AutoScale starts off true
  2292. Assert.AreEqual (true, f.AutoScale, "A1");
  2293. // Setting AutoScaleMode turns AutoScale off
  2294. f.AutoScaleMode = AutoScaleMode.Font;
  2295. Assert.AreEqual (false, f.AutoScale, "A2");
  2296. Assert.AreEqual (AutoScaleMode.Font, f.AutoScaleMode, "A3");
  2297. // Changing Font resets AutoScaleBaseSize..
  2298. f.Font = new Font ("Arial", 10);
  2299. Assert.AreEqual (RoundSizeF (Form.GetAutoScaleSize (f.Font)), f.AutoScaleBaseSize, "A4");
  2300. f.Font = new Font ("Arial", 12);
  2301. Assert.AreEqual (RoundSizeF (Form.GetAutoScaleSize (f.Font)), f.AutoScaleBaseSize, "A5");
  2302. // ..Until AutoScaleBaseSize is explicitly set
  2303. f.AutoScaleBaseSize = new Size (5, 13);
  2304. Assert.AreEqual (new Size (5, 13), f.AutoScaleBaseSize, "A6");
  2305. f.Font = new Font ("Arial", 14F);
  2306. Assert.IsTrue (RoundSizeF (Form.GetAutoScaleSize (f.Font)) != f.AutoScaleBaseSize, "A5");
  2307. f.Dispose ();
  2308. }
  2309. private Size RoundSizeF (SizeF sizef)
  2310. {
  2311. return new Size ((int)Math.Round (sizef.Width), (int)Math.Round (sizef.Height));
  2312. }
  2313. [Test] // Bug 354669
  2314. public void AutoScaleDetails ()
  2315. {
  2316. ProtectedForm f = new ProtectedForm ();
  2317. f.Show ();
  2318. f.SuspendLayout ();
  2319. // First AutoScaleMode shouldn't reset AutoScaleDimensions
  2320. f.AutoScaleDimensions = new SizeF (3F, 3F);
  2321. f.AutoScaleMode = AutoScaleMode.Font;
  2322. Assert.AreEqual (new SizeF (3F, 3F), f.AutoScaleDimensions, "A1");
  2323. // Subsequent calls will reset it to 0, 0
  2324. f.AutoScaleMode = AutoScaleMode.Dpi;
  2325. Assert.AreEqual (SizeF.Empty, f.AutoScaleDimensions, "A2");
  2326. f.ResumeLayout ();
  2327. // CurrentAutoScaleDimensions should be nonzero
  2328. Assert.IsFalse (f.CurrentAutoScaleDimensions == SizeF.Empty, "A3");
  2329. // AutoScaleDimensions and CurrentAutoScaleDimensions should match after ResumeLayout
  2330. Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A4");
  2331. // CurrentAutoScaleDimensions should match AutoScaleDimensions for AutoScaleMode.None
  2332. f.SuspendLayout ();
  2333. f.AutoScaleMode = AutoScaleMode.None;
  2334. f.AutoScaleDimensions = new SizeF (5F, 5F);
  2335. Assert.AreEqual (new SizeF (5F, 5F), f.AutoScaleDimensions, "A5");
  2336. Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A6");
  2337. // ResumeLayout changes nothing
  2338. f.ResumeLayout ();
  2339. Assert.AreEqual (new SizeF (5F, 5F), f.AutoScaleDimensions, "A7");
  2340. Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A8");
  2341. // AutoScaleFactor should be ~2,2 if PerformAutoScale hasn't run
  2342. f.ClientSize = new Size (150, 150);
  2343. f.SuspendLayout ();
  2344. f.AutoScaleMode = AutoScaleMode.Dpi;
  2345. f.AutoScaleDimensions = new SizeF (f.CurrentAutoScaleDimensions.Width / 2F, f.CurrentAutoScaleDimensions.Height / 2F);
  2346. f.ClientSize = new Size (200, 200);
  2347. Assert.AreEqual (new Size (2, 2), RoundSizeF (f.GetPublicAutoScaleFactor ()), "A9");
  2348. // AutoScaleFactor should be 1 after ResumeLayout
  2349. f.ResumeLayout ();
  2350. Assert.AreEqual (new SizeF (1F, 1F), f.GetPublicAutoScaleFactor (), "A10");
  2351. Assert.AreEqual (new Size (400, 400), f.ClientSize, "A11");
  2352. // PerformAutoScale happens immediately when layout not suspended
  2353. f.ClientSize = new Size (125, 125);
  2354. f.AutoScaleDimensions = new SizeF (f.CurrentAutoScaleDimensions.Width / 2F, f.CurrentAutoScaleDimensions.Height / 2F);
  2355. Assert.AreEqual (new Size (250, 250), f.ClientSize, "A12");
  2356. f.Dispose ();
  2357. }
  2358. private class ProtectedForm : Form
  2359. {
  2360. public SizeF GetPublicAutoScaleFactor ()
  2361. {
  2362. return AutoScaleFactor;
  2363. }
  2364. }
  2365. [Test] // Bug #355703
  2366. public void AutoScaleSticks ()
  2367. {
  2368. Form f = new Form ();
  2369. f.AutoScale = false;
  2370. Assert.AreEqual (false, f.AutoScale, "A1");
  2371. f.AutoScale = true;
  2372. Assert.AreEqual (true, f.AutoScale, "A2");
  2373. f.AutoScaleMode = AutoScaleMode.None;
  2374. Assert.AreEqual (false, f.AutoScale, "A3");
  2375. }
  2376. #endif
  2377. [Test] // Bug #359098
  2378. public void AutoScaleBounds ()
  2379. {
  2380. AutoScaleForm a = new AutoScaleForm (false);
  2381. a.Show ();
  2382. Assert.AreEqual (new Size (213, 121), a.ClientSize, "A0");
  2383. Assert.AreEqual (new Rectangle ( 5, 107, 132, 9), new Rectangle (a.hScrollBar1.Location, a.hScrollBar1.Size), "A1");
  2384. Assert.AreEqual (new Rectangle (151, 74, 60, 44), new Rectangle (a.treeView1.Location, a.treeView1.Size), "A2");
  2385. Assert.AreEqual (new Rectangle (197, 21, 9, 39), new Rectangle (a.vScrollBar1.Location, a.vScrollBar1.Size), "A3");
  2386. Assert.AreEqual (new Rectangle (139, 21, 54, 49), new Rectangle (a.listView1.Location, a.listView1.Size), "A4");
  2387. Assert.AreEqual (new Rectangle ( 70, 5, 65, 37), new Rectangle (a.textBox2.Location, a.textBox2.Size), "A5");
  2388. Assert.AreEqual (new Rectangle (139, 5, 70, 0), new Rectangle (a.comboBox1.Location, new Size (a.comboBox1.Width, 0)), "A6");
  2389. Assert.AreEqual (new Rectangle ( 5, 77, 43, 13), new Rectangle (a.button2.Location, a.button2.Size), "A7");
  2390. Assert.AreEqual (new Rectangle ( 70, 44, 65, 37), new Rectangle (a.richTextBox1.Location, a.richTextBox1.Size), "A8");
  2391. Assert.AreEqual (new Rectangle ( 53, 86, 21, 7), new Rectangle (a.label1.Location,a.label1.Size), "A9");
  2392. Assert.AreEqual (new Rectangle ( 65, 84, 58, 0), new Rectangle (a.textBox1.Location, new Size (a.textBox1.Width, 0)), "A10");
  2393. Assert.AreEqual (new Rectangle ( 5, 63, 43, 13), new Rectangle (a.button1.Location, a.button1.Size), "A11");
  2394. Assert.AreEqual (new Rectangle ( 5, 5, 60, 47), new Rectangle (a.listBox1.Location, a.listBox1.Size), "A12");
  2395. a.Dispose ();
  2396. #if NET_2_0
  2397. a = new AutoScaleForm (true);
  2398. a.Show ();
  2399. Assert.AreEqual (new Size (184, 104), a.ClientSize, "B0");
  2400. Assert.AreEqual (new Rectangle ( 4, 92, 114, 16), new Rectangle (a.hScrollBar1.Location, a.hScrollBar1.ClientSize), "B1");
  2401. Assert.AreEqual (new Rectangle (130, 64, 50, 36), new Rectangle (a.treeView1.Location, a.treeView1.ClientSize), "B2");
  2402. Assert.AreEqual (new Rectangle (170, 18, 16, 34), new Rectangle (a.vScrollBar1.Location, a.vScrollBar1.ClientSize), "B3");
  2403. Assert.AreEqual (new Rectangle (120, 18, 44, 40), new Rectangle (a.listView1.Location, a.listView1.ClientSize), "B4");
  2404. Assert.AreEqual (new Rectangle ( 60, 4, 54, 30), new Rectangle (a.textBox2.Location, a.textBox2.ClientSize), "B5");
  2405. Assert.AreEqual (new Rectangle (120, 4, 62, 0), new Rectangle (a.comboBox1.Location, new Size (a.comboBox1.ClientSize.Width, 0)), "B6");
  2406. Assert.AreEqual (new Rectangle ( 4, 66, 38, 12), new Rectangle (a.button2.Location, a.button2.ClientSize), "B7");
  2407. Assert.AreEqual (new Rectangle ( 60, 38, 54, 30), new Rectangle (a.richTextBox1.Location, a.richTextBox1.ClientSize), "B8");
  2408. Assert.AreEqual (new Rectangle ( 46, 74, 18, 6), new Rectangle (a.label1.Location,a.label1.ClientSize), "B9");
  2409. Assert.AreEqual (new Rectangle ( 56, 72, 48, 0), new Rectangle (a.textBox1.Location, new Size (a.textBox1.ClientSize.Width, 0)), "B10");
  2410. Assert.AreEqual (new Rectangle ( 4, 54, 38, 12), new Rectangle (a.button1.Location, a.button1.ClientSize), "B11");
  2411. Assert.AreEqual (new Rectangle ( 4, 4, 50, 39), new Rectangle (a.listBox1.Location, a.listBox1.ClientSize), "B12");
  2412. a.Dispose ();
  2413. #endif
  2414. }
  2415. [Test]
  2416. public void SettingIconToNull ()
  2417. {
  2418. Form form = new Form ();
  2419. Assert.IsNotNull (form.Icon, "1");
  2420. form.Icon = null;
  2421. Assert.IsNotNull (form.Icon, "2");
  2422. }
  2423. [Test]
  2424. [Category ("NotWorking")]
  2425. public void MinimizedWindowSize ()
  2426. {
  2427. Form form = new Form ();
  2428. form.WindowState = FormWindowState.Minimized;
  2429. form.Show ();
  2430. Assert.AreEqual (SystemInformation.MinimizedWindowSize, form.Size, "1");
  2431. form.Close ();
  2432. form = new Form ();
  2433. form.Show ();
  2434. form.WindowState = FormWindowState.Minimized;
  2435. Assert.AreEqual (SystemInformation.MinimizedWindowSize, form.Size, "2");
  2436. form.Close ();
  2437. }
  2438. }
  2439. public class TimeBombedForm : Form
  2440. {
  2441. public Timer timer;
  2442. public bool CloseOnPaint;
  2443. public string Reason;
  2444. public TimeBombedForm ()
  2445. {
  2446. timer = new Timer ();
  2447. timer.Interval = 500;
  2448. timer.Tick += new EventHandler (timer_Tick);
  2449. timer.Start ();
  2450. }
  2451. void timer_Tick (object sender, EventArgs e)
  2452. {
  2453. Reason = "Bombed";
  2454. Close ();
  2455. }
  2456. protected override void OnPaint (PaintEventArgs pevent)
  2457. {
  2458. base.OnPaint (pevent);
  2459. if (CloseOnPaint) {
  2460. Reason = "OnPaint";
  2461. Close ();
  2462. }
  2463. }
  2464. }
  2465. public class AutoScaleForm : Form
  2466. {
  2467. public ListBox listBox1 = new ListBox ();
  2468. public ComboBox comboBox1 = new ComboBox ();
  2469. public Button button1 = new Button ();
  2470. public Button button2 = new Button ();
  2471. public Label label1 = new Label ();
  2472. public TextBox textBox1 = new TextBox ();
  2473. public TextBox textBox2 = new TextBox ();
  2474. public RichTextBox richTextBox1 = new RichTextBox ();
  2475. public ListView listView1 = new ListView ();
  2476. public TreeView treeView1 = new TreeView ();
  2477. public VScrollBar vScrollBar1 = new VScrollBar ();
  2478. public HScrollBar hScrollBar1 = new HScrollBar ();
  2479. public AutoScaleForm (bool use_new_auto_scale)
  2480. {
  2481. ShowInTaskbar = false;
  2482. SuspendLayout ();
  2483. listBox1.IntegralHeight = false;
  2484. listBox1.SetBounds (8, 8, 104, 82);
  2485. comboBox1.SetBounds (240, 8, 121, 21);
  2486. button1.SetBounds (8, 108, 75, 23);
  2487. button2.SetBounds (8, 132, 75, 23);
  2488. label1.SetBounds (92, 148, 35, 13);
  2489. textBox1.SetBounds (112, 144, 100, 20);
  2490. textBox2.Multiline = true;
  2491. textBox2.SetBounds (120, 8, 112, 64);
  2492. richTextBox1.SetBounds (120, 76, 112, 64);
  2493. listView1.SetBounds (240, 36, 92, 84);
  2494. treeView1.SetBounds (260, 128, 104, 76);
  2495. vScrollBar1.SetBounds (340, 36, 16, 68);
  2496. hScrollBar1.SetBounds (8, 184, 228, 16);
  2497. ClientSize = new Size (368, 209);
  2498. Controls.AddRange ( new Control [] { listBox1, comboBox1, button1, button2, label1, textBox1,
  2499. textBox2, richTextBox1, listView1, treeView1, vScrollBar1, hScrollBar1 } );
  2500. if (use_new_auto_scale) {
  2501. #if NET_2_0
  2502. AutoScaleMode = AutoScaleMode.Dpi;
  2503. SizeF s = CurrentAutoScaleDimensions;
  2504. AutoScaleDimensions = new SizeF (s.Width * 2, s.Height * 2);
  2505. #endif
  2506. }
  2507. else {
  2508. AutoScale = true;
  2509. SizeF s = Form.GetAutoScaleSize (Font);
  2510. AutoScaleBaseSize = new Size ((int)Math.Round (s.Width) * 2, (int)s.Height * 2);
  2511. }
  2512. ResumeLayout (false);
  2513. PerformLayout ();
  2514. }
  2515. }
  2516. }