By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,556 Members | 1,669 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,556 IT Pros & Developers. It's quick & easy.

Form1.Enable = True, but cannot set it back?

P: n/a
Hi,

I have 2 forms "Form1" & "Form2"
In Form1, there is a button to click to open Form2 and set Form1.Enabled =
False

However, when i finish using Form2, i cannot Enable Form1?

In Form2, i did something like:

Dim f As new Form1
f.enabled = True
Me.close( )

So it should Enable Form1 and close itself, but it just doesn't.
What am i doing wrong here?

please help, thanks

Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
> Dim f As new Form1
f.enabled = True
Me.close( )
You are creating a new (second) instance of Form1 (that has never been
shown). You need to set the enabled property on a reference to the Form1
instance that was previously disabled...

Not sure what you are attempting with the enabled property. Would
f.ShowModal better serve your goal?

Greg
"Jonathan" <Jo******@discussions.microsoft.com> wrote in message
news:4F**********************************@microsof t.com... Hi,

I have 2 forms "Form1" & "Form2"
In Form1, there is a button to click to open Form2 and set Form1.Enabled =
False

However, when i finish using Form2, i cannot Enable Form1?

In Form2, i did something like:

Dim f As new Form1
f.enabled = True
Me.close( )

So it should Enable Form1 and close itself, but it just doesn't.
What am i doing wrong here?

please help, thanks

Nov 21 '05 #2

P: n/a
> Not sure what you are attempting with the enabled property. Would
f.ShowModal better serve your goal?


I believe you meant f.ShowDialog :)

But yes - you're right - it seems f.ShowDialog would be the way to go for
the OP.
Imran.

Nov 21 '05 #3

P: n/a
Hi,
Both of my form is within a Parent Form, so i don't think i can use
ShowDialog.
but Anyway, the reason I want to use Enable is that my Form2 is smaller than
Form1, and when Form2 comes up, i want to disable everything on Form1 hence i
set the Form1.Enabled = False.

But the problem was once i finished with Form2, I cannot set Form1.Enabled =
True, because I cannot access the control of Form1 in Form2.

therefore i was playing around with
Dim f As new Form1
f.enabled = True
Me.close( )

but as you said its a wrong method of doing it.
So is it possible that you can give me an example of doing it correctly?
please

Many thanks for your help
Jon
"Imran Koradia" wrote:
Not sure what you are attempting with the enabled property. Would
f.ShowModal better serve your goal?


I believe you meant f.ShowDialog :)

But yes - you're right - it seems f.ShowDialog would be the way to go for
the OP.
Imran.

Nov 21 '05 #4

P: n/a
Ok - since you want to do that anyway, there are several ways. Here's one:
Change the constructor (or you could event overload it - whichever way you
prefer) of Form2 to take in an argument which will be a reference to Form1
from which you are calling form2. Use that reference to enable/disable your
form.

Private m_frm As Form1

Public Sub New(ByVal frm As Form1)
MyBase.New()
m_frm = frm
End Sub

So, now your call to Form2 from Form1 would be:

Dim frm2 As New Form2(Me)
Me.Enabled = False
frm2.Show( )

And within your Form2, before you close down the form (or better - in the
Form2_Closing event), call:
m_frm.Enabled = True

I still think this isn't a very good idea. As Greg already mentioned, you
should look into showing up the second form as a modal form over the first
one since that is a more 'standard' design.

anyway, hope that helps..
Imran.

"Jonathan" <Jo******@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
Hi,
Both of my form is within a Parent Form, so i don't think i can use
ShowDialog.
but Anyway, the reason I want to use Enable is that my Form2 is smaller
than
Form1, and when Form2 comes up, i want to disable everything on Form1
hence i
set the Form1.Enabled = False.

But the problem was once i finished with Form2, I cannot set Form1.Enabled
=
True, because I cannot access the control of Form1 in Form2.

therefore i was playing around with
Dim f As new Form1
f.enabled = True
Me.close( )

but as you said its a wrong method of doing it.
So is it possible that you can give me an example of doing it correctly?
please

Many thanks for your help
Jon
"Imran Koradia" wrote:
> Not sure what you are attempting with the enabled property. Would
> f.ShowModal better serve your goal?


I believe you meant f.ShowDialog :)

But yes - you're right - it seems f.ShowDialog would be the way to go for
the OP.
Imran.

Nov 21 '05 #5

P: n/a
> I still think this isn't a very good idea. As Greg already mentioned, you
should look into showing up the second form as a modal form over the first
one since that is a more 'standard' design.


Thankyou very much for helping me.

I am still quite new to programming, so I do not know which is the best way
to do it. You mentioned about showing the form as a model?

Do you mind if you can tell me more about it? the proper way of doing it?
Sorry to bother you so much, but i would like to know more.
many many thanks.
Jon

Nov 21 '05 #6

P: n/a
On Thu, 30 Sep 2004 21:03:03 -0700, Jonathan wrote:
I still think this isn't a very good idea. As Greg already mentioned, you
should look into showing up the second form as a modal form over the first
one since that is a more 'standard' design.


Thankyou very much for helping me.

I am still quite new to programming, so I do not know which is the best way
to do it. You mentioned about showing the form as a model?

Do you mind if you can tell me more about it? the proper way of doing it?
Sorry to bother you so much, but i would like to know more.
many many thanks.
Jon


To show a form modally, just call the ShowDialog method instead of Show:

'In Form1:

Dim f As New Form2
f.ShowDialog(Me)
'Now Form1 is effectively 'disabled' until Form2 closes, no need to change
it's enabled property.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.