Results 1 to 14 of 14

Thread: Multi Item Property

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Location
    Reading, UK
    Posts
    192

    Multi Item Property

    Hi there

    Id like to know you create a property Group for forms and user controls. just like you would get for size, margin, padding etc

    my aim (for now at least) is to be able have a borders property consisting of left, right, top,bottom. All values would be an Integer.

    I could just create 4 single properties but id would much prefer to group them under like borders or something.
    Ive had a bit of a look around and i think i have to create a class with the properties set within that class and then set the property on the object as that class.
    any way ive tried all that and i can't get it to come out on my form properties at all, worse than that when i just added a new one to the form the properties window was blank and visual studio crashed :/

    Even If I'm missing some fundamentally much easier way to achieve my goal of the borders, I'd still like to know how to do the property group as it'll probably come in handy

    please note value are currently in boolean as that was the original idea but writing this i decided that integer would give me much more functionality in fact i might even go for palet color and default it to transparent or something who knows

    any way here is my class

    Code:
    Public Class ClsPnlBorders
        Private mRight As Boolean
        Public Property Right As Boolean
            Get
                Return mRight
            End Get
            Set(value As Boolean)
                mRight = value
                RaiseEvent BordersChanged()
            End Set
        End Property
        Private mLeft As Boolean
        Public Property Left As Boolean
            Get
                Return mLeft
            End Get
            Set(value As Boolean)
                mLeft = value
                RaiseEvent BordersChanged()
            End Set
        End Property
        Private mTop As Boolean
        Public Property Top As Boolean
            Get
                Return mTop
            End Get
            Set(value As Boolean)
                mTop = value
                RaiseEvent BordersChanged()
            End Set
        End Property
        Private mBottom As Boolean
        Public Property Bottom As Boolean
            Get
                Return mBottom
            End Get
            Set(value As Boolean)
                mBottom = value
                RaiseEvent BordersChanged()
            End Set
        End Property
        Public Sub New(right As Boolean, left As Boolean, top As Boolean, bottom As Boolean)
            mRight = right
            mLeft = left
            mTop = top
            mBottom = bottom
        End Sub
        Public Event BordersChanged()
    
    End Class
    and my usage

    Code:
    Private mBorders() As ClsPnlBorders
        <TypeConverter(GetType(ExpandableObjectConverter)), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
        Public Property Borders() As ClsPnlBorders
            Get
                Return mBorders(0)
            End Get
            Set(value As ClsPnlBorders)
                mBorders(0) = value
            End Set
    End Property

    many thanks

    Ian

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Multi Item Property

    Why you declare as array?

    vb Code:
    1. Private mBorders As ClsPnlBorders
    2.     <TypeConverter(GetType(ExpandableObjectConverter)), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
    3.     Public Property Borders() As ClsPnlBorders
    4.         Get
    5.             Return mBorders
    6.         End Get
    7.         Set(value As ClsPnlBorders)
    8.             mBorders = value
    9.         End Set
    10. End Property

    BTW: .NET has System.Drawing.Rectangle try to use it.



  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Location
    Reading, UK
    Posts
    192

    Re: Multi Item Property

    hi 4x2y

    thanks for the reply,

    I Tried using a rectangle but i could get it to only show the sides that i wanted it right, top, bottom or left, it was either on or of

    And im not sure why i declared it as an array to be honest, i was trying to follow what someone else had done from in this post
    http://www.vbforums.com/showthread.p...oup-Attributes

    but i couldn't get it work, its a bit annoying because i can see it as i wold expect it. if i call it in the code but it doesn't appear in the properties window

    Ian

  4. #4
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Multi Item Property

    There is already a type for specifying borders. The ToolStripStatusLabelBorderSides enumeration type. It also has nice designer support where you can specify them with CheckBoxes in the property grid at design time:-
    vbnet Code:
    1. Public Class Test
    2.     Inherits Component
    3.  
    4.     Public Property Borders As ToolStripStatusLabelBorderSides
    5.  
    6. End Class

    All you need to do is have the property declared as ToolStripStatusLabelBorderSides and VS does the rest.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  5. #5
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Multi Item Property

    As i understood, he wants to add his custom property Borders to a form and see/set it inside the form's properties window at design time.



  6. #6
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Multi Item Property

    He can inherit from Form and add the property if he wants.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  7. #7
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Multi Item Property

    He can inherit from Form and add the property if he wants.
    Can you please post a sample, because i did so but cannot see it in the form's properties window at design time.



  8. #8
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Multi Item Property

    vbnet Code:
    1. Public Class SpecialForm
    2.     Inherits Form
    3.  
    4.     Public Property MyBorders As ToolStripStatusLabelBorderSides
    5. End Class

    Name:  PropertyForForm.png
