PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
problem with the New sub in my custom control-VBForums
Results 1 to 11 of 11

Thread: problem with the New sub in my custom control

Hybrid View

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

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

    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
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,651

    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

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

    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

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width