WindowsFormsReplacement.cs 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.ComponentModel;
  5. using System.Globalization;
  6. using System.Drawing;
  7. #pragma warning disable 1591 // disable missing xml comments warning
  8. #pragma warning disable FR0000 // Field must be texted in lowerCamelCase.
  9. namespace System.Windows.Forms
  10. {
  11. #region Enums
  12. [Flags]
  13. public enum Keys
  14. {
  15. Modifiers = -65536,
  16. None = 0,
  17. LButton = 1,
  18. RButton = 2,
  19. Cancel = 3,
  20. MButton = 4,
  21. XButton1 = 5,
  22. XButton2 = 6,
  23. Back = 8,
  24. Tab = 9,
  25. LineFeed = 10,
  26. Clear = 12,
  27. Return = 13,
  28. Enter = 13,
  29. ShiftKey = 16,
  30. ControlKey = 17,
  31. Menu = 18,
  32. Pause = 19,
  33. Capital = 20,
  34. CapsLock = 20,
  35. KanaMode = 21,
  36. HanguelMode = 21,
  37. HangulMode = 21,
  38. JunjaMode = 23,
  39. FinalMode = 24,
  40. HanjaMode = 25,
  41. KanjiMode = 25,
  42. Escape = 27,
  43. IMEConvert = 28,
  44. IMENonconvert = 29,
  45. IMEAccept = 30,
  46. IMEAceept = 30,
  47. IMEModeChange = 31,
  48. Space = 32,
  49. Prior = 33,
  50. PageUp = 33,
  51. Next = 34,
  52. PageDown = 34,
  53. End = 35,
  54. Home = 36,
  55. Left = 37,
  56. Up = 38,
  57. Right = 39,
  58. Down = 40,
  59. Select = 41,
  60. Print = 42,
  61. Execute = 43,
  62. Snapshot = 44,
  63. PrintScreen = 44,
  64. Insert = 45,
  65. Delete = 46,
  66. Help = 47,
  67. D0 = 48,
  68. D1 = 49,
  69. D2 = 50,
  70. D3 = 51,
  71. D4 = 52,
  72. D5 = 53,
  73. D6 = 54,
  74. D7 = 55,
  75. D8 = 56,
  76. D9 = 57,
  77. A = 65,
  78. B = 66,
  79. C = 67,
  80. D = 68,
  81. E = 69,
  82. F = 70,
  83. G = 71,
  84. H = 72,
  85. I = 73,
  86. J = 74,
  87. K = 75,
  88. L = 76,
  89. M = 77,
  90. N = 78,
  91. O = 79,
  92. P = 80,
  93. Q = 81,
  94. R = 82,
  95. S = 83,
  96. T = 84,
  97. U = 85,
  98. V = 86,
  99. W = 87,
  100. X = 88,
  101. Y = 89,
  102. Z = 90,
  103. LWin = 91,
  104. RWin = 92,
  105. Apps = 93,
  106. Sleep = 95,
  107. NumPad0 = 96,
  108. NumPad1 = 97,
  109. NumPad2 = 98,
  110. NumPad3 = 99,
  111. NumPad4 = 100,
  112. NumPad5 = 101,
  113. NumPad6 = 102,
  114. NumPad7 = 103,
  115. NumPad8 = 104,
  116. NumPad9 = 105,
  117. Multiply = 106,
  118. Add = 107,
  119. Separator = 108,
  120. Subtract = 109,
  121. Decimal = 110,
  122. Divide = 111,
  123. F1 = 112,
  124. F2 = 113,
  125. F3 = 114,
  126. F4 = 115,
  127. F5 = 116,
  128. F6 = 117,
  129. F7 = 118,
  130. F8 = 119,
  131. F9 = 120,
  132. F10 = 121,
  133. F11 = 122,
  134. F12 = 123,
  135. F13 = 124,
  136. F14 = 125,
  137. F15 = 126,
  138. F16 = 127,
  139. F17 = 128,
  140. F18 = 129,
  141. F19 = 130,
  142. F20 = 131,
  143. F21 = 132,
  144. F22 = 133,
  145. F23 = 134,
  146. F24 = 135,
  147. NumLock = 144,
  148. Scroll = 145,
  149. LShiftKey = 160,
  150. RShiftKey = 161,
  151. LControlKey = 162,
  152. RControlKey = 163,
  153. LMenu = 164,
  154. RMenu = 165,
  155. BrowserBack = 166,
  156. BrowserForward = 167,
  157. BrowserRefresh = 168,
  158. BrowserStop = 169,
  159. BrowserSearch = 170,
  160. BrowserFavorites = 171,
  161. BrowserHome = 172,
  162. VolumeMute = 173,
  163. VolumeDown = 174,
  164. VolumeUp = 175,
  165. MediaNextTrack = 176,
  166. MediaPreviousTrack = 177,
  167. MediaStop = 178,
  168. MediaPlayPause = 179,
  169. LaunchMail = 180,
  170. SelectMedia = 181,
  171. LaunchApplication1 = 182,
  172. LaunchApplication2 = 183,
  173. OemSemicolon = 186,
  174. Oem1 = 186,
  175. Oemplus = 187,
  176. Oemcomma = 188,
  177. OemMinus = 189,
  178. OemPeriod = 190,
  179. OemQuestion = 191,
  180. Oem2 = 191,
  181. Oemtilde = 192,
  182. Oem3 = 192,
  183. OemOpenBrackets = 219,
  184. Oem4 = 219,
  185. OemPipe = 220,
  186. Oem5 = 220,
  187. OemCloseBrackets = 221,
  188. Oem6 = 221,
  189. OemQuotes = 222,
  190. Oem7 = 222,
  191. Oem8 = 223,
  192. OemBackslash = 226,
  193. Oem102 = 226,
  194. ProcessKey = 229,
  195. Packet = 231,
  196. Attn = 246,
  197. Crsel = 247,
  198. Exsel = 248,
  199. EraseEof = 249,
  200. Play = 250,
  201. Zoom = 251,
  202. NoName = 252,
  203. Pa1 = 253,
  204. OemClear = 254,
  205. KeyCode = 65535,
  206. Shift = 65536,
  207. Control = 131072,
  208. Alt = 262144
  209. }
  210. [Flags]
  211. public enum MouseButtons
  212. {
  213. None = 0,
  214. Left = 1048576,
  215. Right = 2097152,
  216. Middle = 4194304,
  217. XButton1 = 8388608,
  218. XButton2 = 16777216
  219. }
  220. [Flags]
  221. public enum AnchorStyles
  222. {
  223. None = 0,
  224. Top = 1,
  225. Bottom = 2,
  226. Left = 4,
  227. Right = 8
  228. }
  229. public enum DockStyle
  230. {
  231. None,
  232. Top,
  233. Bottom,
  234. Left,
  235. Right,
  236. Fill
  237. }
  238. public enum PictureBoxSizeMode
  239. {
  240. Normal,
  241. StretchImage,
  242. AutoSize,
  243. CenterImage,
  244. Zoom
  245. }
  246. public enum RightToLeft
  247. {
  248. No,
  249. Yes,
  250. Inherit
  251. }
  252. public enum TextImageRelation
  253. {
  254. Overlay,
  255. ImageBeforeText,
  256. TextBeforeImage,
  257. ImageAboveText,
  258. TextAboveImage
  259. };
  260. public enum DialogResult
  261. {
  262. None,
  263. OK,
  264. Cancel,
  265. Abort,
  266. Retry,
  267. Ignore,
  268. Yes,
  269. No
  270. }
  271. public enum Appearance
  272. {
  273. Normal,
  274. Button
  275. }
  276. public enum CheckState
  277. {
  278. Unchecked,
  279. Checked,
  280. Indeterminate
  281. }
  282. public enum DrawMode
  283. {
  284. Normal,
  285. OwnerDrawFixed,
  286. OwnerDrawVariable
  287. }
  288. public enum SelectionMode
  289. {
  290. None,
  291. One,
  292. MultiSimple,
  293. MultiExtended
  294. }
  295. public enum ComboBoxStyle
  296. {
  297. Simple,
  298. DropDown,
  299. DropDownList
  300. }
  301. public enum LeftRightAlignment
  302. {
  303. Left,
  304. Right
  305. }
  306. public enum Day
  307. {
  308. Monday,
  309. Tuesday,
  310. Wednesday,
  311. Thursday,
  312. Friday,
  313. Saturday,
  314. Sunday,
  315. Default
  316. }
  317. public enum CharacterCasing
  318. {
  319. Normal,
  320. Upper,
  321. Lower
  322. }
  323. public enum ScrollBars
  324. {
  325. None,
  326. Horizontal,
  327. Vertical,
  328. Both
  329. }
  330. public enum HorizontalAlignment
  331. {
  332. Left,
  333. Right,
  334. Center
  335. }
  336. public enum DateTimePickerFormat
  337. {
  338. Long,
  339. Short,
  340. Time,
  341. Custom
  342. }
  343. public enum FormBorderStyle
  344. {
  345. None,
  346. FixedSingle,
  347. Fixed3D,
  348. FixedDialog,
  349. Sizable,
  350. FixedToolWindow,
  351. SizableToolWindow
  352. }
  353. public enum FormStartPosition
  354. {
  355. Manual,
  356. CenterScreen,
  357. WindowsDefaultLocation,
  358. WindowsDefaultBounds,
  359. CenterParent
  360. }
  361. public enum CloseReason
  362. {
  363. None,
  364. WindowsShutDown,
  365. MdiFormClosing,
  366. UserClosing,
  367. TaskManagerClosing,
  368. FormOwnerClosing,
  369. ApplicationExitCall
  370. }
  371. public enum BorderStyle
  372. {
  373. Fixed3D,
  374. FixedSingle,
  375. None
  376. }
  377. public enum ControlStyles
  378. {
  379. ContainerControl = 0x00000001,
  380. UserPaint = 0x00000002,
  381. Opaque = 0x00000004,
  382. ResizeRedraw = 0x00000010,
  383. FixedWidth = 0x00000020,
  384. FixedHeight = 0x00000040,
  385. StandardClick = 0x00000100,
  386. Selectable = 0x00000200,
  387. UserMouse = 0x00000400,
  388. SupportsTransparentBackColor = 0x00000800,
  389. StandardDoubleClick = 0x00001000,
  390. AllPaintingInWmPaint = 0x00002000,
  391. CacheText = 0x00004000,
  392. EnableNotifyMessage = 0x00008000,
  393. DoubleBuffer = 0x00010000,
  394. OptimizedDoubleBuffer = 0x00020000,
  395. UseTextForAccessibility = 0x00040000,
  396. }
  397. [TypeConverter(typeof(PaddingConverter))]
  398. public struct Padding
  399. {
  400. private int FLeft;
  401. private int FTop;
  402. private int FRight;
  403. private int FBottom;
  404. public int Left { get => FLeft; set => FLeft = value; }
  405. public int Top { get => FTop; set => FTop = value; }
  406. public int Right { get => FRight; set => FRight = value; }
  407. public int Bottom { get => FBottom; set => FBottom = value; }
  408. public static readonly Padding Empty = new Padding(0, 0, 0, 0);
  409. public Padding(int left, int top, int right, int bottom)
  410. {
  411. FLeft = left;
  412. FTop = top;
  413. FRight = right;
  414. FBottom = bottom;
  415. }
  416. public int Horizontal
  417. {
  418. get { return Left + Right; }
  419. }
  420. public int Vertical
  421. {
  422. get { return Top + Bottom; }
  423. }
  424. public static bool operator ==(Padding p1, Padding p2)
  425. {
  426. return p1.Left == p2.Left && p1.Top == p2.Top && p1.Right == p2.Right && p1.Bottom == p2.Bottom;
  427. }
  428. public static bool operator !=(Padding p1, Padding p2)
  429. {
  430. return !(p1 == p2);
  431. }
  432. public override int GetHashCode()
  433. {
  434. int hash = 17;
  435. hash = hash * 31 + Left;
  436. hash = hash * 31 + Top;
  437. hash = hash * 31 + Right;
  438. hash = hash * 31 + Bottom;
  439. return hash;
  440. }
  441. public override bool Equals(object obj)
  442. {
  443. return base.Equals(obj);
  444. }
  445. }
  446. internal class PaddingConverter : TypeConverter
  447. {
  448. public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
  449. {
  450. if (sourceType == typeof(string))
  451. return true;
  452. return base.CanConvertFrom(context, sourceType);
  453. }
  454. public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
  455. {
  456. if (destinationType == typeof(string))
  457. return true;
  458. return base.CanConvertTo(context, destinationType);
  459. }
  460. public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
  461. {
  462. if (value is string)
  463. {
  464. string[] values = (value as string).Split(new char[] { ',' });
  465. int[] val = new int[values.Length];
  466. if (values.Length != 4)
  467. throw new Exception("Padding: need 4 values to parse from string");
  468. for (int i = 0; i < values.Length; i++)
  469. {
  470. val[i] = (int)Converter.FromString(typeof(int), values[i]);
  471. }
  472. return new Padding(val[0], val[1], val[2], val[3]);
  473. }
  474. return base.ConvertFrom(context, culture, value);
  475. }
  476. public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
  477. {
  478. if (destinationType == typeof(string))
  479. {
  480. if (value == null)
  481. return "";
  482. Padding p = (Padding)value;
  483. StringBuilder builder = new StringBuilder();
  484. builder.Append(Converter.ToString(p.Left)).Append(",");
  485. builder.Append(Converter.ToString(p.Top)).Append(",");
  486. builder.Append(Converter.ToString(p.Right)).Append(",");
  487. builder.Append(Converter.ToString(p.Bottom));
  488. return builder.ToString();
  489. }
  490. return base.ConvertTo(context, culture, value, destinationType);
  491. }
  492. }
  493. internal class Converter
  494. {
  495. /// <summary>
  496. /// Converts an object to a string.
  497. /// </summary>
  498. /// <param name="value">The object to convert.</param>
  499. /// <returns>The string that contains the converted value.</returns>
  500. internal static string ToString(object value)
  501. {
  502. return TypeDescriptor.GetConverter(value).ConvertToInvariantString(value);
  503. }
  504. /// <summary>
  505. /// Converts a string value to the specified data type.
  506. /// </summary>
  507. /// <param name="type">The data type to convert to.</param>
  508. /// <param name="value">The string to convert from.</param>
  509. /// <returns>The object of type specified in the <b>type</b> parameter that contains
  510. /// a converted value.</returns>
  511. internal static object FromString(Type type, string value)
  512. {
  513. return TypeDescriptor.GetConverter(type).ConvertFromInvariantString(value);
  514. }
  515. }
  516. #endregion
  517. public class KeyEventArgs : EventArgs
  518. {
  519. public Keys KeyCode
  520. {
  521. get
  522. {
  523. Keys keys = KeyData & Keys.KeyCode;
  524. if (!Enum.IsDefined(typeof(Keys), (int)keys))
  525. {
  526. return Keys.None;
  527. }
  528. return keys;
  529. }
  530. }
  531. public readonly Keys KeyData;
  532. public bool Control => (KeyData & Keys.Control) == Keys.Control;
  533. public KeyEventArgs(Keys keyData)
  534. {
  535. KeyData = keyData;
  536. }
  537. public KeyEventArgs() : this(default)
  538. {
  539. }
  540. }
  541. public class KeyPressEventArgs : EventArgs
  542. {
  543. }
  544. public class MouseEventArgs : EventArgs
  545. {
  546. public readonly int X, Y;
  547. public readonly MouseButtons Button;
  548. public readonly int Clicks;
  549. public readonly int Delta;
  550. public Point Location => new Point(X, Y);
  551. public MouseEventArgs(MouseButtons button, int clicks, int x, int y, int delta) {
  552. Button = button;
  553. X = x;
  554. Y = y;
  555. Clicks = clicks;
  556. Delta = delta;
  557. }
  558. }
  559. public class PaintEventArgs : EventArgs
  560. {
  561. public Graphics Graphics;
  562. }
  563. public class InvalidateEventArgs : EventArgs
  564. {
  565. public Rectangle Rect;
  566. public InvalidateEventArgs(Rectangle r) { Rect = r; }
  567. }
  568. public class DateRangeEventArgs : EventArgs
  569. {
  570. }
  571. public class MeasureItemEventArgs : EventArgs
  572. {
  573. }
  574. public class DrawItemEventArgs : EventArgs
  575. {
  576. }
  577. public class ItemCheckEventArgs : EventArgs
  578. {
  579. public ItemCheckEventArgs()
  580. {
  581. }
  582. public ItemCheckEventArgs(int index, CheckState newCheckValue, CheckState currentValue)
  583. {
  584. Index = index;
  585. NewValue = newCheckValue;
  586. CurrentValue = currentValue;
  587. }
  588. public int Index { get; }
  589. public CheckState NewValue { get; set; }
  590. public CheckState CurrentValue { get; }
  591. }
  592. public class FormClosingEventArgs : CancelEventArgs
  593. {
  594. private readonly CloseReason FCloseReason;
  595. public FormClosingEventArgs(CloseReason closeReason, bool cancel)
  596. : base(cancel)
  597. {
  598. FCloseReason = closeReason;
  599. }
  600. public CloseReason CloseReason
  601. {
  602. get { return FCloseReason; }
  603. }
  604. }
  605. public class FormClosedEventArgs : EventArgs
  606. {
  607. private readonly CloseReason FCloseReason;
  608. public FormClosedEventArgs(CloseReason closeReason)
  609. {
  610. FCloseReason = closeReason;
  611. }
  612. public CloseReason CloseReason
  613. {
  614. get { return FCloseReason; }
  615. }
  616. }
  617. public delegate void FormClosingEventHandler(object sender, FormClosingEventArgs e);
  618. public delegate void FormClosedEventHandler(object sender, FormClosedEventArgs e);
  619. public delegate void KeyEventHandler(object sender, KeyEventArgs e);
  620. public delegate void KeyPressEventHandler(object sender, KeyPressEventArgs e);
  621. public delegate void MouseEventHandler(object sender, MouseEventArgs e);
  622. public delegate void PaintEventHandler(object sender, PaintEventArgs e);
  623. public delegate void MeasureItemEventHandler(object sender, MeasureItemEventArgs e);
  624. public delegate void DrawItemEventHandler(object sender, DrawItemEventArgs e);
  625. public delegate void ItemCheckEventHandler(object sender, ItemCheckEventArgs e);
  626. public delegate void DateRangeEventHandler(object sender, DateRangeEventArgs e);
  627. public sealed class Cursor
  628. {
  629. }
  630. public static class Cursors
  631. {
  632. public static Cursor AppStarting = new Cursor();
  633. public static Cursor PanSW = new Cursor();
  634. public static Cursor PanSouth = new Cursor();
  635. public static Cursor PanSE = new Cursor();
  636. public static Cursor PanNW = new Cursor();
  637. public static Cursor PanNorth = new Cursor();
  638. public static Cursor PanNE = new Cursor();
  639. public static Cursor PanEast = new Cursor();
  640. public static Cursor NoMoveVert = new Cursor();
  641. public static Cursor NoMoveHoriz = new Cursor();
  642. public static Cursor NoMove2D = new Cursor();
  643. public static Cursor VSplit = new Cursor();
  644. public static Cursor HSplit = new Cursor();
  645. public static Cursor Help = new Cursor();
  646. public static Cursor WaitCursor = new Cursor();
  647. public static Cursor UpArrow = new Cursor();
  648. public static Cursor SizeWE = new Cursor();
  649. public static Cursor SizeNWSE = new Cursor();
  650. public static Cursor SizeNS = new Cursor();
  651. public static Cursor SizeNESW = new Cursor();
  652. public static Cursor SizeAll = new Cursor();
  653. public static Cursor No = new Cursor();
  654. public static Cursor IBeam = new Cursor();
  655. public static Cursor Default = new Cursor();
  656. public static Cursor Cross = new Cursor();
  657. public static Cursor Arrow = new Cursor();
  658. public static Cursor PanWest = new Cursor();
  659. public static Cursor Hand = new Cursor();
  660. }
  661. public class Control : Component
  662. {
  663. public Control Parent {
  664. get { return _parent; }
  665. set {
  666. _parent = value;
  667. _parent?.Controls.Add(this);
  668. }
  669. }
  670. public List<Control> Controls { get; } = new List<Control>();
  671. private Control _parent;
  672. public Cursor Cursor;
  673. public bool Enabled = true; //
  674. public Font Font; //
  675. public RightToLeft RightToLeft;
  676. public int TabIndex;
  677. public bool TabStop;
  678. public virtual string Text { get; set; } = ""; //
  679. public DockStyle Dock;
  680. public AnchorStyles Anchor;
  681. public bool Visible = true; //
  682. public int Left; //
  683. public int Top; //
  684. public int Width; //
  685. public int Height; //
  686. public static Keys ModifierKeys;
  687. public Rectangle ClientRectangle { get; }
  688. public Point Location
  689. {
  690. get => new Point(Left, Top);
  691. set
  692. {
  693. Left = Location.X;
  694. Top = Location.Y;
  695. }
  696. }
  697. public Size Size
  698. {
  699. get => new Size(Width, Height);
  700. set
  701. {
  702. Width = value.Width;
  703. Height = value.Height;
  704. }
  705. }
  706. public Padding Padding { get; set; }
  707. /// <summary>
  708. /// Gets the rectangle that represents the display area of the control.
  709. /// </summary>
  710. public virtual Rectangle DisplayRectangle { get; }
  711. public readonly IntPtr Handle = IntPtr.Zero;
  712. public event EventHandler Click; //
  713. public event EventHandler DoubleClick;
  714. public event EventHandler Enter;
  715. public event EventHandler Leave;
  716. public event KeyEventHandler KeyDown;
  717. public event KeyPressEventHandler KeyPress;
  718. public event KeyEventHandler KeyUp;
  719. public event MouseEventHandler MouseDown;
  720. public event MouseEventHandler MouseMove;
  721. public event MouseEventHandler MouseUp;
  722. public event EventHandler MouseEnter;
  723. public event EventHandler MouseLeave;
  724. public event EventHandler Resize;
  725. public event EventHandler TextChanged; //
  726. public event PaintEventHandler Paint;
  727. public event EventHandler LostFocus;
  728. public Control() : base()
  729. {
  730. // Compute our default size.
  731. Size defaultSize = DefaultSize;
  732. Width = defaultSize.Width;
  733. Height = defaultSize.Height;
  734. }
  735. public Control(Control parent, string text) : this()
  736. {
  737. Parent = parent;
  738. Text = text;
  739. }
  740. public void BringToFront() { }
  741. public void Focus() { }
  742. public void Hide() { }
  743. public void Show() { }
  744. public virtual void Refresh() { }
  745. public void Update() { }
  746. public virtual void Invalidate(bool b) { }
  747. public void Invalidate(Rectangle r) { }
  748. public void Invalidate() { }
  749. public void SetStyle(ControlStyles style, bool fl) { }
  750. public Form FindForm() { return null; }
  751. public void PerformLayout() { }
  752. protected void UpdateStyles() { }
  753. protected virtual System.Drawing.Size DefaultSize { get; set; }
  754. public virtual Image BackgroundImage { get; set; }
  755. public virtual Color BackColor { get; set; }
  756. public virtual Color ForeColor { get; set; }
  757. protected virtual void OnPaint(PaintEventArgs e) { }
  758. protected virtual void OnPaintBackground(PaintEventArgs pevent) { }
  759. protected virtual void OnSystemColorsChanged(EventArgs e) { }
  760. protected virtual void OnLocationChanged(EventArgs e) { }
  761. protected virtual void OnRightToLeftChanged(EventArgs e) { }
  762. protected virtual void OnResize(EventArgs e) { }
  763. protected virtual void OnGotFocus(EventArgs e) { }
  764. protected virtual void OnLostFocus(EventArgs e) { }
  765. protected virtual void OnCursorChanged(EventArgs e) { }
  766. protected virtual void OnMouseDown(MouseEventArgs e) { }
  767. protected virtual void OnMouseLeave(EventArgs e) { }
  768. protected virtual void OnMouseUp(MouseEventArgs e) { }
  769. protected virtual void OnMouseMove(MouseEventArgs e) { }
  770. protected virtual void OnDoubleClick(EventArgs e) { }
  771. protected virtual void OnMouseDoubleClick(MouseEventArgs e) { }
  772. protected virtual void OnInvalidated(InvalidateEventArgs e) { }
  773. protected virtual void OnBackColorChanged(EventArgs eventArgs) { }
  774. }
  775. public class GroupBox : Control
  776. {
  777. protected override Size DefaultSize {
  778. get {
  779. return new Size(200, 100);
  780. }
  781. }
  782. }
  783. public class ToolTip : Control
  784. {
  785. public bool Active;
  786. public int AutoPopDelay;
  787. public int InitialDelay;
  788. public int ReshowDelay;
  789. public bool ShowAlways;
  790. public void SetToolTip(Control c, string newToolTipText) { }
  791. public string GetToolTip(Control c) { return ""; }
  792. }
  793. public class ButtonBase : Control
  794. {
  795. public bool AutoSize;
  796. public Image Image;
  797. public ContentAlignment ImageAlign;
  798. public ContentAlignment TextAlign = ContentAlignment.MiddleCenter; //
  799. public TextImageRelation TextImageRelation;
  800. protected override Size DefaultSize {
  801. get {
  802. return new Size(75, 23);
  803. }
  804. }
  805. }
  806. public class PictureBox : Control
  807. {
  808. private Image _image;
  809. private BorderStyle _borderStyle = BorderStyle.None;
  810. private PictureBoxSizeMode _sizeMode = PictureBoxSizeMode.Normal;
  811. public BorderStyle BorderStyle {
  812. get => _borderStyle;
  813. set {
  814. if (_borderStyle != value)
  815. {
  816. _borderStyle = value;
  817. }
  818. }
  819. }
  820. public Image Image {
  821. get => _image;
  822. set => _image = value;
  823. }
  824. public PictureBoxSizeMode SizeMode {
  825. get => _sizeMode;
  826. set {
  827. if (_sizeMode != value)
  828. {
  829. _sizeMode = value;
  830. }
  831. }
  832. }
  833. protected override Size DefaultSize => new Size(100, 50);
  834. }
  835. public class Button : ButtonBase
  836. {
  837. public DialogResult DialogResult = DialogResult.None; //
  838. }
  839. public class CheckBox : ButtonBase
  840. {
  841. public Appearance Appearance;
  842. public ContentAlignment CheckAlign;
  843. public bool Checked = false; //
  844. public CheckState CheckState;
  845. public bool ThreeState;
  846. public object Tag;
  847. public event EventHandler CheckedChanged;
  848. protected override Size DefaultSize {
  849. get {
  850. return new Size(104, 24);
  851. }
  852. }
  853. }
  854. public abstract class ListControl : Control
  855. {
  856. public event EventHandler SelectedIndexChanged; //
  857. public event MeasureItemEventHandler MeasureItem;
  858. public event DrawItemEventHandler DrawItem;
  859. //public bool Sorted;
  860. public DrawMode DrawMode;
  861. public int ItemHeight;
  862. public abstract int SelectedIndex { get; set; }
  863. public string GetItemText(object item)
  864. {
  865. // if we did not do any work then return the old ItemText
  866. return Convert.ToString(item, CultureInfo.CurrentCulture);
  867. }
  868. }
  869. public partial class ListBox : ListControl
  870. {
  871. public bool IntegralHeight;
  872. public int ColumnWidth;
  873. public bool MultiColumn;
  874. public SelectionMode SelectionMode = SelectionMode.One;
  875. public bool UseTabStops;
  876. bool sorted = false;
  877. ObjectCollection itemsCollection;
  878. SelectedIndexCollection selectedIndices;
  879. SelectedObjectCollection selectedItems;
  880. protected override Size DefaultSize {
  881. get {
  882. return new Size(120, 96);
  883. }
  884. }
  885. public bool Sorted
  886. {
  887. get
  888. {
  889. return sorted;
  890. }
  891. set
  892. {
  893. if (sorted != value)
  894. {
  895. sorted = value;
  896. }
  897. }
  898. }
  899. public ObjectCollection Items
  900. {
  901. get
  902. {
  903. if (itemsCollection == null)
  904. {
  905. itemsCollection = new ObjectCollection(this);
  906. }
  907. return itemsCollection;
  908. }
  909. }
  910. public override int SelectedIndex
  911. {
  912. get
  913. {
  914. if (itemsCollection != null && SelectedItems.Count > 0)
  915. {
  916. return Items.IndexOfIdentifier(SelectedItems.GetObjectAt(0));
  917. }
  918. return -1;
  919. }
  920. set
  921. {
  922. int itemCount = (itemsCollection is null) ? 0 : itemsCollection.Count;
  923. if (value < -1 || value >= itemCount)
  924. {
  925. throw new ArgumentOutOfRangeException();
  926. }
  927. if (SelectionMode == SelectionMode.One && value != -1)
  928. {
  929. // Single select an individual value.
  930. int currentIndex = SelectedIndex;
  931. if (currentIndex != value)
  932. {
  933. if (currentIndex != -1)
  934. {
  935. SelectedItems.SetSelected(currentIndex, false);
  936. }
  937. SelectedItems.SetSelected(value, true);
  938. }
  939. }
  940. else if (value == -1)
  941. {
  942. if (SelectedIndex != -1)
  943. {
  944. ClearSelected();
  945. // ClearSelected raises OnSelectedIndexChanged for us
  946. }
  947. }
  948. else
  949. {
  950. if (!SelectedItems.GetSelected(value))
  951. {
  952. SelectedItems.SetSelected(value, true);
  953. }
  954. }
  955. }
  956. }
  957. public object SelectedItem
  958. {
  959. get
  960. {
  961. if (SelectedItems.Count > 0)
  962. {
  963. return SelectedItems[0];
  964. }
  965. return null;
  966. }
  967. set
  968. {
  969. if (itemsCollection != null)
  970. {
  971. if (value != null)
  972. {
  973. int index = itemsCollection.IndexOf(value);
  974. if (index != -1)
  975. {
  976. SelectedIndex = index;
  977. }
  978. }
  979. else
  980. {
  981. SelectedIndex = -1;
  982. }
  983. }
  984. }
  985. }
  986. public SelectedObjectCollection SelectedItems
  987. {
  988. get
  989. {
  990. if (selectedItems is null)
  991. {
  992. selectedItems = new SelectedObjectCollection(this);
  993. }
  994. return selectedItems;
  995. }
  996. }
  997. public SelectedIndexCollection SelectedIndices
  998. {
  999. get
  1000. {
  1001. if (selectedIndices is null)
  1002. {
  1003. selectedIndices = new SelectedIndexCollection(this);
  1004. }
  1005. return selectedIndices;
  1006. }
  1007. }
  1008. public void ClearSelected()
  1009. {
  1010. int itemCount = (itemsCollection is null) ? 0 : itemsCollection.Count;
  1011. for (int x = 0; x < itemCount; x++)
  1012. {
  1013. if (SelectedItems.GetSelected(x))
  1014. {
  1015. SelectedItems.SetSelected(x, false);
  1016. }
  1017. }
  1018. }
  1019. public void SetSelected(int index, bool value)
  1020. {
  1021. SelectedItems.SetSelected(index, value);
  1022. SelectedItems.Dirty();
  1023. }
  1024. }
  1025. public partial class ComboBox : ListControl
  1026. {
  1027. private int selectedIndex = -1;
  1028. private ObjectCollection _itemsCollection;
  1029. public ComboBoxStyle DropDownStyle;
  1030. public int DropDownWidth;
  1031. public int DropDownHeight;
  1032. public int MaxDropDownItems;
  1033. private bool sorted;
  1034. public object Tag;
  1035. protected override Size DefaultSize {
  1036. get {
  1037. return new Size(121,
  1038. 21); // Approximate value, may be incorrect
  1039. }
  1040. }
  1041. public bool Sorted
  1042. {
  1043. get
  1044. {
  1045. return sorted;
  1046. }
  1047. set
  1048. {
  1049. if (sorted != value)
  1050. {
  1051. sorted = value;
  1052. SelectedIndex = -1;
  1053. }
  1054. }
  1055. }
  1056. public ObjectCollection Items
  1057. {
  1058. get
  1059. {
  1060. if (_itemsCollection == null)
  1061. {
  1062. _itemsCollection = new ObjectCollection(this);
  1063. }
  1064. return _itemsCollection;
  1065. }
  1066. }
  1067. public override int SelectedIndex
  1068. {
  1069. get
  1070. {
  1071. return selectedIndex;
  1072. }
  1073. set
  1074. {
  1075. if (SelectedIndex != value)
  1076. {
  1077. selectedIndex = value;
  1078. UpdateText();
  1079. }
  1080. }
  1081. }
  1082. public object SelectedItem
  1083. {
  1084. get
  1085. {
  1086. int index = SelectedIndex;
  1087. return (index == -1) ? null : Items[index];
  1088. }
  1089. set
  1090. {
  1091. int x = -1;
  1092. if (_itemsCollection != null)
  1093. {
  1094. //
  1095. if (value != null)
  1096. {
  1097. x = _itemsCollection.IndexOf(value);
  1098. }
  1099. else
  1100. {
  1101. SelectedIndex = -1;
  1102. }
  1103. }
  1104. if (x != -1)
  1105. {
  1106. SelectedIndex = x;
  1107. }
  1108. }
  1109. }
  1110. private void UpdateText()
  1111. {
  1112. string s = null;
  1113. if (SelectedIndex != -1)
  1114. {
  1115. object item = Items[SelectedIndex];
  1116. if (item != null)
  1117. {
  1118. s = item.ToString();
  1119. }
  1120. }
  1121. Text = s;
  1122. }
  1123. }
  1124. public class CheckedListBox : ListBox
  1125. {
  1126. public class CheckedIndexCollection : List<int> { }
  1127. public class CheckedItemCollection : List<object> { }
  1128. public event ItemCheckEventHandler ItemCheck;
  1129. public bool CheckOnClick;
  1130. public CheckedIndexCollection CheckedIndices = new CheckedIndexCollection(); //
  1131. public CheckedItemCollection CheckedItems { get; } = new CheckedItemCollection();
  1132. //
  1133. public void SetItemChecked(int index, bool check)
  1134. {
  1135. if (check)
  1136. {
  1137. if (!CheckedIndices.Contains(index))
  1138. {
  1139. CheckedIndices.Add(index);
  1140. CheckedItems.Add(Items[index]);
  1141. }
  1142. }
  1143. else
  1144. {
  1145. CheckedIndices.Remove(index);
  1146. CheckedItems.Remove(Items[index]);
  1147. }
  1148. }
  1149. }
  1150. public class Panel : ScrollableControl
  1151. {
  1152. private BorderStyle borderStyle;
  1153. /// <summary>Initializes a new instance of the <see cref="T:System.Windows.Forms.Panel" /> class.</summary>
  1154. public Panel()
  1155. {
  1156. this.TabStop = false;
  1157. }
  1158. public BorderStyle BorderStyle
  1159. {
  1160. get => this.borderStyle;
  1161. set => this.borderStyle = value;
  1162. }
  1163. protected override Size DefaultSize
  1164. {
  1165. get
  1166. {
  1167. return new Size(200,
  1168. 100);
  1169. }
  1170. }
  1171. }
  1172. public class DateTimePicker : Control
  1173. {
  1174. public event EventHandler ValueChanged;
  1175. public bool Checked;
  1176. public string CustomFormat;
  1177. public LeftRightAlignment DropDownAlign;
  1178. public DateTimePickerFormat Format;
  1179. public DateTime MaxDate;
  1180. public DateTime MinDate;
  1181. public bool ShowCheckBox;
  1182. public bool ShowUpDown;
  1183. public DateTime Value = DateTime.Now; //
  1184. protected override Size DefaultSize {
  1185. get {
  1186. return new Size(200,
  1187. 20); // Approximate value, may be incorrect
  1188. }
  1189. }
  1190. }
  1191. public class Label : Control
  1192. {
  1193. public bool AutoSize;
  1194. public ContentAlignment TextAlign = ContentAlignment.TopLeft; //
  1195. protected override Size DefaultSize {
  1196. get {
  1197. return new Size(100,
  1198. 23); // Approximate value, may be incorrect
  1199. }
  1200. }
  1201. }
  1202. public sealed class SelectionRange
  1203. {
  1204. }
  1205. public class MonthCalendar : Control
  1206. {
  1207. public event DateRangeEventHandler DateChanged;
  1208. public Size CalendarDimensions;
  1209. public Day FirstDayOfWeek;
  1210. public DateTime MaxDate;
  1211. public int MaxSelectionCount;
  1212. public DateTime MinDate;
  1213. public bool ShowToday;
  1214. public bool ShowTodayCircle;
  1215. public bool ShowWeekNumbers;
  1216. public DateTime TodayDate;
  1217. public DateTime[] AnnuallyBoldedDates;
  1218. public DateTime[] BoldedDates;
  1219. public DateTime[] MonthlyBoldedDates;
  1220. public DateTime SelectionEnd;
  1221. public SelectionRange SelectionRange;
  1222. public DateTime SelectionStart = DateTime.Now; //
  1223. }
  1224. public class RadioButton : ButtonBase
  1225. {
  1226. private bool isChecked = false;
  1227. public event EventHandler CheckedChanged;
  1228. public ContentAlignment CheckAlign;
  1229. public bool Checked {
  1230. get { return isChecked; }
  1231. set
  1232. {
  1233. if(isChecked != value)
  1234. {
  1235. isChecked = value;
  1236. if (value && Parent != null)
  1237. {
  1238. var controls = this.Parent.Controls;
  1239. foreach (var control in controls)
  1240. {
  1241. if (control is RadioButton && control != this)
  1242. (control as RadioButton).isChecked = false;
  1243. }
  1244. }
  1245. }
  1246. }
  1247. } //
  1248. protected override Size DefaultSize {
  1249. get {
  1250. return new Size(104, 24);
  1251. }
  1252. }
  1253. }
  1254. public class TextBox : Control
  1255. {
  1256. public bool AcceptsReturn;
  1257. public bool AcceptsTab;
  1258. public CharacterCasing CharacterCasing;
  1259. public int MaxLength = 32767;
  1260. public bool Multiline = false; //
  1261. public bool ReadOnly;
  1262. public ScrollBars ScrollBars;
  1263. public HorizontalAlignment TextAlign = HorizontalAlignment.Left; //
  1264. public bool UseSystemPasswordChar;
  1265. public bool WordWrap;
  1266. public BorderStyle BorderStyle;
  1267. public void SelectAll() { }
  1268. protected override Size DefaultSize {
  1269. get {
  1270. return new Size(100,
  1271. 20); // Approximate value, may be incorrect
  1272. }
  1273. }
  1274. }
  1275. public enum AutoScaleMode
  1276. {
  1277. None = 0,
  1278. Font = 1,
  1279. Dpi = 2,
  1280. Inherit = 3
  1281. }
  1282. public class Form : ScrollableControl
  1283. {
  1284. public event EventHandler Load;
  1285. public event FormClosedEventHandler FormClosed;
  1286. public event FormClosingEventHandler FormClosing;
  1287. public event EventHandler Shown;
  1288. public Button AcceptButton;
  1289. public Button CancelButton;
  1290. public FormBorderStyle FormBorderStyle;
  1291. public Size ClientSize;
  1292. public FormStartPosition StartPosition;
  1293. public bool ShowIcon;
  1294. public bool ShowInTaskbar;
  1295. public bool MinimizeBox;
  1296. public bool MaximizeBox;
  1297. public DialogResult DialogResult;
  1298. public SizeF AutoScaleDimensions;
  1299. public AutoScaleMode AutoScaleMode;
  1300. public DialogResult ShowDialog()
  1301. {
  1302. return DialogResult.OK;
  1303. }
  1304. protected override Size DefaultSize {
  1305. get {
  1306. return new Size(300, 300);
  1307. }
  1308. }
  1309. public void SuspendLayout()
  1310. {
  1311. }
  1312. public void ResumeLayout()
  1313. {
  1314. }
  1315. public int Dpi()
  1316. {
  1317. return 96;
  1318. }
  1319. public float FontDpiMultiplier()
  1320. {
  1321. return 1f;
  1322. }
  1323. }
  1324. public class BaseForm : Form
  1325. {
  1326. public event EventHandler DpiChanged;
  1327. public virtual void UpdateDpiDependencies()
  1328. {
  1329. }
  1330. }
  1331. public class Timer : Component
  1332. {
  1333. public event EventHandler Tick;
  1334. public int Interval;
  1335. public bool Enabled;
  1336. public void Start() { if (Tick != null) Tick(this, EventArgs.Empty); }
  1337. public void Stop() { }
  1338. }
  1339. public sealed class MessageBox
  1340. {
  1341. public static DialogResult Show(string text)
  1342. {
  1343. return DialogResult.None;
  1344. }
  1345. }
  1346. public sealed class Application
  1347. {
  1348. public static void DoEvents()
  1349. {
  1350. }
  1351. }
  1352. public class SystemInformation
  1353. {
  1354. public static bool HighContrast;
  1355. }
  1356. public sealed class ControlPaint
  1357. {
  1358. public static void DrawFocusRectangle(Graphics g, Rectangle r) { }
  1359. }
  1360. public class ScrollableControl : Control
  1361. {
  1362. public Control ActiveControl;
  1363. }
  1364. }
  1365. #pragma warning restore FR0000 // Field must be texted in lowerCamelCase.
  1366. #pragma warning restore 1591