Results 1 to 11 of 11

Thread: problem with the New sub in my custom control

  1. #1

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    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:
    1. Public Class mytxtbox
    2.     Inherits System.Windows.Forms.TextBox
    3.     Sub New()
    4.         MyBase.New()
    5.         Me.MaxLength = 10
    6.         Me.Text = 0
    7.         Me.RightToLeft = Windows.Forms.RightToLeft.Yes
    8.  
    9.     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

  2. #2
    Hyperactive Member Lil Ms Squirrel's Avatar
    Join Date
    Nov 2004
    Location
    planet squirrel
    Posts
    494

    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

  3. #3

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: problem with the New sub in my custom control

    i tried it

    doesn't work

    any other suggestions


    |THx in advance

  4. #4
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: problem with the New sub in my custom control

    Try making it a Public Sub New.
    I don't live here any more.

  5. #5
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: problem with the New sub in my custom control

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

  6. #6

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    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

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: problem with the New sub in my custom control

    Here is a sample of the Text property for a UC control.
    VB Code:
    1. Private _Text As String = ""
    2.  
    3.     <Browsable(True), DefaultValue("0"), Category("Appearance")> _
    4.     Public Shadows Property Text() As String
    5.         Get
    6.             Return _Text
    7.         End Get
    8.         Set(ByVal Value As String)
    9.             _Text = Value
    10.         End Set
    11.     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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  9. #9

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    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:
    1. <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

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    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:
    1. <Browsable(True), DefaultValue("0"), Category("Appearance"), Description("MyTextBox Control is great!")> _
    2. Public Shadows Property Text() As String
    3.     Get
    4.         Return _Text
    5.     End Get
    6.     Set(ByVal Value As String)
    7.         _Text = Value
    8.     End Set
    9. 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
    Attached Images Attached Images   
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  11. #11

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: problem with the New sub in my custom control



    thx a million RobDog888 , that is really nice of you

    understood


    Again thx, and you can count that i will vote for your sake in this thread

    C u soon i hope

    BST RGDS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width