自定义用户控制中的问题 [英] Problem in Custom USER CONTROL

查看:83
本文介绍了自定义用户控制中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友



我的用户控制代码是

dear friends

my User control code is

Public class xCombo
inherits system.windows.form.combobox

   Public sub new()

   End Sub

End Class



----- --------------------

我在工具箱中拥有这个控件。

我能够拖拽在窗体表格中输入。



在表单设计器中,声明显示为Friends xCombo1 as xCombo。

但不是Friends Withevent xCombo1 as xCombo。


所有Windows控制声明附带
-

朋友Withevent xxx为xxx。

朋友Withevent yyy as yyy

朋友Withevent zzz as zzz





先谢谢你


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

推荐答案

这对我很有用。我拿了你的代码,然后用以下内容创建了一个新的应用程序:

This worked for me just fine. I took your code, and I created a new application with the following:
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





我编译了那个。然后我创建了一个新项目,选择了工具/选择工具箱项目,浏览到我的新EXE并选中它。我的工具箱中出现了一个新的xCombo控件,所以我在表单中添加了一个。我还添加了一个常规的组合框。以下是设计器代码中的结果:



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:

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.


这篇关于自定义用户控制中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