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

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

中国个人站长站 ASP.NET教程 点击数: 更新时间:2007-7-8 7:16:31
sp;   '指定位置的卡片(这个对于vb.net是比较特殊的,具有带参数的属性)
    Default Public ReadOnly Property items(ByVal index As Integer) As pic
        Get
            If index >= 0 And index < m_piccontrols.Count Then
                Return CType(m_piccontrols(index), pic)
            End If
        End Get
    End Property

    Public Sub shuffle() ' 混卡片,也就是生成一组随机的卡片集合。(这里的算法不错!)
        Dim r As New System.Random()
        Dim d As New System.Collections.ArrayList()
        Dim p As pic
        While (m_piccontrols.Count > 0)
            Dim removeindex As Integer = r.Next(0, m_piccontrols.Count - 1)
            p = CType(m_piccontrols(removeindex), my_namespace.pic)
            m_piccontrols.RemoveAt(removeindex)
            d.Add(p)
        End While
        m_piccontrols = d
    End Sub

    Private m_image As imagelist
    <Category("grid"), Description("选择相应的imagelist控件。")> _
    Public Property imagelist() As imagelist
        Get
            Return m_image
        End Get
        Set(ByVal Value As imagelist)
            m_image = Value
            changepic()
        End Set
    End Property
    '/////////
    '这个事件比较重要,主要是根据图片的变动来生成不同的卡片集合。
    Private Sub changepic()
        If m_image Is Nothing Then Exit Sub
        Dim i As Integer
        For i = 0 To m_piccontrols.Count - 1
            CType(m_piccontrols(i), pic).Dispose() '注意这里。
        Next
        m_piccontrols.Clear()
        Dim j As Integer
        For i = 0 To m_image.Images.Count - 1
            For j = 0 To 3
                Dim p As New pic(m_image.Images(i))
                p.id = i
                m_piccontrols.Add(p)
            Next
        Next
    End Sub
    '由于在排列好后,每个在集合中的卡片的doubles属性都会被设置成true,
    '所以要在开始一次新的排序时设置所有的卡片该属性为false
    Public Sub setfalse()
        Dim i As Integer
        For i = 0 To m_piccontrols.Count - 1
            Dim apic As pic = CType(m_piccontrols(i), pic)
            apic.doubles = False
        Next
    End Sub

End Class

3.

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

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

    Public Sub New()
        MyBase.New()

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

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

    End Sub

    'UserControl 重写 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()
        components = New System.ComponentModel.Container()
    End Sub

#End Region
    '//                                 这个程序的原理                                                                        //
    '//先做一个pic控件,可以为其设置相应的图片,不允许改变大小,要重写sizechange,onpait事件  //
    '//做一个集合组件piccontrols来容纳一定数量的pic卡片,但并不显示它,因为是组件。只是容器  //
    '//最后做一个picshow控件,用于显示piccontrols.count数量的卡片集合。                      //
    '//比较重要的地方就是如何对卡片进行随机混排(piccontrols的shuffle方法)和picshow控件的   //
    '//contrains,start方法。尤其注意这里进行排序的方法:是将卡片在集合里就弄混(随机),这样//
    '//我们取得的每个卡片都是随机的了,然后在picshow控件里根据每个卡片的doubles,id属性来进行 //
    '//排序,把随机和排序分开了。当然也可以把他们合并写到picshow控件里。不过这里不建议这样。 //
    '//因为对于piccontrols组件来说,它的集合就是一个随机产生的卡片集合。这样比较好理解。     //

    Private Const m_spacing As Integer = 10 '间隔设置的常量

    Private m_rows As Integer = 2 ' 对于一个阵列来讲,2行应该更有意义。
    <Category("grid"), Description("矩阵的行。"), DefaultValue(2)> _
        Public Property row() As Integer
        Get
            Return m_rows
        End Get
        Set(ByVal Value As Integer)
            If Value > 0 Then
                m_rows = Value
                Me.Refresh()
            End If
        End Set
    End Property
    Private m_columns As Integer = 2
    <Category("grid"), Description("矩阵的列。"), DefaultValue(2)> _
    Public Property columns() As Integer
        Get
            Return m_columns
        End Get
        Set(ByVal Value As Integer)
      

上一页  [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号