473,411 Members | 1,923 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,411 software developers and data experts.

Control Properties

Hello all,
Can you dynamically change the property options for a control in the property grid of VisualStudio?

What I want is to be able to change some of the property options which are dependent upon others. For example:
If my control orientation was horizontal then I would want the text direction options to be "left" or "right" but if the orientation wsa vertical then I would want the text direction options to be "up" and "down". It does go deeper than that as there likely to be at least three controls dependent upon each other...

Currently I have some getter/setter methods which expose my custom properties in the property grid but I cannot see how you can change the options dependent upon another getter/setter method.

Clearly I need this to work at design time, which the current method does after the source is built.

Can anoyone help?

Thanks
Jun 17 '09 #1
10 1693
tlhintoq
3,525 Expert 2GB
Override the OnPaint and put some of the logic in there.
This has to run even at design time in order for the form to be painted so you can work on it.
Jun 17 '09 #2
r035198x
13,262 8TB
Just register appropriate event handlers to your controls.
Jun 17 '09 #3
Thanks for the reply but it is the logic that is escaping me at the moment :(

This is what I have so far; it should be quite obvious to someone with brains what I am doing wrong!!

Expand|Select|Wrap|Line Numbers
  1. public partial class CustomControl1 : Control
  2.     {
  3.         public enum HorizontalDirection
  4.         {
  5.             Left,
  6.             Right,
  7.         }
  8.  
  9.         public enum VerticalDirection
  10.         {
  11.             Up,
  12.             Down,
  13.         }
  14.  
  15.         public enum ControlOrientation
  16.         {
  17.             Horizontal,
  18.             Vertical
  19.         }
  20.  
  21.         private Enum _direction;
  22.         private ControlOrientation _orientation;
  23.  
  24.         public Enum TextDirection
  25.         {
  26.             get
  27.             {
  28.                 if (_orientation == ControlOrientation.Horizontal)
  29.                 {
  30.                     return _direction; //[need to return HorizontalDirection];
  31.                 }
  32.                 else
  33.                 {
  34.                     return _direction; //[need to return VerticalDirection];
  35.                 }
  36.             }
  37.             set
  38.             {
  39.                 _direction = value; 
  40.             }
  41.         }
  42.  
  43.         public ControlOrientation Orientation
  44.         {
  45.             get
  46.             {
  47.                 return _orientation;
  48.             }
  49.             set
  50.             {
  51.                 _orientation = value;
  52.             }
  53.         }
  54.  
Jun 17 '09 #4
r035198x
13,262 8TB
You don't really need to extend (inherit from) the Control class to do this.
Just add event handlers to instances of your controls.
Here is a basic example of attaching an event handler to a button's onclick action.
The trick for you will be attaching the delegates to the appropriate event for each control.
Jun 17 '09 #5
@r035198x
Agreed, attaching to the correct event is tricky...not sure where to start!!

Even if I did manage to figure it out, I still need to somehow return the correct enum from the method the event handler calls to give the correct options, wouldn't I??
Jun 17 '09 #6
r035198x
13,262 8TB
The good news is you don't have to guess. All the controls have a lot of documentation at MSDN (and indeed probably available on your IDE) that explains which event listeners you can attach handlers on. The handlers (delegate methods) would then change the look of the controls as you wish. The method handler methods themselves would take parameters about the control that generated the event so you can decide how to change your controls by analyzing the source of the events from the parameters.
Jun 17 '09 #7
@r035198x
This is a custom control created by me and MSDN will not have any information on it!!

Cannot find any sound examples so i'll approach this another way...
Jun 17 '09 #8
r035198x
13,262 8TB
Even if it's custom control, isn't it that the changes you want to listen for are available in the Control class(es) that you inherited from?
Whatever approach you decide to take I feel that it should ultimately involve attaching appropriate delegates to handle property changes on your controls.
Jun 17 '09 #9
tlhintoq
3,525 Expert 2GB
Thanks for the reply but it is the logic that is escaping me at the moment :(
The logic for which part...?
How to tell if your control is horizontal or vertical?
Expand|Select|Wrap|Line Numbers
  1. if (this.width > this.height) 
  2. {
  3.    this.orientation = Control.Orientation.Horizontal;
  4. }
Otherwise, please me more specific about where you are lost.
Jun 17 '09 #10
@tlhintoq
No, :) not the orientation bit. I meant the event handlers but; I think that is solved now though.

The newest bit that has me is how you can dynamically change the options for a control property ie for the direction property how can you change it from having a choice of left and right to have a choice of up and down?

thanks for your reply
Jun 17 '09 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: deko | last post by:
I'm trying to find a way to set form/control properties programmatically. In a nut shell: 1. Open a database 2. Open a form in design view 3. Do something like this: For Each prp In...
8
by: deko | last post by:
I'm hoping someone can sanity check my understanding of the Object Model for Forms/Controls. I'm having trouble drilling down into Control properties. First, I have a record set with the...
5
by: Eric | last post by:
Given System.Web.UI.Control Control Can I determine the height of Control without knowing specifically what it is?
5
by: Miguel Dias Moura | last post by:
Hello, i am trying to create a .css file with several styles and apply them to the calendar control so i can change the look of: 1. Text Type and Format (Bold, Underline, etc) 2. Background...
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...
4
by: Mark Goldin | last post by:
I'd like to create a user control (Label and Text box) and modify every instance of that control when I add it to a web page. How can I do that?
4
by: TS | last post by:
When i try to access the page class or parent properties inside a server control that is nested in another server control, they are null. I don't even call CreateChildControls for the parent...
0
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
2
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be...
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
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
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...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.