编程教程
您现在的位置: 中国个人站长站 >> 网络编程 >> ASP.NET教程 >> 教程正文 一个使用用户控件(包括组件)的演示。
推荐位

一个使用用户控件(包括组件)的演示。

中国个人站长站 ASP.NET教程 点击数: 更新时间:2007-7-8 7:16:31

1.

Imports System.ComponentModel
Public Class pic
    Inherits System.Windows.Forms.UserControl

#Region " Windows 窗体设计器生成的代码 "

    'UserControl1 重写 dispose 以清理组件列表。
    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

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意:以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        '
        'pic
        '
        Me.Name = "pic"
        Me.Size = New System.Drawing.Size(48, 48)

    End Sub

#End Region

    Public Const m_maxlen As Integer = 48 '固定的宽和高
    Public Const m_maxheight As Integer = 48
    Public Sub New(ByVal m As image) '主要是用于在piccontrols组件中创建实例时使用
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化
        m_image = m
    End Sub
    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    Private m_image As image = image.FromFile("G:\练习\重要的例程\使用问题(在格子中显示图片)\Gounda Takeshi.ico")
    <Category("grid"), Description("设置卡片的图片。")> _
    Public Property image() As image
        Get
            Return m_image
        End Get
        Set(ByVal Value As image)
            m_image = Value
            Me.Refresh()
        End Set
    End Property
    '绘制边框和图象
    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim g As Graphics = Me.CreateGraphics
        Me.BackColor = Color.White
        g.DrawRectangle(System.Drawing.Pens.Black, 0, 0, Me.Width - 1, Me.Height - 1)
        Dim ic As Image = CType(m_image, Image)
        g.DrawImage(ic, 0, 0)
    End Sub
    '不允许调整大小
    Protected Overrides Sub OnSizeChanged(ByVal e As System.EventArgs)
        Me.Size = New Size(m_maxlen, m_maxheight)
    End Sub
    '匹配否标志
    Private m_double As Boolean = False
    <Category("grid"), Description("是否匹配的标志。")> _
    Public Property doubles() As Boolean
        Get
            Return m_double
        End Get
        Set(ByVal Value As Boolean)
            m_double = Value
        End Set
    End Property
    Private m_id As Integer
    <Category("grid"), Description("区分是否来自同一图片的标志。")> _
    Public Property id() As Integer
        Get
            Return m_id
        End Get
        Set(ByVal Value As Integer)
            m_id = Value
        End Set
    End Property
 
End Class

2.

Imports my_namespace
Imports System.ComponentModel
Public Class piccontrols
    Inherits System.ComponentModel.Component

#Region " 组件设计器生成的代码 "

    '组件重写 dispose 以清理组件列表。
    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

    '组件设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意:以下过程是组件设计器所必需的
    '可以使用组件设计器修改此过程。
    '不要使用代码编辑器修改它。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        components = New System.ComponentModel.Container()
    End Sub

#End Region
    Public Sub New(ByVal Container As System.ComponentModel.IContainer)
        MyClass.New()

        'Windows.Forms 类撰写设计器支持所必需的
        Container.Add(Me)

        changepic() '如果选择的图片发生了变化,那么创建卡片集合也要相应的变化。

    End Sub

    Public Sub New()
        MyBase.New()

        '该调用是组件设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

        changepic() '如果选择的图片发生了变化,那么创建卡片集合也要相应的变化。

    End Sub
    '////////////////////////////////////////////////////////////////

    Dim m_piccontrols As New System.Collections.ArrayList()
    '总数量
    <Category("grid"), Description("集合内卡片的总数。")> _
        Public ReadOnly Property count() As Integer
        Get
            Return m_piccontrols.Count
        End Get
    End Property
&nb

[1] [2] [3] [4] 下一页

教程录入:swh    责任编辑:swh 
个人站长站与你风雨同舟!
本站所提供的资源均来源于互联网,如有侵权行为,请与本站管理员联系,我们会第一时间删除!
·如果您发现《一个使用用户控件(包括组件)的演示。》文章有错误,也请通知我们修改!
联系邮箱chinageren#126.com,谢谢支持!
站内搜索:
版权所有:中国个人站长站 2007-2008 未经授权禁止复制或建立镜像 客服QQ号:112731235
copyright © 2007-2008 www.ChinaGeRen.com online services. all rights reserved. 苏ICP备05000059号