Click here to Skip to main content
15,902,276 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
dear friends

my User control code is
VB
Public class xCombo
inherits system.windows.form.combobox

   Public sub new()

   End Sub

End Class

-------------------------
i'm having this control in toolbox .
i'm able to drag & drop in to the windows form.

in form designer, the declaration appears as Friends xCombo1 as xCombo .
but not Friends Withevent xCombo1 as xCombo.

for all windows control declaration comes with -
Friend Withevent xxx as xxx.
Friend Withevent yyy as yyy
Friend Withevent zzz as zzz
etc.

Thanks in Advance
Posted
Updated 2-Aug-13 8:11am
v4
Comments
Sergey Alexandrovich Kryukov 1-Aug-13 17:39pm    
What event? there is no any event... There is no a user control either...
—SA
Manish (Mack) 2-Aug-13 14:18pm    
In which line you r getting error?

1 solution

This worked for me just fine. I took your code, and I created a new application with the following:
VB
Public Class Form1

    Dim WithEvents x As New xCombo

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.Controls.Add(x)
        For i As Integer = 1 To 5
            x.Items.Add(i)
        Next
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged, x.SelectedIndexChanged
        MessageBox.Show(DirectCast(sender, ComboBox).SelectedItem)
    End Sub
End Class

Public Class xCombo
    Inherits System.Windows.Forms.ComboBox

    Public Sub New()

    End Sub

End Class


I compiled that. I then created a new project, selected Tools/Choose Toolbox Items, browsed to my new EXE and selected it. A new xCombo control appeared in my toolbox, so I added one to my form. I also added a regular combobox. Here's the result in the designer code:
VB
Private Sub InitializeComponent()
    Me.XCombo1 = New WindowsApplication1.xCombo()
    Me.ComboBox1 = New System.Windows.Forms.ComboBox()
    Me.SuspendLayout()
    '
    'XCombo1
    '
    Me.XCombo1.FormattingEnabled = True
    Me.XCombo1.Location = New System.Drawing.Point(67, 90)
    Me.XCombo1.Name = "XCombo1"
    Me.XCombo1.Size = New System.Drawing.Size(121, 21)
    Me.XCombo1.TabIndex = 0
    '
    'ComboBox1
    '
    Me.ComboBox1.FormattingEnabled = True
    Me.ComboBox1.Location = New System.Drawing.Point(67, 132)
    Me.ComboBox1.Name = "ComboBox1"
    Me.ComboBox1.Size = New System.Drawing.Size(121, 21)
    Me.ComboBox1.TabIndex = 1
    '
    'Form1
    '
    Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
    Me.ClientSize = New System.Drawing.Size(284, 262)
    Me.Controls.Add(Me.ComboBox1)
    Me.Controls.Add(Me.XCombo1)
    Me.Name = "Form1"
    Me.Text = "Form1"
    Me.ResumeLayout(False)

End Sub
Friend WithEvents XCombo1 As WindowsApplication1.xCombo
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox


Looks OK to me.
 
Share this answer
 
Comments
debangshub 13-Aug-13 14:07pm    
Thanks for the reply.
Sorry for the delay as i was not present.

Actually i also did the same thing but not having Friend WithEvents xCombo1 as WindowsApplication1.xCombo in designer form. Which project type have you selected ?.
woopsydoozy 13-Aug-13 15:44pm    
I did an EXE (Windows Form Application) initially, but I also tried it as a DLL (Class Library), and that worked fine, too.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900