|
-
Jul 22nd, 2003, 12:55 PM
#1
Thread Starter
Junior Member
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!
-
Jul 22nd, 2003, 01:25 PM
#2
Addicted Member
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!
-
Jul 22nd, 2003, 09:12 PM
#3
Thread Starter
Junior Member
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
-
Jul 22nd, 2003, 11:55 PM
#4
Hyperactive Member
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
-
Jul 23rd, 2003, 05:36 AM
#5
Addicted Member
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
-
Jul 23rd, 2003, 05:58 AM
#6
Thread Starter
Junior Member
Thank you!
The problem is fixed now. The problem is I am only changing the control name.
Thank you!
-
Jul 23rd, 2003, 06:05 AM
#7
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|