Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic .NET (http://www.programmingforums.org/forum19.html)
-   -   Accesing Control Properties on Another Form (http://www.programmingforums.org/showthread.php?t=14358)

Rythn Nov 7th, 2007 10:18 AM

Accesing Control Properties on Another Form
 
I'm trying to enable a button on the main form, once the child form is closing. I'm using a MDI here, and I noticed that if I do this by a button click on the child form it works. But it aint happening if i use the FormClosing or FormClosed events.

Please Help

Private Sub frmSuppliers_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
Dim frmMain As New frmMain
frmMain.tsbSuppliers.Enabled = True
End Sub

Alias Nov 7th, 2007 10:41 AM

Re: Accesing Control Properties on Another Form
 
Does an instance of the main form not already exist? is that not where the child forms are hosted?

Creating a new instance of the main form and setting the enabled state of the button of that instance will not have an effect on the form already shown.

Try looking into the forms 'Parent' property and take it from there.

lectricpharaoh Nov 7th, 2007 11:51 AM

Re: Accesing Control Properties on Another Form
 
your best bet here is probably to create a public property on the child form that is set according to user input into the child form. Then, after you close the child form, you can check this property from the main form.

Alias Nov 7th, 2007 2:44 PM

Re: Accesing Control Properties on Another Form
 
How would it be best to declare, reference and use new variables for this task when it could be done with a simple cast?

Imagine...

:

  1. ((Button)Parent.Controls["ButtonName"]).Enabled = value


lectricpharaoh Nov 7th, 2007 9:54 PM

Re: Accesing Control Properties on Another Form
 
Quote:

Originally Posted by Alias
How would it be best to declare, reference and use new variables for this task when it could be done with a simple cast?

I was suggesting that for encapsulation. Having the child form muck with the parent form's controls abrogates the parent form's responsibility to take care of its own controls. Having a mechanism (property or otherwise) as part of the child form's interface that allows the parent form to determine its state and act appropriately seems a better solution to me.

SydneyMcConnell Jan 9th, 2008 12:50 PM

Re: Accesing Control Properties on Another Form
 
Should be something along the lines of:

:

Me.Parent.Controls("tsbSuppliers").enabled = false

Give that a try.
If it doesn't work there, try it in the child form's Disposing event.


All times are GMT -5. The time now is 9:12 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC