Expose Form Properties and it Controls Properties.

  • Thread starter Thread starter Dimsion
  • Start date Start date
D

Dimsion

Hi,

How do i expose all my forms and it controls to other form in the project?
I want to be able to add a form and some control on it, this then be
available to all other forms.

form1 click event:
'this allow me to change the textbox on form2 from form1
Form2.text=""
'this allow me to add item to form2 from form1
Form2.listview.item.add("")
end form1 click event:

Dimsion
Visual Studio 2005/VB

====Sorry to double post this, but maybe where i have posted this quesiton
was not the right place the first time.===
 
Hello:

Declare a instance of form 2 in form1 and use that instance to refer to
form2's controls.
Like:
Dim instfrm2 as New form2
instfrm2.text = ""
instfrm2.listview.item.add("")

You might even declare a public variable for form2 and access it within
form1.

Hope this helps
 
I believe all forms are public by default and all controls are Friends
by default unless you change the modifiers property of that control to
something else. Friends modifier means, other classes/forms within the
same project/assembly are permitted to change the properties and adding
items to the control. Let's go back to your example:

you have form1 that has a click capture a click event
Form2 has a textbox and a listview controls
Now, when the click event is fired:
Form2.textbox.text = "Whatever" and Form2.listview.item.add("Whatever")
are excuted and they shouldn't cause any problems.

I am assuming that both forms are running on the same thread. If each
as its own thread, you need to use delegates or p/invoke. Somebody
correct me if I am wrong.

Ahmed
 
Ahmed,

I have two project that i work on, the old one can communicate between forms
and controls. If i added a new form and control on it to that project it can
continue to allow me to access the form and controls. However if i start a
new proect, it will not work the same way.

I have try to declare as IdelBrain mention in the other thread, but it only
allow me access to the form and not it controls.

Thanks,
Dimsion
 
It didn't allow you to access them because their modifier is set to
Friends which is the default value. If you select and of the controls
(listview, buttons), in the properties window there is an entry called
modifers. You need to set that to public. But, that means anybody who
knows .NET can include your excutable in their project and have fun
with it.
 
Thanks Ahmed,

The project default was private, that's why i can't get it to work.
I have change it to friend and everything work fine. I think friend would
only allow the program access the properties and not everyone else(i
think..).

Thanks you sooo much!!

Dimsion.
 
Ahmed,

Do you know how to set the default to be friend instead of private?

Thanks,
Dimsion
 
Sorry about that,
I meant to say do you know how to set the modifier default to friend,
currently every project i started have the modifier set to private.

Thanks again,
Dimsion
 
But I never saw a modifer for a project. Usually the modifer for the
controls on the form. Just select all controls and set the modifer to
friend or public.
 
Back
Top