473,394 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Controlling Controls on another Form

This is rediculous that I can't figure this out. I'm really getting frustrated with VB .NET. Everything seemed so much easier in VB5 and VB6. I'm really getting to feel conciseness about the number of questions I need to ask. If it weren't for a couple of you I would have accomplished almost nothing. Oh well, I guess I help your MVP status

Anyways, sorry for that. Here is my problem. I have form1 and form2. Form1 has 25 labels and form2 has 25 checkboxes. the labels on form1 all have their visible property set to false on application startup. When I am on form2 I want to be able to check a checkbox and make the corresponding label on form1 visible. I will exit form2 and return to form1 when I click on the Apply button so some of the code can probably be in either form2.close or form1.show or maybe a got.focus or lost.focus

Thank you
John
Nov 20 '05 #1
9 1041
In article <36**********************************@microsoft.co m>,
an*******@discussions.microsoft.com says...
I have form1 and form2. Form1 has 25 labels and form2 has 25 checkboxes.
the labels on form1 all have their visible property set to false on
application startup. When I am on form2 I want to be able to check a
checkbox and make the corresponding label on form1 visible.


Form2 will need a reference to Form1 to be able to access the Labels.
Create a property on Form2 that will accept a Form1 instance:

Public Class Form2
Inherits System.Windows.Form

...
Private m_Form1 As Form1
...
Public Property MainForm
Set
m_Form1 = Value
End Set
End Property

...
End Class

Now, before showing Form2, pass Form1 to it:

(somewhere in Form1)

Dim f2 As Form2 = New Form2
f2.MainForm = Me
f2.ShowDialog()

Now inside the checkbox click events in Form2, you can access Form1
labels through the m_Form1 variable.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 20 '05 #2
Disregard this post

Sorry
John
Nov 20 '05 #3
Hi John,

When you use this in your program, (on a new item class page or even pasted
under your form1) then you can use it everywhere on every form in your
project. If you have beside this problems with showing the form, message
that again? Making them every time new will in my opinion not solve your
problem.

I hope this helps?

Cor
\\\
Public Class Checked
Private Shared mCheck(25) As Boolean
Public Shared Sub SetCheck(ByVal index As Integer, _
ByVal setting As Boolean)
mCheck(index) = setting
End Sub
Public Shared Function _
GetCheck(ByVal index As Integer) As Boolean
Return mCheck(index)
End Function
End Class
///
Nov 20 '05 #4
* "=?Utf-8?B?amNyb3VzZQ==?=" <an*******@discussions.microsoft.com> scripsit:
Anyways, sorry for that. Here is my problem. I have form1 and
form2. Form1 has 25 labels and form2 has 25 checkboxes. the labels on
form1 all have their visible property set to false on application
startup. When I am on form2 I want to be able to check a checkbox and
make the corresponding label on form1 visible. I will exit form2 and
return to form1 when I click on the Apply button so some of the code can
probably be in either form2.close or form1.show or maybe a got.focus or
lost.focus.


Are you creating 'Form2' within 'Form1'? Then you can easily pass a
reference to your instance of 'Form2' by adding a property of type
'Form1' to your 'Form2' and setting this property to 'Me' in 'Form1':

\\\
Public Class Form2
Inherits...

Private m_MyForm1 As Form1

Public Property MyForm1() As Form1
Get
Return m_MyForm1
End Get
Set(ByVal Value As Form1)
m_MyForm1 = Value
End Set
End Property
...
End Class
///

Inside 'Form1':

\\\
Dim f As New Form2()
f.MyForm1 = Me
f.Show()
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5
Hi John,

I forgot to tell how to use it.

mycheckbox.checked = checked.getcheck(23) 'checkbox 24

Cor
Nov 20 '05 #6
* "Cor Ligthert" <no**********@planet.nl> scripsit:
When you use this in your program, (on a new item class page or even pasted
under your form1) then you can use it everywhere on every form in your
project. If you have beside this problems with showing the form, message
that again? Making them every time new will in my opinion not solve your
problem.

I hope this helps?

Cor
\\\
Public Class Checked
Private Shared mCheck(25) As Boolean
Public Shared Sub SetCheck(ByVal index As Integer, _
ByVal setting As Boolean)
mCheck(index) = setting
End Sub
Public Shared Function _
GetCheck(ByVal index As Integer) As Boolean
Return mCheck(index)
End Function
End Class
///


1. Why not use a property?

2. I don't understand how this will allow access to the other forms'
controls.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #7
Hi Herfried,

I will take the time, however when it is to difficult you may ask again.

Let say you use the visible event from the form, than you can do in that
when you have used a simple textbox array.

for I as integer = 0 to 24
mytextbox(i).enabled = checked.getcheck(i)
next

Simple is it not?

What would be the benefit if a property was used by the way (with wich I
started however this is much simpler)

Cor
Nov 20 '05 #8
* "Cor Ligthert" <no**********@planet.nl> scripsit:
I will take the time, however when it is to difficult you may ask again.

Let say you use the visible event from the form, than you can do in that
when you have used a simple textbox array.

for I as integer = 0 to 24
mytextbox(i).enabled = checked.getcheck(i)
next

Simple is it not?
Right, but you cannot force the form to update without having a
reference to it.
What would be the benefit if a property was used by the way (with wich I
started however this is much simpler)


I hate those 'Set*' and 'Get*' methods :-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #9
> > What would be the benefit if a property was used by the way (with wich I
started however this is much simpler)


I hate those 'Set*' and 'Get*' methods :-).


Exactly the same with me however in this case the alternative was in my
opinion more difficult to describe.

:-)

Cor
Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mainard | last post by:
Hi, all First off I know alittle about javascript, but i have never worked with controlling froms with it be for i wonder can some help me? for example:I have this <textarea name"write1">Write...
0
by: Giulio Santorini | last post by:
Hi, I've got two drop down list controls. When I select a value from the first one I fill the second one. And when I select a value from the second one I would like to fill another control. But...
1
by: Robert W. | last post by:
I have a 'Controller' object that manages the interaction between its two children: a Form and a DataObject. I've written specialized code in the Controller to control how the Form updates the...
1
by: Holger (David) Wagner | last post by:
Hi there, we have an application which is built with several ASCX controls some of which contain form elements (e.g. Textboxes, Buttons etc.) For example: in the top section (one...
8
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
5
by: =?Utf-8?B?UmljaA==?= | last post by:
Hello, If I create a form in Java with controls like Panels, textboxes... when I stretch/shrink the form, all the controls can grow/shrink - along with the text contained in the textboxes. This...
4
by: Joergen Bech | last post by:
Just out of curiosity: What is your favorite method of making sure that anything that happens on a form, only happens in response to a single, external event? Take the example below. I have made...
0
by: DonnaDarko | last post by:
Hi again, I have a question regarding how to control one form's values from another form. I have figured out that the best spot for this control comes from the OKButton on a form called...
16
by: Mike | last post by:
Hi, I have a form with some controls, and a different class that needs to modify some control properties at run time. Hoy can I reference the from so I have access to its controls and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.