Component Question

runswithsizzors

Well-known member
Joined
May 11, 2005
Messages
70
Location
Northern Michigan
Programming Experience
5-10
Hello all this was a neat forum and I had to join.

For my first question here I go:

I have a main form that opens other forms. I have a list of check boxes and the ones that are check when a button is pressed that opens all the forms(second forms) that match the check boxes.

When I do that I gray out the check boxes on the main form because i don't want the user to keep opening up the same form (second Form).

When I close the other forms (Second Forms). I want to enable the check boxes on the main form and uncheck the check box.

Now on my second form do I create and instance of the main form,
Dim mainform = new main

mainform.checkbox1.Enable = True
mainform.checkbox1.CheckState = CheckState.Unchecked

I do this in the closed event of the second form.

Well that doesn't get me any where :confused: , I think I am on the right path but it just isn't working. Any suggestions? Anything would be great, Thanks!
 

kulrom

Well-known member
Joined
May 10, 2005
Messages
2,854
Location
Republic of Macedonia
Programming Experience
10+
Hi,
Wellcome to the forum ;)

about your Q; You should declare Public boolean variables and check 'em on load events

i.e.
Add new module and declare new vars:
Public enabledChk As boolean = False
Public checkedChk As boolean = False

the part with closed event is good approach but wrong code:

VB.NET:
enabledChk = true 'or false .. depends on that you want to happens when your main form load
checkedChk = true 'also here

then put load event

VB.NET:
If checkedChk = False then
checkedChk = true
checkbox1.Enable = True
checkbox1.C[size=2]heckState = CheckState.Unchecked[/size]
End If

Cheers :)

Please do let me know if something isn't working as it should, i will make a demo for you ...
 
Last edited:

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,335
Location
Sydney, Australia
Programming Experience
10+
I am going to assume that each CheckBox on your main Form refers to a different type of Form and that you only want one of each type to be open at any one time. Also, I am going to assume that your main Form will remain open while these other Forms are displayed. If these assumptions are correct, I would suggest the following:

In your main Form, declare your child Form as a variable with events:
VB.NET:
[color=Blue]Private WithEvents[/color] childForm [color=Blue]As[/color] ChildForm

In the Click event handler for your button, disable and uncheck the CheckBox that corresponds to the child Form, then open the child Form:
VB.NET:
[color=Blue]Private Sub[/color] openFormsButton_Click(...) [color=Blue]Handles[/color] openFormsButton.Click
	[color=Blue]If Me[/color].childFormCheck.Checked [color=Blue]Then[/color]
		[color=Blue]Me[/color].childFormCheck.Enabled = [color=Blue]False[/color]
		[color=Blue]Me[/color].childFormCheck.Checked = [color=Blue]False[/color]

		[color=Blue]Me[/color].childForm = [color=Blue]New[/color] ChildForm
		[color=Blue]Me[/color].childForm.Show()
	[color=Blue]End If[/color]
[color=Blue] End Sub[/color]

In your main Form, declare a Closed event handler for the child Form and in it re-enable the CheckBox that corresponds to the child Form:
VB.NET:
[color=Blue]Private Sub[/color] childForm_Closed([color=Blue]ByVal[/color] sender [color=Blue]As Object[/color], [color=Blue]ByVal[/color] e [color=Blue]As[/color] System.EventArgs) [color=Blue]Handles[/color] childForm.Closed
	[color=Blue]Me[/color].childFormCheck.Enabled = [color=Blue]True[/color]
[color=Blue] End Sub[/color]
 
Top Bottom