|
-
Oct 2nd, 2008, 07:44 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] [2008] property grayed out.
I am trying to create a "base" form from which all my forms will inherit from.
I am trying to put a logo (taken from the internet) and a text on the form.
The text called "formTitleText". I think i know where I am making the mistake.
vb.net Code:
Imports System.Drawing.Drawing2D
Public Class BaseFormClass
Inherits System.Windows.Forms.Form
Private _formTitleText As String
Public Property TitleText()
Get
Return _formTitleText
End Get
Set(ByVal value)
_formTitleText = value
End Set
End Property
Public Sub New()
MyBase.New()
Me.Text = "Cool, inherited form"
Me.BackColor = Color.White
If String.IsNullOrEmpty(_formTitleText) Then
_formTitleText = "####"
End If
End Sub
Public Sub New(ByVal formTitleText As String)
MyBase.New()
Me.Text = "Cool, inherited form"
Me.BackColor = Color.White
If String.IsNullOrEmpty(_formTitleText) Then
_formTitleText = "####"
Else
_formTitleText = formTitleText
End If
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
'MyBase.OnPaint(e)
Dim fnt As New Font("Verdana", 16)
g.DrawString(_formTitleText, fnt, New SolidBrush(Color.Red), 14, 10)
End Sub
End Class
When I build the project, and use it in my main form (which I changed by showing the designer file and inheriting my class) the property, though it shows up, is grayed out and I cant change it.
However, I can change it on the onload event.
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TitleText = "New"
End Sub
Is it because I am using it in the 'onpaint' event?
Last edited by masfenix; Oct 2nd, 2008 at 07:55 PM.
-
Oct 2nd, 2008, 08:16 PM
#2
Re: [2008] property grayed out.
First up, I'm a stickler for terminology. There are no OnLoad or OnPaint events. The OnLoad method raises the Load event. The OnPaint method raises the Paint event. Anything beginning with "On" will be a method. Remove the "On" and that's the name of the event. Notice that your OnPaint member has "Sub" in the declaration, not "Event".
Apart from that, that code won't even compile so I don't really see how you can have tested it as is. There's an error and two warnings, so I would think that they should be addressed before asking what might be causing any other issues.
You also must have Option String Off because you haven't specified a type for your TitleText property. That's the reason that your property is greyed out in the derived class and, if you had Option Strict turned On, it would have notified you of the issue and forced you to fix it. No self-respecting VB.NET developer should work with Option Strict Off.
Finally, if you want to inherit a form then add an Inherited Form to your project instead of a Windows Form.
-
Oct 2nd, 2008, 08:26 PM
#3
Thread Starter
Fanatic Member
Re: [2008] property grayed out.
Hey Thankyou,
After googling it, I realized I had to add a "inherited form" but manually worked as well (possibly because its so simple right now)..
The setting the type as string worked perfectly, will take notice from now on and add option strict all the time.
However, I am confused about the errors. I have 0 errors, and able to compile and run.
Do you mind telling me the errors so i can see why its not working for you.
I mena its just a simple class.. one constructor, one overrideable method and a property :P
Edit: Oh you might be getting an error in the onpaint method. Because in the code I posted "g" isnt declared, however, I left out a few things from the method to save you from reading unneccesary code.
I am positive thats it :P
-
Oct 2nd, 2008, 08:43 PM
#4
Re: [2008] property grayed out.
 Originally Posted by masfenix
Edit: Oh you might be getting an error in the onpaint method. Because in the code I posted "g" isnt declared, however, I left out a few things from the method to save you from reading unneccesary code.
I am positive thats it :P
That's it alright. You also get warnings on the constructors IF you add a Windows Form to your project, which I did, but NOT if you add a Class to your project, which I'm guessing you did.
You can turn Option Strict On for the current project on the Compile tab of the project properties. To make it the default for all future projects open the IDE Options dialogue and go to Projects & Solutions -> VB Defaults.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|