properties of user controls
-
Dear All, I am making a Windows Control Library(user control) using VS.NET & C#.NET. Now, i am facing 3 problems: 1.In this control, i wants to remove some of the properties which are available by default to the controls. These properties must be removed from the 'Properties window' of the usercontrol. Also the user must not be able to set these properties using code. I am able to remove the properties from the 'Properties window' by inheriting a class from the System.Windows.Forms.Design.ScrollableControlDesigner & removing the properties by overriding the PreFilterProperties function as show below: protected override void PreFilterProperties(System.Collections.IDictionary properties) { properties.Remove("BackColor"); } But, doing so, this property is available to be set from the code. How can i remove this property fully? 2.I wants to create a property for the control which has sub properties, like the 'Location' property of a button, which has sub properties as 'X, Y & Locked'. My new property for the control must have some subproperties like this. How can i achieve this? 3.I wants to add a property to the user control which allows the user to select a color. When the user selects this property, it must display the same options which are displayed for selecting the color for the satndard properties like 'BackColor'. Then the user must be able to select the required color from these options & the value must be stored in that specific property. Kindly help me to acheieve the above scenarios Best Regards, Abhilash Chandran
-
Dear All, I am making a Windows Control Library(user control) using VS.NET & C#.NET. Now, i am facing 3 problems: 1.In this control, i wants to remove some of the properties which are available by default to the controls. These properties must be removed from the 'Properties window' of the usercontrol. Also the user must not be able to set these properties using code. I am able to remove the properties from the 'Properties window' by inheriting a class from the System.Windows.Forms.Design.ScrollableControlDesigner & removing the properties by overriding the PreFilterProperties function as show below: protected override void PreFilterProperties(System.Collections.IDictionary properties) { properties.Remove("BackColor"); } But, doing so, this property is available to be set from the code. How can i remove this property fully? 2.I wants to create a property for the control which has sub properties, like the 'Location' property of a button, which has sub properties as 'X, Y & Locked'. My new property for the control must have some subproperties like this. How can i achieve this? 3.I wants to add a property to the user control which allows the user to select a color. When the user selects this property, it must display the same options which are displayed for selecting the color for the satndard properties like 'BackColor'. Then the user must be able to select the required color from these options & the value must be stored in that specific property. Kindly help me to acheieve the above scenarios Best Regards, Abhilash Chandran
hi, well it seems that you have partly solved question 1. you could also use the attribute: [Browsable(false)] on the properties that you don't wan't to show. i don't know how to remove the property completely, but you could override the existing property and disable the set part. question 2 : don't know:( question3: you can add new properties that you want with the right data type if you wanted to set the 'BackColor' property you could do: [Browsable(true)] public override Color BackColor { get{return this.bkColor;/*or base.BackColor; or any color*/} set{this.bkColor=value;/*or base.BackColor=value; or what ever ...*/} } hope this helps
regards :)
-
Dear All, I am making a Windows Control Library(user control) using VS.NET & C#.NET. Now, i am facing 3 problems: 1.In this control, i wants to remove some of the properties which are available by default to the controls. These properties must be removed from the 'Properties window' of the usercontrol. Also the user must not be able to set these properties using code. I am able to remove the properties from the 'Properties window' by inheriting a class from the System.Windows.Forms.Design.ScrollableControlDesigner & removing the properties by overriding the PreFilterProperties function as show below: protected override void PreFilterProperties(System.Collections.IDictionary properties) { properties.Remove("BackColor"); } But, doing so, this property is available to be set from the code. How can i remove this property fully? 2.I wants to create a property for the control which has sub properties, like the 'Location' property of a button, which has sub properties as 'X, Y & Locked'. My new property for the control must have some subproperties like this. How can i achieve this? 3.I wants to add a property to the user control which allows the user to select a color. When the user selects this property, it must display the same options which are displayed for selecting the color for the satndard properties like 'BackColor'. Then the user must be able to select the required color from these options & the value must be stored in that specific property. Kindly help me to acheieve the above scenarios Best Regards, Abhilash Chandran
hi again, for question 2: have a look at : http://www.thescripts.com/forum/thread576786.html[^]
regards :)
-
hi, well it seems that you have partly solved question 1. you could also use the attribute: [Browsable(false)] on the properties that you don't wan't to show. i don't know how to remove the property completely, but you could override the existing property and disable the set part. question 2 : don't know:( question3: you can add new properties that you want with the right data type if you wanted to set the 'BackColor' property you could do: [Browsable(true)] public override Color BackColor { get{return this.bkColor;/*or base.BackColor; or any color*/} set{this.bkColor=value;/*or base.BackColor=value; or what ever ...*/} } hope this helps
regards :)
Hi. thank you for the information. i will try that.. But the 3rd requirement is slightly different than wht u have mentioned. I will make it more clear. For eg: i am making a user control. I adds a property called MyColor to it, which accepts a color as the value. Now, when i uses this control in allications, the properties window for the control displays the MyColor property When the user clicks to select the value for the myColor prperty, the color pallate must be prompted to the user from where he can select the color, like the color pallates displayed to select the color for BackColor property. is there any method to achieve it. Kindly help me Best Regards, Abhilash Chandran
-
Hi. thank you for the information. i will try that.. But the 3rd requirement is slightly different than wht u have mentioned. I will make it more clear. For eg: i am making a user control. I adds a property called MyColor to it, which accepts a color as the value. Now, when i uses this control in allications, the properties window for the control displays the MyColor property When the user clicks to select the value for the myColor prperty, the color pallate must be prompted to the user from where he can select the color, like the color pallates displayed to select the color for BackColor property. is there any method to achieve it. Kindly help me Best Regards, Abhilash Chandran
hi, so, it seems that you want to create your own property. it isn't that hard. try this:
private Color _myColor;/*this will be your private member to store the color*/ [Browsable(true),Description("This property will set myColor")]/*this is not required*/ public Color MyColor { get{return _myColor;} set { _myColor=value; this.Invalidate();/*this causes the control to repaint so new changes are visible right away*/ } }
if you do this, you will have access to _myColor and when used in VS, the property tab will display the color that the user can select from. hope this helpsregards :)