Results 1 to 7 of 7

Thread: User control error

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    19

    Angry User control error

    I am trying to create a simple user control.
    I have added a 'windows control library' project template and changed the name of the user control to 'Mycontrol'. Even in the class I changed the name to mycontrol and Built the solution. Next I added a test project to use 'mycontrol' and add areference to 'mycontrol'. In the tool box instead of the name 'mycontrol' , the name 'usercontrol1' is appearing.

    When I try to add that control to the test form I am getting an error.

    What I am doing wrong?


    Thanks!

  2. #2
    Addicted Member PeteD's Avatar
    Join Date
    Jun 2003
    Location
    Sydney
    Posts
    158
    I know! It's annoying. If you rename your usercontol class after you have added it to the toolbox, the name does not update. You have to delete the toolbox item, and then add a new item to the toolbox (browsing to the location of the usercontrol's dll!

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    19

    No.

    After renaming and building the the control, then only it was added to the tool box. I did not rename the control after it was added to the tool box.

    Any ideas?

    Thanks

  4. #4
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Dublin (Ireland)
    Posts
    304
    Here is an example which worked fine for me:

    Public Class DecTxtBox
    Inherits System.Windows.Forms.TextBox


    #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

    'UserControl1 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.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    components = New System.ComponentModel.Container()
    End Sub

    #End Region

    Private Sub DecTxtBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
    Dim KeyAscii As Integer
    KeyAscii = Asc(e.KeyChar)
    Select Case KeyAscii
    Case 48 To 57, 8, 13
    ' Do nothing digits 0 - 9
    Case 46
    ' allow one decimal point only
    If InStr(Me.Text, ".") <> 0 Then
    KeyAscii = 0 'ignore
    End If
    Case Else
    KeyAscii = 0
    End Select
    ' set to return as handled or not
    If KeyAscii = 0 Then
    e.Handled = True
    Else
    e.Handled = False
    End If
    End Sub
    End Class

    and when I added it to my tool box, it did so using the name of the class

  5. #5
    Addicted Member PeteD's Avatar
    Join Date
    Jun 2003
    Location
    Sydney
    Posts
    158
    Renaming the file to mycontrol.vb will not be enough. You must make sure you rename the class

    i.e

    Public Class MyControl
    '.............................
    End Class

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    19

    Thank you!

    The problem is fixed now. The problem is I am only changing the control name.

    Thank you!

  7. #7
    Addicted Member PeteD's Avatar
    Join Date
    Jun 2003
    Location
    Sydney
    Posts
    158
    Pleased to help!

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