Few questions
-
I am developing a Custom Control and I will ask question from several categories. I appreciate your answers 1st question: How can I create a class to be used like XmlNode. XmlNode can be XmlElement or other types. I wan't to use similar approach. I need it, because I want draw other type of controls within one control. Example: Display a Group box with a picture and a button as an item in TreeView 2nd Question: My Control is Inherits Control class. How can I hide some properties and/or change its description. Thank you for your time.
-
I am developing a Custom Control and I will ask question from several categories. I appreciate your answers 1st question: How can I create a class to be used like XmlNode. XmlNode can be XmlElement or other types. I wan't to use similar approach. I need it, because I want draw other type of controls within one control. Example: Display a Group box with a picture and a button as an item in TreeView 2nd Question: My Control is Inherits Control class. How can I hide some properties and/or change its description. Thank you for your time.
Saksida Bojan wrote:
1st question: How can I create a class to be used like XmlNode. XmlNode can be XmlElement or other types. I want to use similar approach. I need it, because I want draw other type of controls within one control.
Okay, well then create a simple interface for your object and have a toString method that can convert it to the correct output. Look at the XML classes and interfaces, they all share a common.
Saksida Bojan wrote:
Example: Display a Group box with a picture and a button as an item in TreeView
This is more complex. You would have to use some kind of logic to display the node as such. HTML/WPF/SilverLight/WinForms all do it differently. Look for some examples on: Creating User Controls.
Saksida Bojan wrote:
2nd Question: My Control is Inherits Control class. How can I hide some properties and/or change its description.
In the designer. All properties are visible. You can change them there, there will be somethings you can't hide or change depending on the inheritance of the object/control. Question: What are you creating the control in? WPF?
-
Saksida Bojan wrote:
1st question: How can I create a class to be used like XmlNode. XmlNode can be XmlElement or other types. I want to use similar approach. I need it, because I want draw other type of controls within one control.
Okay, well then create a simple interface for your object and have a toString method that can convert it to the correct output. Look at the XML classes and interfaces, they all share a common.
Saksida Bojan wrote:
Example: Display a Group box with a picture and a button as an item in TreeView
This is more complex. You would have to use some kind of logic to display the node as such. HTML/WPF/SilverLight/WinForms all do it differently. Look for some examples on: Creating User Controls.
Saksida Bojan wrote:
2nd Question: My Control is Inherits Control class. How can I hide some properties and/or change its description.
In the designer. All properties are visible. You can change them there, there will be somethings you can't hide or change depending on the inheritance of the object/control. Question: What are you creating the control in? WPF?
TheArchitectmc∞ wrote:
Okay, well then create a simple interface for your object and have a toString method that can convert it to the correct output. Look at the XML classes and interfaces, they all share a common.
Will look at it. If I coudn't use, then I would use Object, but I would rather avoid Object
TheArchitectmc∞ wrote:
This is more complex. You would have to use some kind of logic to display the node as such. HTML/WPF/SilverLight/WinForms all do it differently.
I have already thought on how to handle it
TheArchitectmc∞ wrote:
Look for some examples on: Creating User Controls.
I have read a Book about creating Custom control, however i need data layer that behaves like XmlNode. I will look at the interface.
TheArchitectmc∞ wrote:
Question: What are you creating the control in? WPF?
I am desinging for windows form
-
TheArchitectmc∞ wrote:
Okay, well then create a simple interface for your object and have a toString method that can convert it to the correct output. Look at the XML classes and interfaces, they all share a common.
Will look at it. If I coudn't use, then I would use Object, but I would rather avoid Object
TheArchitectmc∞ wrote:
This is more complex. You would have to use some kind of logic to display the node as such. HTML/WPF/SilverLight/WinForms all do it differently.
I have already thought on how to handle it
TheArchitectmc∞ wrote:
Look for some examples on: Creating User Controls.
I have read a Book about creating Custom control, however i need data layer that behaves like XmlNode. I will look at the interface.
TheArchitectmc∞ wrote:
Question: What are you creating the control in? WPF?
I am desinging for windows form
Saksida Bojan wrote:
I am desinging for windows form
Okay if you are designing for windows forms, then this has sort of been done for you in the WPF implementation of Windows Forms. Create a WPF application, add WinForms to the project, it appears as a button in the widget box.
Saksida Bojan wrote:
I have read a Book about creating Custom control, however i need data layer that behaves like XmlNode. I will look at the interface.
There are many way of representing data as an XML node. Many converrters in the .NET runtime. Take a look at LINQ to SQL, LINQ to XML, and LINQ to Objects. There are ways to easily use SQL as XML, Object as XML.
Saksida Bojan wrote:
Will look at it. If I coudn't use, then I would use Object, but I would rather avoid Object
Another approach to to directly inherit from XMLNode or what ever works for you. I would make sure that it is a basic enough object which can also be used in other assemblies in the .NET runtime.
-
I am developing a Custom Control and I will ask question from several categories. I appreciate your answers 1st question: How can I create a class to be used like XmlNode. XmlNode can be XmlElement or other types. I wan't to use similar approach. I need it, because I want draw other type of controls within one control. Example: Display a Group box with a picture and a button as an item in TreeView 2nd Question: My Control is Inherits Control class. How can I hide some properties and/or change its description. Thank you for your time.
1. You can either use an interface or an abstract class depending on what suits your needs best. 2. This is possible by creating new properties the same as the old and applying certain attributes (overriding instead of
new
may work - I seem to recall having problems that way). The control will need to be compiled to a separate assembly, if in the same assembly as the project, or in a referenced project then the attributes will have no effect!public class MyControl : Control
{
[Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
EditorBrowsable(EditorBrowsableState.Never),
ObsoleteAttribute("This property is not valid for this control")]
public new string Text
{
get { return base.Text; }
set { base.Text = value; }
}
}This isn't foolproof though as the end user can always treat your control as
Control
and have access to all the stuff thatControl
has. It's also against OOP priciples to inherit stuff you don't want, but in the case ofControl
there isn't much option and even MS themselves do it!Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
1. You can either use an interface or an abstract class depending on what suits your needs best. 2. This is possible by creating new properties the same as the old and applying certain attributes (overriding instead of
new
may work - I seem to recall having problems that way). The control will need to be compiled to a separate assembly, if in the same assembly as the project, or in a referenced project then the attributes will have no effect!public class MyControl : Control
{
[Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
EditorBrowsable(EditorBrowsableState.Never),
ObsoleteAttribute("This property is not valid for this control")]
public new string Text
{
get { return base.Text; }
set { base.Text = value; }
}
}This isn't foolproof though as the end user can always treat your control as
Control
and have access to all the stuff thatControl
has. It's also against OOP priciples to inherit stuff you don't want, but in the case ofControl
there isn't much option and even MS themselves do it!Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus)thanks for info. Gonna need to look into abstract, because i do not know what it is.
-
thanks for info. Gonna need to look into abstract, because i do not know what it is.
An abstract class is a bottom level class in the class hierarchy which can not be instantiated. So if you are using inheritance you won't be able to use abstract classes. The attributes solution is a good hack to keep the user from using something you don't want them to use.