473,405 Members | 2,167 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,405 software developers and data experts.

Accessing properties of multiple (different) controls

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
3 1207
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Hargrove | last post by:
I'm having trouble setting decimal place values in the results field of a sample management database I'm building for an environmental testing laboratory. The degree of sensitivity varies among...
5
by: Jonathan Williams | last post by:
Hi, I have an object which inherits from WebControl (CUSTOM : WebControl) In this object I have code in which I add child contols: protected override void CreateChildControls() {...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
1
by: Jeff Smith | last post by:
Can I load custom web user controls dynamically and access the properties and methods without having to explicitly define custom control types (example 2 below). I have custom web control named...
1
by: Sammy | last post by:
When a user control access SQL Server, what happens if I host it multiple times on one webpage (create several instances of that user control), in terms of trips being made to the server? How can I...
6
by: arvee | last post by:
Is there a way to access controls (and their properties) in a user control? The Web Form Designer marks controls as 'Protected' which makes them inaccessable from the host form. If I mark them as...
0
by: tshad | last post by:
I have a User Control with 4 Textboxes. I want to be able to access the properties (.text, .visible, .enable etc) directly from outside the Controls as the normal properties (.text, .visible...
7
by: =?Utf-8?B?Li46OiBLZXZpbiA6Oi4u?= | last post by:
I have a problem with accessing controls that I have loaded dynamically and added to a web page. The scenario: I have a webpage that displays multiple instances of a user control on the page. ...
0
by: Kabo | last post by:
Hi there, I'm currently working on a C# application that deals with dynamically created TabPages based (each TabPage represents a file that has been opened). On each TabPage there is a...
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.