Views: 156
Size:  22.8 KB
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  9. #9
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Multi Item Property

    When i create a class with this code
    Code:
    Public Class SpecialForm
        Inherits Form
     
        Public Property MyBorders As ToolStripStatusLabelBorderSides
    End Class
    i don't see MyBorders in the properties window.

    I see only if i add another class and inherit SpecialForm

    Code:
    Public Class Class2
        Inherits WindowsApplication1.SpecialForm
    
    End Class



  10. #10
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Multi Item Property

    Quote Originally Posted by 4x2y View Post
    I see only if i add another class and inherit SpecialForm

    Code:
    Public Class Class2
        Inherits WindowsApplication1.SpecialForm
    
    End Class
    Right, that's exactly what you're supposed to do. You simply edit the designer generated file for your application's forms and have it inherit from your new form class instead of the default System.Windows.Forms.Form.

    Name:  InheritYourForms.png
Views: 156
Size:  30.5 KB
    Last edited by Niya; May 14th, 2013 at 08:43 AM. Reason: Fixed attachment
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  11. #11
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Multi Item Property

    You simply edit the designer generated file for your application's forms and have it inherit from your new form class instead of the default System.Windows.Forms.Form.
    I think it was important to describe this step, because i knew it only from your properties window screen shoot, as it show the class name Form1 WindowsApllication1.SpecialForm

    Attachment 100091 is Invalid Attachment.



  12. #12
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Multi Item Property

    Quote Originally Posted by 4x2y View Post
    I think it was important to describe this step.
    Sorry about that. I assumed it was common knowledge. I use all kinds of inherited forms all the time.

    Quote Originally Posted by 4x2y View Post
    Attachment 100091 is Invalid Attachment.
    Fixed...
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Location
    Reading, UK
    Posts
    192

    Re: Multi Item Property

    Wow Thanks alot guys thats brill

    the problem is this is more for user controls rather than forms

    I want to use this mainly in my version of the Panel, The Idea being that i could choose what sort of a border that wanted in the panel. can i use the Inherits WindowsApplication.SpecialForm When im already inheriting the base class of the Panel?

    but i would imagine it would be of use in all sorts of places.

    Lastly Whilst the suggestion for the borders is very good, Id still like to know how to create my own Multi Item Properties. it may be that it is more trouble than its worth but if it is possible it would be great to know

    Ian

  14. #14
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Multi Item Property

    Quote Originally Posted by 12many View Post
    Lastly Whilst the suggestion for the borders is very good, Id still like to know how to create my own Multi Item Properties. it may be that it is more trouble than its worth but if it is possible it would be great to know

    Ian
    vbnet Code:
    1. Imports System.ComponentModel
    2.  
    3. Public Class BorderedPanel
    4.     Inherits Panel
    5.  
    6.     Public Sub New()
    7.         Me.Borders = New BorderSides
    8.     End Sub
    9.  
    10.     <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
    11.     Public Property Borders As BorderSides
    12.  
    13. End Class
    14.  
    15.  
    16. <TypeConverter(GetType(BorderSidesConverter))> _
    17. Public Class BorderSides
    18.     Public Property Left As Boolean
    19.     Public Property Top As Boolean
    20.     Public Property Right As Boolean
    21.     Public Property Bottom As Boolean
    22. End Class
    23.  
    24. Public Class BorderSidesConverter
    25.     Inherits ExpandableObjectConverter
    26.  
    27.     Public Overrides Function CanConvertTo(context As System.ComponentModel.ITypeDescriptorContext, destinationType As System.Type) As Boolean
    28.         If GetType(String) Is destinationType Then Return True
    29.  
    30.         Return MyBase.CanConvertTo(context, destinationType)
    31.     End Function
    32.  
    33.     Public Overrides Function ConvertTo(context As System.ComponentModel.ITypeDescriptorContext, culture As System.Globalization.CultureInfo, value As Object, destinationType As System.Type) As Object
    34.         If GetType(String) Is destinationType Then Return ""
    35.  
    36.         Return MyBase.ConvertTo(context, culture, value, destinationType)
    37.     End Function
    38.  
    39. End Class
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width