473,503 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PropertyGrid Category Appearance

I want to display in my application a PropertyGrid showing only the
"Appearance" of a control (ie. textBox) so the user can change it.
Bare with me, I'm new in csharp.

Where do I go from:
this.PropertyGrid1.SelectedObject = this.Textbox1;

Thank a lot
Nov 15 '05 #1
3 7302
Derive a class from TextBox that implements ICustomTypeDescriptor.

You can use the GetProperties method to return a
PropertyDescriptorCollection that you can create on the fly looking at all
the properties and only putting the ones you want, such as those with the
"Appearance" category on the list.

--
Bob Powell [MVP]
C#, System.Drawing

September's edition of Well Formed is now available.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

"Nicolas" <nl*****@hotmail.com> wrote in message
news:u1**************@TK2MSFTNGP12.phx.gbl...
I want to display in my application a PropertyGrid showing only the
"Appearance" of a control (ie. textBox) so the user can change it.
Bare with me, I'm new in csharp.

Where do I go from:
this.PropertyGrid1.SelectedObject = this.Textbox1;

Thank a lot

Nov 15 '05 #2
Thank you, I try some of those but get very confuse with all those csharp
code, so it never works.
Won't you have any very sample code to point me to the right direction.

Thank you very much.
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:OH****************@TK2MSFTNGP12.phx.gbl...
Derive a class from TextBox that implements ICustomTypeDescriptor.

You can use the GetProperties method to return a
PropertyDescriptorCollection that you can create on the fly looking at all
the properties and only putting the ones you want, such as those with the
"Appearance" category on the list.

--
Bob Powell [MVP]
C#, System.Drawing

September's edition of Well Formed is now available.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

"Nicolas" <nl*****@hotmail.com> wrote in message
news:u1**************@TK2MSFTNGP12.phx.gbl...
I want to display in my application a PropertyGrid showing only the
"Appearance" of a control (ie. textBox) so the user can change it.
Bare with me, I'm new in csharp.

Where do I go from:
this.PropertyGrid1.SelectedObject = this.Textbox1;

Thank a lot


Nov 15 '05 #3
This is part of a set of examples from this months Well Formed magazine
which has an article on enhancing the user UI by customizing the
PropertyGrid view. To get the rest of the article you can subscribe to Well
Formed here...

http://www.bobpowell.net/subscribe.htm
Code After my signature.

--
Bob Powell [MVP]
C#, System.Drawing

September's edition of Well Formed is now available.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

----------------------------------------------

using System;

using System.Drawing;

using System.Drawing.Design;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using System.Reflection;

namespace PropertyFilter

