Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Few questions

Few questions

Scheduled Pinned Locked Moved C#
questiontutorial
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Saksida Bojan
    wrote on last edited by
    #1

    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.

    L D 2 Replies Last reply
    0
    • S Saksida Bojan

      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.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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?

      S 1 Reply Last reply
      0
      • L Lost User

        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?

        S Offline
        S Offline
        Saksida Bojan
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • S Saksida Bojan

          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

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • S Saksida Bojan

            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.

            D Offline
            D Offline
            DaveyM69
            wrote on last edited by
            #5

            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 that Control has. It's also against OOP priciples to inherit stuff you don't want, but in the case of Control 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)

            S 1 Reply Last reply
            0
            • D DaveyM69

              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 that Control has. It's also against OOP priciples to inherit stuff you don't want, but in the case of Control 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)

              S Offline
              S Offline
              Saksida Bojan
              wrote on last edited by
              #6

              thanks for info. Gonna need to look into abstract, because i do not know what it is.

              L 1 Reply Last reply
              0
              • S Saksida Bojan

                thanks for info. Gonna need to look into abstract, because i do not know what it is.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups