By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,566 Members | 1,762 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,566 IT Pros & Developers. It's quick & easy.

Accessing properties of multiple (different) controls

P: n/a
Hi,

I have a main form with a number of controls on it. They are a range
of different customized controls.
There are some properties that belong to all of these controls, such
as XOffset, YOffset etc.
Currently, in order to get this value when for instance, the user
clicks on the control, I need to determine the type of control, then
reference it in the following manner:

int MyOffset;

String WhatType = sender.GetType();
if (WhatType == "WindowsApplication1.ucContType1) then
MyOffset = ((WindowsApplication1.ucConttype1)sender).XOffset
if (WhatType == "WindowsApplication1.ucContType2) then
MyOffset = ((WindowsApplication1.ucConttype2)sender).XOffset

As I am referencing a lot of properties on a lot of occasions, the
code starts to get a little unmanageable, even when putting these
lookups away in functions.

So, my question is, is there a way to access a property that I know
belongs to every one of these different types of controls, without
needing to find out the control type?

Thankyou.

James
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Derive all of your controls from a common base that includes the XOffset
property.

HTH

DalePres
MCAD, MCDBA, MCSE
"jralford" <jr******@hotmail-dot-com.no-spam.invalid> wrote in message
news:42********@127.0.0.1...
Hi,

I have a main form with a number of controls on it. They are a range
of different customized controls.
There are some properties that belong to all of these controls, such
as XOffset, YOffset etc.
Currently, in order to get this value when for instance, the user
clicks on the control, I need to determine the type of control, then
reference it in the following manner:

int MyOffset;

String WhatType = sender.GetType();
if (WhatType == "WindowsApplication1.ucContType1) then
MyOffset = ((WindowsApplication1.ucConttype1)sender).XOffset
if (WhatType == "WindowsApplication1.ucContType2) then
MyOffset = ((WindowsApplication1.ucConttype2)sender).XOffset

As I am referencing a lot of properties on a lot of occasions, the
code starts to get a little unmanageable, even when putting these
lookups away in functions.

So, my question is, is there a way to access a property that I know
belongs to every one of these different types of controls, without
needing to find out the control type?

Thankyou.

James
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 16 '05 #2

P: n/a
Thanks for the response.

Ok, so I can derive my controls from a common base.
Now in each control type I can see the property and get the values I
need.
However, it doesn't seem to solve the problem of having to get to the
property through each different type of control on the form and
therefore needing to go through the process I outlined in my original
post - to find out what type of control the clicked on object is, then
get the property with: ((controltye)sender).property

To clarify a little more if a user clicks on a control, I do not want
to know what type of control it is. I just want to access the
property.

Am I missing something?

thanks again.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 16 '05 #3

P: n/a
You do not need to know the control's type because they all derive from a
base class X.
Each control you get is of type X as far as your code is concerned....

Eran Kampf
http://www.ekampf.com
http://www.ekampf.com/blog

"jralford" <jr******@hotmail-dot-com.no-spam.invalid> wrote in message
news:42********@127.0.0.1...
Thanks for the response.

Ok, so I can derive my controls from a common base.
Now in each control type I can see the property and get the values I
need.
However, it doesn't seem to solve the problem of having to get to the
property through each different type of control on the form and
therefore needing to go through the process I outlined in my original
post - to find out what type of control the clicked on object is, then
get the property with: ((controltye)sender).property

To clarify a little more if a user clicks on a control, I do not want
to know what type of control it is. I just want to access the
property.

Am I missing something?

thanks again.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.