-
Mar 8th, 2005, 07:23 AM
#1
Thread Starter
Frenzied Member
problem with the New sub in my custom control
Dear all,
i am building a small control that inherits from the textbox, i am doing this so that i can preset some properties of the textbox so that when i drag them into my form in design view i dont need to adjust each one properties.
the problem is with the text property.
here is my code for the control
VB Code:
Public Class mytxtbox
Inherits System.Windows.Forms.TextBox
Sub New()
MyBase.New()
Me.MaxLength = 10
Me.Text = 0
Me.RightToLeft = Windows.Forms.RightToLeft.Yes
End Sub
now when i drag the new control from the toolbox to my form it is pulled down with all the properties setup as i want Except for the text propert
it is always mytxtbox1 instead of 0 as i preset it in the new sub
Waiting ur answer
RGDS
-
Mar 8th, 2005, 07:39 AM
#2
Hyperactive Member
Re: problem with the New sub in my custom control
You need to set all of the properties using the MyBase keyword so instead of Me.Text, use MyBase.Text.
Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
Dr. Seuss 
-
Mar 8th, 2005, 08:55 AM
#3
Thread Starter
Frenzied Member
Re: problem with the New sub in my custom control
i tried it
doesn't work
any other suggestions
|THx in advance
-
Mar 8th, 2005, 09:41 AM
#4
Re: problem with the New sub in my custom control
Try making it a Public Sub New.
I don't live here any more.
-
Mar 8th, 2005, 09:48 AM
#5
Re: problem with the New sub in my custom control
 Originally Posted by Lil Ms Squirrel
You need to set all of the properties using the MyBase keyword so instead of Me.Text, use MyBase.Text.
That would only happen if you had local variables of the same name and you specifically didn't want to change them.
I don't live here any more.
-
Mar 8th, 2005, 05:51 PM
#6
Thread Starter
Frenzied Member
Re: problem with the New sub in my custom control
i tried the public new with no difference
the very strange thing that is all other properties are set as i need but only the text property don't ?????
i can ignore it and change it from design form but i need to understand to learn better
thx for your replies
-
Mar 8th, 2005, 06:13 PM
#7
Re: problem with the New sub in my custom control
The Name property comes from the UC Class name - mytxtbox + 1 or whatever instances you have created.
If you want the Text property to be defaulted to something then did you create a Public Property of Text?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 8th, 2005, 06:21 PM
#8
Re: problem with the New sub in my custom control
Here is a sample of the Text property for a UC control.
VB Code:
Private _Text As String = ""
<Browsable(True), DefaultValue("0"), Category("Appearance")> _
Public Shadows Property Text() As String
Get
Return _Text
End Get
Set(ByVal Value As String)
_Text = Value
End Set
End Property
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 8th, 2005, 07:59 PM
#9
Thread Starter
Frenzied Member
Re: problem with the New sub in my custom control
first of all thank you for your reply RobDog888
i need to understand what is the Shadow means ??? and why is it necessary to have this line
VB Code:
<Browsable(True), DefaultValue("0"), Category("Appearance")>
i know what is overloading and overriding but it is the first time to get in touch with Shadows thing ??
can you explain more
thx again for your kind answers
RGDS
-
Mar 8th, 2005, 09:46 PM
#10
Re: problem with the New sub in my custom control
Ok, to start the line is an attribute tag that you get when you declare "Imports System.ComponentModel"
at the very top of your class.
"<Browsable(True)," means that in the property grid window you can "browse" the property
or is "visible" so to speak.
If you change it to False then it will be hidden from the property grid.
"DefaultValue("0")," means that "0" will be the default property value for the property. If you change a
property from its default value the value will become bold in the property grid. Also, when you right
click on the property in the grid you get a popup menu that has two menuitems on it - "Reset"
and "Description". Reset will change the property value back to your specified default value of "0". The Description
menuitem will turn the HelpText panel on or off.
"Description("The TabPages in the control." Description is the "description" that displays in the help text window below
the prop grid like shown in the TabPages description.

"Category("Appearance")>" means where you are placing the property categorically. If you look at
your property grid window you will see:- Accessibility
- Appearance
- Behavior
- Configurations
- Data
- Design
- Focus
- Layout
- Misc
So when its all put together you have several options plus more that I didnt get into.
VB Code:
<Browsable(True), DefaultValue("0"), Category("Appearance"), Description("MyTextBox Control is great!")> _
Public Shadows Property Text() As String
Get
Return _Text
End Get
Set(ByVal Value As String)
_Text = Value
End Set
End Property
Note: there is a line wrap underscrore designator so it can attach to the Public Property blah bah...
Now the "Shadows" part of it is required because the "Text" property is a built-in windows default
property. We need to attach to the windows text property so we can modify it instead of having errors
or duplicate Text properties.
There is allot to cover for user controls. I just learned all this a few weeks ago and I now see the real
depth with user controls and its not fun. , but the result is
Last edited by RobDog888; Mar 8th, 2005 at 11:36 PM.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 8th, 2005, 10:55 PM
#11
Thread Starter
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|