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
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