{

/// <summary>

/// Summary description for Form1.

/// </summary>

public class Form1 : System.Windows.Forms.Form

{

private System.Windows.Forms.Button button1;

private System.Windows.Forms.Button button2;

private System.Windows.Forms.PropertyGrid propertyGrid1;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

Filterable f=new Filterable();

public Form1()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.button1 = new System.Windows.Forms.Button();

this.button2 = new System.Windows.Forms.Button();

this.propertyGrid1 = new System.Windows.Forms.PropertyGrid();

this.SuspendLayout();

//

// button1

//

this.button1.Location = new System.Drawing.Point(8, 32);

this.button1.Name = "button1";

this.button1.TabIndex = 0;

this.button1.Text = "With";

this.button1.Click += new System.EventHandler(this.button1_Click);

//

// button2

//

this.button2.Location = new System.Drawing.Point(8, 72);

this.button2.Name = "button2";

this.button2.TabIndex = 0;

this.button2.Text = "Without";

this.button2.Click += new System.EventHandler(this.button2_Click);

//

// propertyGrid1

//

this.propertyGrid1.Anchor =
((System.Windows.Forms.AnchorStyles)((((System.Win dows.Forms.AnchorStyles.To
p | System.Windows.Forms.AnchorStyles.Bottom)

| System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right)));

this.propertyGrid1.CommandsVisibleIfAvailable = true;

this.propertyGrid1.LargeButtons = false;

this.propertyGrid1.LineColor = System.Drawing.SystemColors.ScrollBar;

this.propertyGrid1.Location = new System.Drawing.Point(160, 16);

this.propertyGrid1.Name = "propertyGrid1";

this.propertyGrid1.Size = new System.Drawing.Size(272, 240);

this.propertyGrid1.TabIndex = 1;

this.propertyGrid1.Text = "propertyGrid1";

this.propertyGrid1.ViewBackColor = System.Drawing.SystemColors.Window;

this.propertyGrid1.ViewForeColor =
System.Drawing.SystemColors.WindowText;

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(440, 266);

this.Controls.Add(this.propertyGrid1);

this.Controls.Add(this.button1);

this.Controls.Add(this.button2);

this.Name = "Form1";

this.Text = "Form1";

this.ResumeLayout(false);

}

#endregion

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main()

{

Application.Run(new Form1());

}

private void button1_Click(object sender, System.EventArgs e)

{

this.f.Filtered=true;

this.propertyGrid1.SelectedObject=f;

this.propertyGrid1.Refresh();

}

private void button2_Click(object sender, System.EventArgs e)

{

this.f.Filtered=false;

this.propertyGrid1.SelectedObject=f;

this.propertyGrid1.Refresh();

}

}

class Filterable : ICustomTypeDescriptor

{

bool _filtered;

public bool Filtered

{

get{return _filtered;}

set{_filtered=value;}

}

string _stringOne;

[Category("Other")]

public string StringOne

{

get{return _stringOne;}

set{_stringOne=value;}

}

string _stringTwo;

[Category("Appearance")]

public string StringTwo

{

get{return _stringTwo;}

set{_stringTwo=value;}

}

#region ICustomTypeDescriptor Members

public TypeConverter GetConverter()

{

// DONE: Add Filterable.GetConverter implementation

return TypeDescriptor.GetConverter(this,true);

}

public EventDescriptorCollection GetEvents(Attribute[] attributes)

{

// DONE: Add Filterable.GetEvents implementation

return TypeDescriptor.GetEvents(this,attributes,true);

}

EventDescriptorCollection
System.ComponentModel.ICustomTypeDescriptor.GetEve nts()

{

// DONE: Add
Filterable.System.ComponentModel.ICustomTypeDescri ptor.GetEvents
implementation

return TypeDescriptor.GetEvents(this,true);

}

public string GetComponentName()

{

// DONE: Add Filterable.GetComponentName implementation

return TypeDescriptor.GetComponentName(this,true);

}

public object GetPropertyOwner(PropertyDescriptor pd)

{

// DONE: Add Filterable.GetPropertyOwner implementation

return this;

}

public AttributeCollection GetAttributes()

{

// DONE: Add Filterable.GetAttributes implementation

return TypeDescriptor.GetAttributes(this,true);

}

public PropertyDescriptorCollection GetProperties(Attribute[]
attributes)

{

// DONE: Add Filterable.GetProperties implementation

PropertyDescriptorCollection
pdc=TypeDescriptor.GetProperties(this,attributes,t rue);

if(_filtered)

{

PropertyDescriptorCollection pds=new
PropertyDescriptorCollection(new PropertyDescriptor[0]);

foreach(PropertyDescriptor pd in pdc)

{

Attribute a=pd.Attributes[typeof(CategoryAttribute)];

if(a!=null && ((CategoryAttribute)a).Category=="Appearance")

{

pds.Add(pd);

}

}

return pds;

}

else

return TypeDescriptor.GetProperties(this,attributes,true) ;

}

PropertyDescriptorCollection
System.ComponentModel.ICustomTypeDescriptor.GetPro perties()

{

// DONE: Add
Filterable.System.ComponentModel.ICustomTypeDescri ptor.GetProperties
implementation

PropertyDescriptorCollection
pdc=TypeDescriptor.GetProperties(this,true);

if(_filtered)

{

PropertyDescriptorCollection pds=new
PropertyDescriptorCollection(new PropertyDescriptor[0]);

foreach(PropertyDescriptor pd in pdc)

{

Attribute a=pd.Attributes[typeof(CategoryAttribute)];

if(a!=null && ((CategoryAttribute)a).Category=="Appearance")

{

pds.Add(pd);

}

}

return pds;

}

else

return pdc;

}

public object GetEditor(Type editorBaseType)

{

// DONE: Add Filterable.GetEditor implementation

return TypeDescriptor.GetEditor(this, typeof(UITypeEditor), true);

}

public PropertyDescriptor GetDefaultProperty()

{

// DONE: Add Filterable.GetDefaultProperty implementation

return TypeDescriptor.GetDefaultProperty(this, true);

}

public EventDescriptor GetDefaultEvent()

{

// DONE: Add Filterable.GetDefaultEvent implementation

return TypeDescriptor.GetDefaultEvent(this,true);

}

public string GetClassName()

{

// DONE: Add Filterable.GetClassName implementation

return TypeDescriptor.GetClassName(this,true);

}

#endregion

}

}


