Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a control which inherits the textbox control. I put the following code in the constructor for it:

 

  Public Sub New()

     MyBase.New()

     'This call is required by the Windows Form Designer.
     InitializeComponent()

     'Add any initialization after the InitializeComponent() call
     MyBase.Text = ""
     Me.Text = ""

  End Sub

 

What I want is that when you create the control the text is empty. The code I put in does nothing (I tried both lines seperately to no avail.) On a side note, for a control like a textbox is there a load event? How would I code it so that when the control is executed at RUNTIME I can initialize some things?

  • Administrators
Posted (edited)

I think the problem is the Windows Form Designer automatically setting the text to the name of the control on creation. Even though your sub new is setting the text property to "".

If you look in the designer generated code you will see some asignment to the .Text

 

The DefaultAttribute may help...

 

http://ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemcomponentmodeldefaultvalueattributeclasstopic.htm

Edited by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • Leaders
Posted

because , after the Sub , the form gets told what it's name is lower down the Designer generated Code area , eg:

#Region " Windows Form Designer generated code "

   Public Sub New()
       MyBase.New()

       'This call is required by the Windows Form Designer.
       InitializeComponent()

       'Add any initialization after the InitializeComponent() call

   End Sub

   'Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub

   'Required by the Windows Form Designer
   Private components As System.ComponentModel.IContainer

   'NOTE: The following procedure is required by the Windows Form Designer
   'It can be modified using the Windows Form Designer.  
   'Do not modify it using the code editor.
   Friend WithEvents Button1 As System.Windows.Forms.Button
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       '
       'Form1
       '
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(496, 266)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1})
       Me.Name = "Form1"
       Me.Text = "Form1" '///<<<<<<<<<<<<<<<<<<<<
       '//////////////////////// you need to change it here^^^^
       Me.ResumeLayout(False)

   End Sub

#End Region

hope that's what you're after.:)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...