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.
Is it because I am using it in the 'onpaint' event?Code:Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.TitleText = "New" End Sub




Reply With Quote