Subversion Repositories DevTools

Rev

Rev 2153 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2153 Rev 2155
Line 1... Line 1...
1
using System;
1
using System;
2
using System.Drawing;
-
 
3
using System.Collections;
-
 
4
using System.ComponentModel;
-
 
5
using System.Windows.Forms;
2
using System.Windows.Forms;
6
 
3
 
7
namespace EA_ReqPro
4
namespace EA_ReqPro
8
{
5
{
9
	/// <summary>
6
	/// <summary>
10
	/// A simple alternative MessageBox class. This allows us to set TopMost=true for the
7
	/// A wrapper for MessageBox class, that ensures the TopMost flag is set.
-
 
8
	/// WARNING - this uses an undocumented feature. It might stop working correctly in future
-
 
9
	/// versions of the .NET framework. We need the topmost flag to be set because the reqpro
11
	/// message box.
10
	/// import/export works as a thread and any message boxes it throws up can get lost behind
-
 
11
	/// EA and other windows if the user is not paying attention to what is going on, or perhaps
-
 
12
	/// is using some other program while the EA window is minimized during a reqpro import/export.
12
	/// </summary>
13
	/// </summary>
13
	public class MessageBoxEx : System.Windows.Forms.Form
-
 
14
	{
-
 
15
      private System.Windows.Forms.Label label1;
-
 
16
      
-
 
17
		/// <summary>
-
 
18
		/// Required designer variable.
-
 
19
		/// </summary>
-
 
20
		private System.ComponentModel.Container components = null;
-
 
21
 
-
 
22
		public MessageBoxEx(string msg, MessageBoxButtons msgBoxButtons)
-
 
23
		{
-
 
24
			//
-
 
25
			// Required for Windows Form Designer support
-
 
26
			//
-
 
27
			InitializeComponent();
-
 
28
 
-
 
29
         // this is why we need this class - to be able to force the message box to be the
-
 
30
         // top most window so a user of EA is forced to deal with the message that arises
-
 
31
         // out of a background thread managing the ReqPro import.
-
 
32
         this.TopMost = true;
-
 
33
 
-
 
34
         // assign a minimum width for the message box based on how many buttons it needs
-
 
35
         int minWidth = 160;
-
 
36
         int maxWidth = 800;
-
 
37
         if (msgBoxButtons == MessageBoxButtons.YesNo)
-
 
38
         {
-
 
39
            minWidth = 280;
-
 
40
         }
-
 
41
 
-
 
42
         this.SuspendLayout();
-
 
43
 
-
 
44
         label1.Text = msg;
-
 
45
 
-
 
46
         Size sz = MeasureString(msg, maxWidth, label1.Font);
-
 
47
 
-
 
48
         // adjust label dimensions
-
 
49
         if (label1.Width > maxWidth)
-
 
50
            label1.Width = maxWidth;
-
 
51
         if (label1.Width < sz.Width)
-
 
52
            label1.Width = sz.Width;
-
 
53
 
-
 
54
         label1.Height = sz.Height + 50;
-
 
55
 
-
 
56
         // adjust client dimensions
-
 
57
         this.Width = sz.Width + 50;
-
 
58
         if (this.Width < minWidth)
-
 
59
            this.Width = minWidth;
-
 
60
         this.Height = sz.Height + 150;
-
 
61
 
-
 
62
         // adjust label position
-
 
63
         label1.Left = (this.Width - sz.Width)/2;
-
 
64
      
-
 
65
         // create buttons
-
 
66
         if (msgBoxButtons == MessageBoxButtons.OK)
-
 
67
         {
-
 
68
            Button button1 = new Button();
-
 
69
            button1.DialogResult = DialogResult.OK;
-
 
70
            button1.Size = new System.Drawing.Size(80, 24);
-
 
71
            button1.Name = "button1";
-
 
72
            button1.TabIndex = 0;
-
 
73
            button1.Text = "OK";
-
 
74
            button1.Visible = true;
-
 
75
            button1.Location = new System.Drawing.Point((this.Width - button1.Width)/2, label1.Top + sz.Height + 50);
-
 
76
            this.Controls.Add(button1);
-
 
77
         }
-
 
78
         else if (msgBoxButtons == MessageBoxButtons.YesNo)
-
 
79
         {
-
 
80
            Button button1 = new Button();
-
 
81
            button1.DialogResult = DialogResult.Yes;
-
 
82
            button1.Size = new System.Drawing.Size(80, 24);
-
 
83
            button1.Name = "button1";
-
 
84
            button1.TabIndex = 0;
-
 
85
            button1.Text = "Yes";
-
 
86
            button1.Location = new Point((this.Width - (button1.Width * 2))/3, label1.Top + sz.Height + 50);
-
 
87
            this.Controls.Add(button1);
-
 
88
 
-
 
89
            Button button2 = new Button();
-
 
90
            button2.DialogResult = DialogResult.No;
-
 
91
            button2.Size = new System.Drawing.Size(80, 24);
-
 
92
            button2.Name = "button2";
-
 
93
            button2.TabIndex = 1;
-
 
94
            button2.Text = "No";
-
 
95
            button2.Location = new Point(button1.Left + button1.Width + ((this.Width - (button2.Width * 2))/3), label1.Top + sz.Height + 50);
-
 
96
            this.Controls.Add(button2);
-
 
97
         }
-
 
98
 
14
 
99
         this.ResumeLayout(false);
15
   public class MessageBoxEx
100
		}
16
   {
-
 
17
      private static int topMost = 0x40000;  // .NET v1.1 does not expose this in its MessageBoxOptions enumeration
101
 
18
 
102
      public static DialogResult Show(string msg)
19
      public static DialogResult Show(string msg)
103
      {
20
      {
104
         MessageBoxEx msgBox = new MessageBoxEx(msg, MessageBoxButtons.OK);
21
         return MessageBox.Show(msg, "", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, (MessageBoxOptions)topMost);
105
         msgBox.Text = "";
-
 
106
         return msgBox.ShowDialog();
-
 
107
      }
-
 
108
 
-
 
109
      public static DialogResult Show(string msg, MessageBoxButtons msgBoxButtons)
-
 
110
      {
-
 
111
         MessageBoxEx msgBox = new MessageBoxEx(msg, msgBoxButtons);
-
 
112
         msgBox.Text = "";
-
 
113
         return msgBox.ShowDialog();
-
 
114
      }
-
 
115
 
-
 
116
      public static DialogResult Show(string msg, string caption, MessageBoxButtons msgBoxButtons)
-
 
117
      {
-
 
118
         MessageBoxEx msgBox = new MessageBoxEx(msg, msgBoxButtons);
-
 
119
         msgBox.Text = caption;
-
 
120
         return msgBox.ShowDialog();
-
 
121
      }
22
      }
122
 
23
 
123
      public static DialogResult Show(string msg, string caption)
24
      public static DialogResult Show(string msg, string caption)
124
      {
25
      {
125
         MessageBoxEx msgBox = new MessageBoxEx(msg, MessageBoxButtons.OK);
26
         return MessageBox.Show(msg, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, (MessageBoxOptions)topMost);
126
         msgBox.Text = caption;
-
 
127
         return msgBox.ShowDialog();
-
 
128
      }
27
      }
129
 
28
 
130
		/// <summary>
-
 
131
		/// Clean up any resources being used.
-
 
132
		/// </summary>
-
 
133
		protected override void Dispose( bool disposing )
-
 
134
		{
-
 
135
			if( disposing )
-
 
136
			{
-
 
137
				if(components != null)
-
 
138
				{
-
 
139
					components.Dispose();
-
 
140
				}
-
 
141
			}
-
 
142
			base.Dispose( disposing );
-
 
143
		}
-
 
144
 
-
 
145
		#region Windows Form Designer generated code
-
 
146
		/// <summary>
-
 
147
		/// Required method for Designer support - do not modify
-
 
148
		/// the contents of this method with the code editor.
-
 
149
		/// </summary>
-
 
150
		private void InitializeComponent()
-
 
151
		{
-
 
152
         this.label1 = new System.Windows.Forms.Label();
-
 
153
         this.SuspendLayout();
-
 
154
         // 
-
 
155
         // label1
-
 
156
         // 
-
 
157
         this.label1.Location = new System.Drawing.Point(8, 24);
-
 
158
         this.label1.Name = "label1";
-
 
159
         this.label1.Size = new System.Drawing.Size(280, 32);
-
 
160
         this.label1.TabIndex = 1;
-
 
161
         this.label1.Text = "label1";
-
 
162
         // 
-
 
163
         // MessageBoxEx
-
 
164
         // 
-
 
165
         this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
-
 
166
         this.ClientSize = new System.Drawing.Size(292, 168);
-
 
167
         this.Controls.Add(this.label1);
-
 
168
         this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
-
 
169
         this.MaximizeBox = false;
-
 
170
         this.MinimizeBox = false;
-
 
171
         this.Name = "MessageBoxEx";
-
 
172
         this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
-
 
173
         this.Text = "caption";
-
 
174
         this.TopMost = true;
-
 
175
         this.ResumeLayout(false);
-
 
176
 
-
 
177
      }
-
 
178
		#endregion
-
 
179
 
-
 
180
 
-
 
181
      /// <summary>
-
 
182
      /// Measures a string using the Graphics object for this form with
-
 
183
      /// the specified font
-
 
184
      /// </summary>
-
 
185
      /// <param name="str">The string to measure</param>
-
 
186
      /// <param name="maxWidth">The maximum width available to display the string</param>
-
 
187
      /// <param name="font">The font with which to measure the string</param>
-
 
188
      /// <returns></returns>
-
 
189
      private Size MeasureString(string str, int maxWidth, Font font)
29
      public static DialogResult Show(string msg, string caption, MessageBoxButtons buttons)
190
      {
30
      {
191
         Graphics g = this.CreateGraphics();
-
 
192
         SizeF strRectSizeF = g.MeasureString(str, font, maxWidth);
-
 
193
         g.Dispose();
-
 
194
 
-
 
195
         return new Size((int)Math.Ceiling(strRectSizeF.Width), (int)Math.Ceiling(strRectSizeF.Height));
31
         return MessageBox.Show(msg, caption, buttons, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, (MessageBoxOptions)topMost);
196
      }
32
      }
197
 
33
 
198
 
-
 
199
      /// <summary>
-
 
200
      /// Measures a string using the Graphics object for this form and the
-
 
201
      /// font of this form
-
 
202
      /// </summary>
-
 
203
      /// <param name="str"></param>
-
 
204
      /// <param name="maxWidth"></param>
-
 
205
      /// <returns></returns>
-
 
206
      private Size MeasureString(string str, int maxWidth)
34
      public static DialogResult Show(string msg, string caption, MessageBoxIcon icon)
207
      {
35
      {
208
         return MeasureString(str, maxWidth, this.Font);
36
         return MessageBox.Show(msg, caption, MessageBoxButtons.OK, icon, MessageBoxDefaultButton.Button1, (MessageBoxOptions)topMost);
209
      }
37
      }
210
 
38
 
211
 
39
 
212
	}
40
   }
213
}
41
}