Global Properties (or whatever!)

Geysser

Member
Joined
Apr 6, 2010
Messages
17
Programming Experience
5-10
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?
 
Base control and inheritance seems like a good idea, you can hide the base class from Toolbox like this:
VB.NET:
<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)
 
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?
 
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?

VB.NET:
'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!
 
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.
 
Back
Top