Setting the DialogResult in the Load event

T

Tibor Meinczinger

Hi,

i have severeal modal dialogs and i am using the load
event for filling the widgets on the dialogs with some
data.
There are cases, when there is no data, so I would like to
show up a message and hide the dialog immediately.
I have tried to set the DialogResult (Besides the Load
event, I am using it everywhere, and it works), but it
doesn't work.
So my question is:
How can I hide a dialog in the Load event?
Thanks,
Tibor
 
M

MichaelLipp[MS]

I've entered a bug for this. I don't think I would use this method even if
it worked on the compact framework because it will likely cause the dialog
to flash, then go away. I think I would call a method to on the dialog (or
figure out before trying to show the dialog) if the dialog was needed.
Something like:
Dialog x = new Dialog();
if(x.HasDataToShow())
x.ShowDialog();

An easy work around in line with what you're doing now would be to just
call Close() from OnLoad

using System;
using System.Drawing;
using System.Windows.Forms;

public class Form1 : System.Windows.Forms.Form
{
Button b;
public Form1()
{
this.Text = "test";

b = new Button();
b.Text = "show dialog";
b.Click += new EventHandler(this._Click);
b.Bounds = new Rectangle(10, 50, 200, 30);
b.Parent = this;
}

void _Click(object o, EventArgs e)
{
Dialog x = new Dialog();
x.ShowDialog();
}

static void Main()
{
Application.Run(new Form1());
}
}

public class Dialog : Form
{
protected override void OnLoad(EventArgs e)
{
// there is no data to show
MessageBox.Show("no data");
this.Close();
}
}









NETCF Beta FAQ's -- http://www.gotdotnet.com/team/netcf/FAQ.aspx
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top