> > Hi
> >
[quoted text clipped - 26 lines]
> hth,
> Max
Well, I am using DoEvents, as I mentioned in the other thread, but even
without that it could still be called twice. Picture this: I have a
form, with two buttons. In my form constructor, or somewhere, I create
an instance of my object. Each button calls myObject.DoSomething(),
which, say, displays another form using form.Show(). When this other
form is closed, it raises an event or calls a delegate. Now the user
clicks on button 1, but doesn't close the form yet; then clicks on
button 2. My DoSomething() method will then be called again.
Basically, my problem is that I have an app with potentially many
forms; one of them will trigger the opening of a 2nd form. I want the
user to still be able to use the other forms, so I can't open this 2nd
form using ShowDialog, since it will be modal with respect to the
entire app. If I could make it modal only with respect to its parent
form, that would solve all my problems.
Lloyd Dupont - 31 Jul 2006 06:21 GMT
> Well, I am using DoEvents, as I mentioned in the other thread, but even
> without that it could still be called twice. Picture this: I have a
[quoted text clipped - 11 lines]
> entire app. If I could make it modal only with respect to its parent
> form, that would solve all my problems.
Apart from the fact you are confused I hardly see any problem in what you
tryed to achieve.
Not being sure of what is your problem exactly I wrote a a possible (and
possibly irrelevant) solution below.
class AnObject : Object
{
bool done = false;
public void DoSomethingOnce()
{
if(done)
return;
DoItDamnIt();
done = false;
}
void DoItDamnIt()
{
// whatever it is you want to do
}
}
class MyForm : Form
{
AnObject anObj;
Button perhaps, maybe;
public MyForm(AbObject anObj)
{
this.anObj = anObj;
perhaps = new Button();
perhaps.Location = new Point(10, 10);
perhaps.Parent = this;
perhaps.Text = "Perhaps";
perhaps.Click += delegate(object sender, EventArgs e) { new
MyForm(anObj).Show(); };
maybe = new Button();
maybe.Location = new Point(80, 10);
maybe.Parent = this;
maybe.Text = "Maybe";
maybe.Click += delegate(object sender, EventArgs e) {
anObj.DoSomethingOnce(); };
}
}