----------------------------------------------

"Nicolas" <nl*****@hotmail.com> wrote in message
news:eu**************@TK2MSFTNGP12.phx.gbl...
Thank you, I try some of those but get very confuse with all those csharp
code, so it never works.
Won't you have any very sample code to point me to the right direction.

Thank you very much.
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:OH****************@TK2MSFTNGP12.phx.gbl...
Derive a class from TextBox that implements ICustomTypeDescriptor.

You can use the GetProperties method to return a
PropertyDescriptorCollection that you can create on the fly looking at all the properties and only putting the ones you want, such as those with the "Appearance" category on the list.

--
Bob Powell [MVP]
C#, System.Drawing

September's edition of Well Formed is now available.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

"Nicolas" <nl*****@hotmail.com> wrote in message
news:u1**************@TK2MSFTNGP12.phx.gbl...
I want to display in my application a PropertyGrid showing only the
"Appearance" of a control (ie. textBox) so the user can change it.
Bare with me, I'm new in csharp.

Where do I go from:
this.PropertyGrid1.SelectedObject = this.Textbox1;

Thank a lot



Nov 15 '05 #4

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

Similar topics

0
1210
by: Dave | last post by:
Hi all, To repro the problem I am having: 1. Create a class that derives from System.Windows.Forms.Form 2. Add some controls such as buttons and labels (wherever you want). The default values...
4
23878
by: Robert Hooker | last post by:
Hi all, I'm looking for a way to sort/order the Category text items in a property grid. The grids sort the categories by alpha when the catergories are displayed. Does anyone at Microsoft (or...
2
3956
by: Mevar81 | last post by:
Hi to everybody.I have a problem with the PropertyGrid control.I want to display not all the properties of a generic Control(Button,TextBox,ComboBox,ecc.).In general I don't want to display only...
2
3401
by: Steve Teeples | last post by:
Someone introduced me to PropertyGrid last night. It is a great feature for what I need. A question though. I noticed that when I assign a "TextBox" control to a property grid the description on...
1
11851
by: ANDRES BECERRA | last post by:
Herfried K. Wagner was kind enough to point me to the PropertyGrid control http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwindowsformspropertygridclasstopic.asp I have found a few...
4
1708
by: Nicolas | last post by:
I want to display in my application a PropertyGrid showing only the "Appearance" of a control (ie. textBox) so the user can change it. Bare with me, I'm new in Dotnet VB. Where do I go from:...
2
4829
by: Lance | last post by:
I want to be able to reset a complex property in a PropertyGrid. I know that for properties that are ValueTypes you can include System.ComponentModel.DefaultValue in the declaration of the property....
3
2784
by: Joe | last post by:
Hi I have a propertygrid that I allow the user to pick a system.color and I want to save to a file to load later onto the propertygrid. String and bool values work but I am unable to save...
2
7929
by: Marco Segurini | last post by:
Hi All, I have a form containing only a PropertyGrid that I use to modify an instance of the following class: class MyClass { Point _point = new Point();
0
7076
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
7323
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...
1
6984
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
7453
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
5576
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,...
1
5005
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...
0
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
377
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.