Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Project components/vfp visual classes
Message
From
14/11/2007 12:19:47
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01268726
Message ID:
01268923
Views:
16
Thanks Glenn, that will make it easier for Vince. I usually use the Convert sites, but there are certain things that they don't always convert correctly ... I thought this might be one thing that doesn't convert well, so I didn't even bother to try. My bad. I guess I should have! <g>

~~Bonnie




>Hi Bonnie,
>
>I was able to convert your C# to VB.Net using one of the Convert sites on the Web.
>
>Here is the equivalent VB.Net code:
>
>Imports Microsoft.VisualBasic
>Imports System.ComponentModel
>
>Public Class MyTextBox
>    Inherits TextBox
>
>    Private m_MyProperty As String
>
>    <DefaultValue("")> _
>    Public Property MyProperty() As String
>        Get
>            Return Me.m_MyProperty
>        End Get
>        Set(ByVal value As String)
>            Me.m_MyProperty = value
>        End Set
>    End Property
>
>    <DefaultValue(GetType(System.Drawing.Color), "90,100,240")> _
>    Public Overrides Property BackColor() As System.Drawing.Color
>        Get
>            Return MyBase.BackColor
>        End Get
>        Set(ByVal value As System.Drawing.Color)
>            MyBase.BackColor = value
>        End Set
>    End Property
>
>    <DefaultValue(GetType(System.Drawing.Color), "Firebrick")> _
>    Public Overrides Property ForeColor() As System.Drawing.Color
>        Get
>            Return MyBase.ForeColor
>        End Get
>        Set(ByVal value As System.Drawing.Color)
>            MyBase.ForeColor = value
>        End Set
>    End Property
>End Class
>
>
>Glenn
>>Vince,
>>
>>The key is to use the DefaultValue attribute for the ForeColor and Font properties. Unfortunately, I don't know VB, so I'm not sure what the syntax would be (or if it's even *called* DefaultValue in VB). But here's a blurb I wrote some time ago that explains the gist of it in C#:
>>
>>You need code in two places: in the Constructor to set the value to begin with,
>>and a DefaultValue attribute for the Property itself:
>>
>>
>>public class MyTextBox : TextBox
>>{
>>    private string m_MyProperty;
>>
>>    public MyTextBox
>>    {
>>        this.m_MyProperty = "";
>>
>>        // As an additional bonus, I'm showing you two ways to do color
>>	this.BackColor = System.Drawing.Color.FromArgb(90, 100, 240);
>>	this.ForeColor = System.Drawing.Color.Firebrick; ;
>>    }
>>
>>        [DefaultValue("")]
>>        public string MyProperty
>>        {
>>            get {return this.m_MyProperty;}
>>            set {this.m_MyProperty = value;}
>>        }
>>	[DefaultValue(typeof(System.Drawing.Color), "90,100,240")]
>>	public override System.Drawing.Color BackColor
>>	{
>>		get
>>		{
>>			return base.BackColor;
>>		}
>>		set
>>		{
>>			base.BackColor = value;
>>		}
>>	}
>>	[DefaultValue(typeof(System.Drawing.Color), "Firebrick")]
>>	public override System.Drawing.Color ForeColor
>>	{
>>		get
>>		{
>>			return base.ForeColor;
>>		}
>>		set
>>		{
>>			base.ForeColor = value;
>>		}
>>	}
>>}
>>
>>
>>Setting some of these properties doesn't always work as you would expect
>>them to ... one that comes to mind is "Text" ... you may or may not have
>>problems setting a default for that one, depending on which control you're
>>sub-classing.
>>
>>Also, some properties aren't virtual and can't be overridden. For
>>those properties, you can use "new" instead of "override".
>>
>>Hope that helps ... sorry for the C# example. =0(
>>
>>~~Bonnie
>>
>>
>>
>>
>>>Greetings all
>>>I am attempting to duplicate visual classes in vb.net. Currently, I am creating a class in a name space:
>>>
>>>Namespace frwFormObjects
>>>    Public Class clsLblFieldDesc
>>>        Inherits System.Windows.Forms.Label
>>>        Public Sub New()
>>>            Me.ForeColor = Color.CadetBlue
>>>            Me.Font = New Font("Arial", 10, FontStyle.Bold)
>>>        End Sub
>>>    End Class
>>>
>>>    Public Class clsTxtBox
>>>        Inherits System.Windows.Forms.TextBox
>>>        Public Sub New()
>>>            Me.ForeColor = Color.CadetBlue
>>>            Me.Font = New Font("Arial", 15, FontStyle.Bold)
>>>        End Sub
>>>    End Class
>>>End Namespace
>>>
>>>When the system is rebuilt, the classes show up in the project components tool box. I can drag the component on the form where all the properties come along for the ride. The properties overstay there welcome however, the properties for those objects also show up in the code.
>>>
>>>        'txtLastName
>>>        '
>>>        Me.txtLastName.Font = New System.Drawing.Font("Arial", 11.0!, System.Drawing.FontStyle.Bold)
>>>        Me.txtLastName.ForeColor = System.Drawing.Color.CadetBlue
>>>        Me.txtLastName.Location = New System.Drawing.Point(98, 45)
>>>        Me.txtLastName.Name = "txtLastName"
>>>        Me.txtLastName.Size = New System.Drawing.Size(100, 24)
>>>        Me.txtLastName.TabIndex = 3
>>>        '
>>>
>>>Therefore, if I change a property in one of the above classes in namespace frwFormObjects, the change does not manifest on existing form objects after the rebuild because the form code overrides the properties of the class. I could delete all the code, but there must be a better way. How can I keep the code out of the form and have existing form objects inherit from the component after dragging the component out on the form.
>>>
>>>Thanks, Vince
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform