CommonDialog.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2004-2006 Novell, Inc. (http://www.novell.com)
  21. //
  22. // Authors:
  23. // Peter Bartok (pbartok@novell.com)
  24. //
  25. //
  26. // NOT COMPLETE
  27. // changed (simplified) by Alexander Tsyganenko
  28. using System.ComponentModel;
  29. using System.Drawing;
  30. namespace System.Windows.Forms
  31. {
  32. public abstract class CommonDialog : Component
  33. {
  34. #region DialogForm
  35. internal class DialogForm : Form
  36. {
  37. #region DialogForm Local Variables
  38. protected CommonDialog owner;
  39. #endregion DialogForm Local Variables
  40. #region DialogForm Constructors
  41. internal DialogForm(CommonDialog owner)
  42. {
  43. this.owner = owner;
  44. AutoScaleDimensions = new SizeF(96f, 96f);
  45. AutoScaleMode = AutoScaleMode.Dpi;
  46. MinimizeBox = false;
  47. MaximizeBox = false;
  48. ShowInTaskbar = false;
  49. FormBorderStyle = FormBorderStyle.Sizable;
  50. StartPosition = FormStartPosition.CenterScreen;
  51. Font = new Font("Segoe UI", 8.5f);
  52. }
  53. #endregion DialogForm Constructors
  54. #region Internal Methods
  55. internal DialogResult RunDialog()
  56. {
  57. owner.InitFormsSize(this);
  58. this.ShowDialog();
  59. return this.DialogResult;
  60. }
  61. #endregion Internal Methods
  62. }
  63. #endregion DialogForm
  64. #region Local Variables
  65. internal DialogForm form;
  66. private object tag;
  67. #endregion Local Variables
  68. #region Public Constructors
  69. public CommonDialog()
  70. {
  71. }
  72. #endregion Public Constructors
  73. #region Public Properties
  74. public object Tag
  75. {
  76. get { return this.tag; }
  77. set { this.tag = value; }
  78. }
  79. #endregion
  80. #region Internal Methods
  81. internal virtual void InitFormsSize(Form form)
  82. {
  83. // Override this to set a default size for the form
  84. form.Width = 200;
  85. form.Height = 200;
  86. }
  87. #endregion Internal Methods
  88. #region Public Instance Methods
  89. public abstract void Reset();
  90. public DialogResult ShowDialog()
  91. {
  92. return ShowDialog(null);
  93. }
  94. public DialogResult ShowDialog(object owner)
  95. {
  96. // This is an external derived CommonDialog
  97. if (form == null)
  98. {
  99. if (RunDialog())
  100. return DialogResult.OK;
  101. return DialogResult.Cancel;
  102. }
  103. // This is an internal derived CommonDialog
  104. if (RunDialog())
  105. form.ShowDialog();
  106. return form.DialogResult;
  107. }
  108. #endregion // Public Instance Methods
  109. #region Protected Instance Methods
  110. protected abstract bool RunDialog();
  111. #endregion // Protected Instance Methods
  112. }
  113. internal static class Locale
  114. {
  115. internal static string GetText(string text) => text;
  116. }
  117. }