Hello,

On Wed, 2007-09-19 at 12:36 -0500, [EMAIL PROTECTED] wrote:
> Thank you for your respond.  You are right that I am using
> "Form.ShowDialog".  However, I am using it in both Windows, and Linux.
> The reason I am using "Form.ShowDialog" is because I want to monitor for
> the return of the form.
> 
> Is there a problem with "Form.ShowDialog"?

No there is no problem with ShowDialog but it blocks all other Forms of
the Application, like you already noticed.

Howerver, a workaround would be to attach a delegate to the Closed event
of the Form and then read out the DialogResult manually. (See the
Attachment for a short sample)

Kind Regards,
Valentin S.

> 
> Thanks.
> 
> -Tri.
> 
> -----Original Message-----
> From: Valentin Sawadski [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, September 19, 2007 10:34 AM
> To: Nguyen, Tri
> Cc: [email protected]
> Subject: Re: [MonoDevelop] Moving Focus Between Form
> 
> Hello,
> 
> On Fri, 2007-09-14 at 12:41 -0500, [EMAIL PROTECTED] wrote:
> > Hi I am new to Mono, and I not sure this is a right place to ask this
> > question:
> > 
> > 1.       I am trying to port a C# Windows app to Mono running on SLES
> > 10.1.  The app starts with one form, and base on user input , it can
> > launch other forms.  When this happens, the new form gets focus, and I
> > can click on the previous form (parent?), and get focus.  On mono, the
> > app behaves differently:  I cannot get focus back to the previous,
> > unless I close the new form.
> > 
> > Any help on this matter would be appreciated.
> 
> As far as I know there's no bug in Form.Show, so my guess is that you
> call Form.Show on Windows and changed it to Form.ShowDialog while
> porting to Linux which would explain the behavior you mentioned.
> 
> However I you are sure that this is not the cause for the behavior, then
> please file a bug with a repro at http://bugzilla.novell.com.
> 
> Kind Regards,
> Valentin S.
> 
> P.S. I cc'ed this message to the winforms list, so that more people
> concerned with WinForm will notice to this issue.
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace FormsTest {
	
	public class MainClass {
		
		public static void Main() {
			Application.Run(new MainForm());
		}
	}
	
	class MainForm : Form {

		Button bDialog = new Button();
		Button b = new Button();
	
		protected override void OnLoad (EventArgs e) {
			b.AutoSize = bDialog.AutoSize = true;
			bDialog.Text = "Show Dialog";
			b.Text = "Show";
			b.Left = bDialog.Right + 10;
			
			b.Click += delegate {
				ChildForm f = new ChildForm();
				f.Closed += delegate {
					MessageBox.Show("Called Show and returned DialogResult " + f.DialogResult.ToString());
					f.Dispose();
				};
				f.Show();
				MessageBox.Show("Please note that excecution of this method does not stop when Show has been called.");
			};
			bDialog.Click += delegate {
				using(ChildForm f = new ChildForm()) {
					DialogResult res = f.ShowDialog();
					MessageBox.Show("Called ShowDialog and returned DialogResult " + res);
				}
			};
			
			Controls.Add(b);
			Controls.Add(bDialog);
		}
	}
	
	class ChildForm : Form {
	
		protected override void OnClosing (CancelEventArgs e) {
			// Setting to a random dialog result.
			Random r = new Random();
			int elements = Enum.GetValues(typeof(DialogResult)).Length;
			DialogResult = (DialogResult) Enum.Parse(typeof(DialogResult), Enum.GetNames(typeof(DialogResult))[r.Next(elements)]);
		}
	}
}
_______________________________________________
Mono-winforms-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-winforms-list

Reply via email to