473,394 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Probably Simple Text Property Problem

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
Nov 20 '05 #1
1 1096
* Tom <re***@to.group> scripsit:
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
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: FrankJeroen | last post by:
Hi there, I have a simple problem, but I can't fix it. I have worked with Visual Basic 6. But I recently switched to Visual Basic ..Net 2003. I have a Form with an Spreadsheet. I want to...
2
by: MK | last post by:
Hi, I don't have much experience with Javascript and have a simple question. Suppose one wants to write some text in the web page which needs to be center aligned, then how to do it? The...
5
by: Greg Smith | last post by:
I am sure this is very simple but I can't seem to get the syntax correct. I have a class that I added to my application and I would like to reference controls on a webform. Something like: ...
0
by: Daniel Sélen Secches | last post by:
I found a good class to do a simple FTP. Very good.... I'm posting it with the message, i hope it helps someone ============================================================== Imports...
12
by: Peter Proost | last post by:
Hi group, I've got what seems a simple problem, but I can't find the solution. I've got a textbox and a handheld scanner to scan barcodes, the scanner just generates keypresses like a keyboard...
2
by: RSH | last post by:
Hi, i have a situation where I have a VB .Net Module built that contains all of the functions I need. I now need to add a form to the project and i need the form to sdisplay and the module code...
11
by: Kush | last post by:
Hello All, I am having problem writing some data to file and I do not understand my mistake / misconception. I am trying to write some simple text to file but the text is rather output to...
0
by: opedog | last post by:
I'm monkeying around with databinding, trying to learn all the ins and outs. I'm populating a label from one of my business objects properties which is a string, however, I want some formatting done...
26
by: optimistx | last post by:
A variable in global scope var a1 = 'contents of global variable a1'; can be references (with some limitations) as window; // or window.a1; // or even window;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.