472,791 Members | 979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,791 software developers and data experts.

Showing different properties in design/run mode - user controls

ajk
Hi

I was wondering how to show different properties in design and
run-mode for a user control? Is it possible to do this when
implementing the System.ComponentModel.ICustomTypeDescriptor
interface?

e.g. when selecting the control from a toolbox with controls other
properties show up when the program is in design mode than in run
mode.

BR/ajk
Aug 26 '07 #1
6 2715
Well, yes it probably is, but I wouldn't recommend it; remember that
the designer is typically simply writing code based on the properties,
so keeping it normal (i.e. the same, regular properties exist at both
run- and design-time) is the best approach. Otherwise you'd have to
override the designer serializer to get it to write the correct code
to setup your object, and that isn't always easy.

However! What is it you want to do? If you simply want to filter the
lists, then you can do this by setting appropriate [Browsable] and
[EditorBrowsable] attributes; setting [Browsable(false)] on a property
will remove it from the PropertyGrid (warning: this will also
generally make it non-bindable at run-time); setting
[EditorBrowsable(EditorBrowsableState.Never)] will hide it in the
editor (although it still exists and can be used).

Of course, another option is to write a custom UITypeEditor for your
object, and set the [Editor] against the class; you can then provide
your own UI for the designer to use - but note that it *still* needs
to be understandable by the designer-serializer, so keep it simple...

Is this sufficient?

Marc

Aug 26 '07 #2
ajk
On Sun, 26 Aug 2007 12:15:37 -0700, Marc Gravell
<ma**********@gmail.comwrote:
>Well, yes it probably is, but I wouldn't recommend it; remember that
the designer is typically simply writing code based on the properties,
so keeping it normal (i.e. the same, regular properties exist at both
run- and design-time) is the best approach. Otherwise you'd have to
override the designer serializer to get it to write the correct code
to setup your object, and that isn't always easy.

However! What is it you want to do? If you simply want to filter the
lists, then you can do this by setting appropriate [Browsable] and
[EditorBrowsable] attributes; setting [Browsable(false)] on a property
will remove it from the PropertyGrid (warning: this will also
generally make it non-bindable at run-time); setting
[EditorBrowsable(EditorBrowsableState.Never)] will hide it in the
editor (although it still exists and can be used).

Of course, another option is to write a custom UITypeEditor for your
object, and set the [Editor] against the class; you can then provide
your own UI for the designer to use - but note that it *still* needs
to be understandable by the designer-serializer, so keep it simple...

Is this sufficient?

Marc
thanks for your help Marc!

The reason for having different properties in design and run-mode is
that we have a client that allows users to create displays, the person
creating the displays - the designer - is not the same who is going to
use them and therefore they need to be simpler for the end-user.

So when the display is switched to design mode more detailed
properties should show up and when in run-mode just basic ones should
show up like colors.

/ajk
Aug 27 '07 #3
So I assume you are using PropertyGrid on your user-facing UI?

The quickest option here is probably to use BrowsableAttributes on the
PropertyGrid (below)

Marc

using System;
using System.ComponentModel;
using System.Windows.Forms;

static class Program {
static void Main() {
Application.EnableVisualStyles();
using(Form f = new Form())
using (PropertyGrid grid = new PropertyGrid()) {
f.Text = "BrowsableAttributes demo";
grid.Dock = DockStyle.Fill;
grid.SelectedObject = new SomeData();
grid.BrowsableAttributes = new AttributeCollection(new
BrowsableAttribute(true), new UserFacingAttribute());
f.Controls.Add(grid);
Application.Run(f);
}
}
}
sealed class SomeData {

private bool someBool;
[Description("I'm something complex; unsuitable for the users")]
public bool SomeBool { get { return someBool; } set { someBool =
value; } }

private string someString, someComplexString;
[UserFacing, Description("I'm a friendly cuddly string")]
public string SomeString { get { return someString; } set {
someString = value; } }

[Description("Eek!")]
public string SomeComplexString { get { return
someComplexString; } set { someComplexString = value; } }

private DateTime someDate;
[UserFacing, Description("Simple, me")]
public DateTime SomeWhen { get { return someDate; } set { someDate
= value; } }
}

[ImmutableObject(true)]
sealed class UserFacingAttribute : Attribute {}
Aug 28 '07 #4
ajk
On Tue, 28 Aug 2007 08:35:49 +0100, "Marc Gravell"
<ma**********@gmail.comwrote:
>So I assume you are using PropertyGrid on your user-facing UI?

