How to Override the TEXT property of a CLASS? Anyone please?
-
Tuesday, December 04, 2007 11:50 AM
Hi to the experts,
I have built a CLASS called CustomMsgBox with a vertical scrollbar on the RichTextBox and I want to
OVERRIDE ( or will it be SHADOW ? )
the TEXT property so that any text is written and read from the rtb RichTextBox.
Additionally I always want this CustomMsgBox to open in the Center ( or Centre ) of the screen.
Unfortunately I can not Inherit from MessageBox as it has not got an accessible NEW SUB.
If it has a PRIVATE NEW Sub can it be overridden?
Does CLOSE also call DISPOSE?
Please help.
This is what i have so far.
Thanks, in advance, for any help.
Regards,
John
Code BlockOption
Strict OnPublic
Class Form1Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cMsgBox As New CustomMsgBox
cMsgBox.Show()
End Sub
End Class
My CLASS code.
Code BlockPublic
Class CustomMsgBoxInherits System.Windows.Forms.Form
Friend WithEvents btn As New Windows.Forms.Button
Friend WithEvents rtb As New Windows.Forms.RichTextBox
Public Sub New()
Me.ControlBox = False
Dim aPoint As Point Me.Width = 450 Me.Height = My.Computer.Screen.WorkingArea.HeightaPoint.X = 300
aPoint.Y = 0
Me.Location = aPointaPoint.X = 5
aPoint.Y = 5
rtb.Location = aPoint
rtb.Width =
Me.Width - 20rtb.Height =
Me.Height - 120rtb.ScrollBars = RichTextBoxScrollBars.Vertical
Me.Controls.Add(rtb)btn.Width = 50
btn.Height = 20
aPoint.X = (
Me.Width \ 2) - (btn.Width \ 2)aPoint.Y =
Me.Height - 100btn.Location = aPoint
btn.Text =
"OK" Me.Controls.Add(btn) Me.Text = "Output message." End SubPrivate Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn.Click
Me.Close()
End Sub
'Public Property Text() As String 'Get 'Return rtb.Text 'End Get 'Set(ByVal value As String) 'rtb.Text = value 'End Set 'End PropertyEnd
Class
All Replies
-
Tuesday, December 04, 2007 12:18 PM
John Oliver (UK)MSP, VSIP wrote: I have built a CLASS called CustomMsgBox with a vertical scrollbar on the RichTextBox and I want to
OVERRIDE ( or will it be SHADOW ? )
the TEXT property so that any text is written and read from the rtb RichTextBox.
You can override the Text property, it's virtual.
John Oliver (UK)MSP, VSIP wrote: Additionally I always want this CustomMsgBox to open in the Center ( or Centre ) of the screen.
Code BlockMe.StartPosition = FormStartPosition.CenterScreen
John Oliver (UK)MSP, VSIP wrote: Unfortunately I can not Inherit from MessageBox as it has not got an accessible NEW SUB.
If it has a PRIVATE NEW Sub can it be overridden?
No.
John Oliver (UK)MSP, VSIP wrote: Does CLOSE also call DISPOSE?
Let that be the problem of the GC. You don't need to call Dispose explicitly.
--
Regards,
Daniel Kuppitz
-
Tuesday, December 04, 2007 12:28 PM
Daniel Kuppitz wrote: You can override the Text property, it's virtual.
Regards,
Daniel Kuppitz
Hi Daniel,
Thanks for your post but I want to know how to override the the text property as well please.
Thanks for the other answers by the way.
What do you mean by GC please?
Regards,
John.
-
Tuesday, December 04, 2007 12:54 PMEnd Property
John Oliver (UK)MSP, VSIP wrote: Thanks for your post but I want to know how to override the the text property as well please.
End SetCode BlockPublic Overrides Property Text() As String
Get
Return Me.rtb.TextEnd Get
Set(ByVal value As String)
Me.rtb.Text = value
| John Oliver (UK)MSP, VSIP wrote: | |
|
GC = Garbage Collector
The Form base class will trigger all the relevant Dispose stuff.
--
Regards,
Daniel Kuppitz

