Obtaining Buttons and Menu Items similarly to Delphi's Form.Compon

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Can anyone tell me how to obtain access to controls (MenuItems and Buttons)
so that I can create a parent forms method to control the switching of
Enabled on/off for same?

I am a Delphi programmer converting to C#.

Thanks in advance,

Roger.
 
I don't quite understand what you are looking for here...
do you want access the controls of one form from another?
If so... that goes two ways:

1. You have a parent form who creates two children, Bob
and Sam. Do you want Sam to be able to change aspects of
Bob's controls?

2: Are you having the parent form create a single child
and want one of them to be able to modify the others
controls?

In either case, it is doable, provided that the modifying
form has a reference to the form whose controls will be
modified and that said controls are public. I should note,
that this is not a very good way of doing it. Within
the .NET world (as well as OOP in general), you should try
to create appropriate public interfaces for a class to
modify internal private parts.
 
Thanks for your reply.

I inherit from my own forms quite a lot - basically, like most programmers,
I have a way of working that I like. I usually add a public method that will
enable/disable controls - particularly Buttons and MenuItems so that when I
navigate to a subordinate form I can switch-off the Enabled feature before
showing the subordinate form (e.g. I may need to switch off the button that
navigates to my subordinate form so that the form cannot be called again).

The arguments of the method that I use are generally: -
a) enable state (state that I want),
b) an array of controls that the method should ignore.

This means that when my method is processing it needs to get a list (as a
general term) of the controls on the form, pass through the list - determine
if the item is a Button or a MenuItem, determine if the control is in the
list of controls to ignore and if not switch the enable state of the control.
Hope all that makes sense!

I believe that I can use form.controls (that's according to how I make sense
of the help) but that doesn't seem to give me MenuItems (I need all controls
in a single list). So that really my question - How can I get all controls on
the form in a single list.

I create this method primarily because it is relatively elegant and mostly
maintenance free and I only need to add specifics (which are the items that I
want the method to ignore).

Because I'm converting from Delphi the problem maybe cultural. I do use
similar methods in other self created productivity tools.

I tried posting this message this morning - and it seemed ok but my message
didn't appear in the log.
 
Back
Top