Results 1 to 4 of 4

Thread: [RESOLVED] [2008] property grayed out.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    Resolved [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:
    1. Imports System.Drawing.Drawing2D
    2.  
    3. Public Class BaseFormClass
    4.     Inherits System.Windows.Forms.Form
    5.     Private _formTitleText As String
    6.  
    7.     Public Property TitleText()
    8.         Get
    9.             Return _formTitleText
    10.         End Get
    11.         Set(ByVal value)
    12.             _formTitleText = value
    13.         End Set
    14.     End Property
    15.  
    16.     Public Sub New()
    17.         MyBase.New()
    18.         Me.Text = "Cool, inherited form"
    19.         Me.BackColor = Color.White
    20.         If String.IsNullOrEmpty(_formTitleText) Then
    21.             _formTitleText = "####"
    22.         End If
    23.     End Sub
    24.  
    25.     Public Sub New(ByVal formTitleText As String)
    26.         MyBase.New()
    27.         Me.Text = "Cool, inherited form"
    28.         Me.BackColor = Color.White
    29.         If String.IsNullOrEmpty(_formTitleText) Then
    30.             _formTitleText = "####"
    31.         Else
    32.             _formTitleText = formTitleText
    33.         End If
    34.     End Sub
    35.  
    36.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
    37.         'MyBase.OnPaint(e)
    38.         Dim fnt As New Font("Verdana", 16)
    39.         g.DrawString(_formTitleText, fnt, New SolidBrush(Color.Red), 14, 10)
    40.  
    41.     End Sub
    42.  
    43.  
    44. 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?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    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

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] property grayed out.

    Quote 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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