Probably Simple Text Property Problem

T

Tom

Hi

I have a usercontrol that inherits from
System.Windows.Forms.Usercontrol. As the Text property is not visable
in the IDE by default i am shadowing the property because i want ot
use it on the control.

This works fine and within the IDE i can set the text property,
however whenever i build the control this property is set to an empty
string, and i don't know why.

<code>

Option Strict On

Imports System.ComponentModel

Public Class ContextButton
Inherits System.Windows.Forms.UserControl

Dim mText As String
<Browsable(True)> _
Public Shadows Property Text() As String
Get
Return mText
End Get
Set(ByVal Value As String)
mText = Value
Invalidate()
End Set
End Property

Private Sub ContextButton_Paint(ByVal sender As Object, ByVal e As
PaintEventArgs) Handles MyBase.Paint

'get the text position
Dim TextSize As SizeF = e.Graphics.MeasureString(mText,
SystemInformation.MenuFont)
Dim TextPos As PointF
TextPos.X = ((Width - CInt(TextSize.Width)) \ 2) + 1
TextPos.Y = ((Height - CInt(TextSize.Height)) \ 2) + 1

'Draw the text
e.Graphics.DrawString(mText, SystemInformation.MenuFont, New
SolidBrush(Color.Black), TextPos.X, TextPos.Y)

End Sub

End Class

</code>

Any ideas would be greatly appreciated. I know i can just create
another property called Caption and use that, however i want
consistency with other controls.

Thanks

Tom
 
H

Herfried K. Wagner [MVP]

* Tom said:
Hi

I have a usercontrol that inherits from
System.Windows.Forms.Usercontrol. As the Text property is not visable
in the IDE by default i am shadowing the property because i want ot
use it on the control.

This works fine and within the IDE i can set the text property,
however whenever i build the control this property is set to an empty
string, and i don't know why.

Quick and Dirty:

\\\
Public Class MyTextBox
Inherits TextBox

Private m_Text As String

Public Sub New()
MyBase.Text = "0"
End Sub

<System.ComponentModel.DefaultValue("0")> _
Public Overrides Property Text() As String
Get
Return m_Text
End Get
Set(ByVal Value As String)
m_Text = Value
MyBase.Text = m_Text
End Set
End Property
End Class
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top