The quickest option here is probably to use BrowsableAttributes on the
PropertyGrid (below)

Marc

using System;
using System.ComponentModel;
using System.Windows.Forms;

static class Program {
static void Main() {
Application.EnableVisualStyles();
using(Form f = new Form())
using (PropertyGrid grid = new PropertyGrid()) {
f.Text = "BrowsableAttributes demo";
grid.Dock = DockStyle.Fill;
grid.SelectedObject = new SomeData();
grid.BrowsableAttributes = new AttributeCollection(new
BrowsableAttribute(true), new UserFacingAttribute());
f.Controls.Add(grid);
Application.Run(f);
}
}
}
well no i am not using the property grid, this program is designed
like this (not my design, som q&d vb6 programmer did it):

user control
communication class : user control
baseclass : communication class
my control : base class (from base class new controls are derived)

then in "my control" there are a number of properties like the normal
location, autosize etc. and some custom ones

e.g.

[Description("String to display instead of the value if the value is
above high range or below low range."), Category("Appearance")]
public string OutOfRangeString
{
get { return this.outOfRangeString; }
set
{
this.outOfRangeString = value;
...
}
}
[DisplayName("Numeric Items"), Browsable(false)]
public NumericValueColorWrapperCollection NumericItems
{
get { return this.numNumValColorWrapCol; }
}

so far that works, however having it like this makes for a lot for
similar coding in each control and it feels as if one can do it better
than this? saving/loading the properties calls a method in the base
class.

i still want to force users to implement the communication methods but
in the base class there are a lot of other gonk which makes each "my
control" quite version sensitive, my idea was to separate the library
stuff from the communication making the comm an interface and the lib
stuff a member instance in the "my control's", then using reflection
to get hold of the methods that way making it more resilient against
versioning.

i appreciate a lot your input! I hope I have expressed myself clearly
even though i went slightly off-topic :)
br/ajk
Aug 28 '07 #5
hrmph hopefully this was clearer, although i am not sure :)

OK - so *how* are you currently showing these properties? If this is
via a PropertyGrid (similar to Visual Studio) then a variant on my
earlier post should suffice. If you are showing them in some other,
bespoke way, then you'll need to mention how you are showing them.

As for having similar properties in design mode... put them on the
base-class, then... or if this is not possible, use something like
IExtenderProvider or TypeDescriptionProvider to supplement the
properties on the fly - but the problem here is that you need
somewhere concrete to put the data (the base-class doesn't have this
issue since you can use direct fields storage in the base-class). Any
use?

Marc

Aug 29 '07 #6
ajk
On Wed, 29 Aug 2007 13:25:51 -0700, Marc Gravell
<ma**********@gmail.comwrote:
>
OK - so *how* are you currently showing these properties? If this is
via a PropertyGrid (similar to Visual Studio) then a variant on my
earlier post should suffice. If you are showing them in some other,
bespoke way, then you'll need to mention how you are showing them.
yep you are right, not having written that piece of code I did some
research and found it. thanks for your help and patience Marc

br/ajk
Aug 30 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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...
12
by: Simon Jefferies | last post by:
Hello, I have created a new form within C# and I am unable to get any properties on this form and also unable to add a new controls to it. Any ideas? Simon Jefferies
5
by: Grant | last post by:
Hello, How come when I add a new row to my dataset table it shows up as changed (agencyData.Haschanges() = True) but when I delete a row the dataset thinks here are no...
1
by: Jim | last post by:
I have some complex (fairly) user controls that I have created. Some of those user controls host other user controls. When I host one of these on a WinForm, I sometimes run into problems where...
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: Christophe Peillet | last post by:
I have a CompositeControl with two types of properties: 1.) Mapped Properties that map directly to a child control's properties (ex.: this.TextboxText = m_txt.Text). These properties are handled...
4
by: Suhaib | last post by:
Hi All, I'm using VS 2005 8.0.50727.42 (RTM.050727-4200), with .NET framework 2.0. Everything was working fine, but now suddenly I don't see my ToolBox icons, whether you are in design mode or...
0
by: fiaolle | last post by:
Hi I have a combobox wich I set the Datasource,Displaymember and Valuemember at design time. I'm using a Dataset's table. But when I run the form the combobox isn't filled. Can't I set properties...
0
by: DigitalDan3 | last post by:
Visual Studio 2008 C#. Web Controls I have a simple user control (TextBoxViewer) that contains 2 controls a TextBox and a Label Control. The usercontrol exposes a default "Text" property and also...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.