473,387 Members | 1,572 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,387 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 2753
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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...

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.