Results 1 to 7 of 7

Thread: Global Properties (or whatever!)

  1. #1
    Geysser is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Apr 2010
    Posts
    17
    Reputation
    41

    Global Properties (or whatever!)

    Here is a thing I've been confused about for a long time now.
    I'm creating a package full of custom controls and one thing that I've being really frustrated about is that I have to write the same properties over and over again, in each one of these controls. You see, each control has more or less the same properties to customize its appearance - gradients, glass effects, etc.
    Is there a way to somehow share all these properties between controls? One way I thought was to create a "basis" control for all the other to inherit from, but something tells me that this is not the right way-plus, this control would be compiled in the toolbox, which I don't want. Any ideas?

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,225
    Reputation
    2370
    Base control and inheritance seems like a good idea, you can hide the base class from Toolbox like this:
    Code:
    <System.ComponentModel.ToolboxItem(False)> _
    Public MustInherit Class MyControlBase
        Inherits Control
        Public Property ID As Integer
    End Class
    
    <System.ComponentModel.ToolboxItem(True)> _
    Public Class MyControl
        Inherits MyControlBase
    
    End Class
    ToolboxItemAttribute Class (System.ComponentModel)

  3. #3
    Geysser is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Apr 2010
    Posts
    17
    Reputation
    41
    Thanks very much for the advice! I'm gonna try it right away! But there is one small detail: The Public Property ID what is it for?

  4. #4
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,225
    Reputation
    2370
    The Public Property ID what is it for?
    Just a sample base property VB 2010 has Auto-Implemented Properties (Visual Basic)

  5. #5
    Geysser is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Apr 2010
    Posts
    17
    Reputation
    41
    VB 2008 on my side! I tried 2010 but for some reason the IDE is very unstable (crashes all the time)!

    One last thing, if it's not too much trouble! Overriding the OnPaint in my control doesn't do jack, i.e, my control doesn't paint! I tried in both the control and the base control, still nada.Any advice?

    Code:
    'A Label Control with graphical effects
    Imports System.Drawing
    Imports System.Drawing.Drawing2D
    Imports System.ComponentModel
    
    <ToolboxItem(True)> _
    Public Class GLabel
      Inherits BaseControl
    
    #Region "Painting"
      Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(e)
        'Painting the control
        Dim rc As New Rectangle(0, 0, Width - 1, Height - 1)
        'Paint the border
        PaintBorder(e.Graphics, rc, BorderColor, BorderStyle, BorderSides)
      End Sub
    #End Region
    End Class
    The BorderStyle is Enum, the BorderSides is a structure (will write the UITypeConverter later)


    EDIT: Sorry, I;ve got it! Haven't initialize the structure in the designer! My bad!

  6. #6
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,225
    Reputation
    2370
    I tried 2010 but for some reason the IDE is very unstable (crashes all the time)!
    I've used it a lot since release in April, haven't had a single crash.

  7. #7
    Geysser is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Apr 2010
    Posts
    17
    Reputation
    41
    Maybe it's me then! Anyway, I really appreciate your help!

Bookmarks

Posting Permissions

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