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

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

中国个人站长站 ASP.NET教程 点击数: 更新时间:2007-7-8 7:16:31
      If (Value > 0) And (Value Mod 2 = 0) Then
                m_columns = Value
                Me.Refresh()
            Else
                Throw New Exception("不是有效的列值!请输入2的倍数的列值。")
            End If
        End Set
    End Property
    Private m_collection As piccontrols
    <Category("grid"), Description("指定相应的piccontrols组件。")> _
    Public Property getcontrols() As piccontrols
        Get
            Return m_collection
        End Get
        Set(ByVal Value As piccontrols)
            m_collection = Value
        End Set
    End Property
    '绘制边框,由于还没有将卡片加入到me.controls集合,所以只有边框。
    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim height As Integer = my_namespace.pic.m_maxheight
        Dim width As Integer = my_namespace.pic.m_maxlen
        Me.Width = (width + m_spacing) * m_columns + m_spacing
        Me.Height = (height + m_spacing) * m_rows + m_spacing
        Dim g As Graphics = Me.CreateGraphics
        Dim row, column As Integer
        For row = 0 To m_rows - 1
            For column = 0 To m_columns - 1
                g.DrawRectangle(System.Drawing.Pens.Gray, column * (width + m_spacing) + m_spacing, _
                row * (height + m_spacing) + m_spacing, width, height)
            Next
        Next
    End Sub

    Private m_double As pic '记录相同的那个卡片

    Private m_last As Integer  '记录格子中的最后一个卡片

    '开始排列
    Public Sub start()

        Me.Controls.Clear() '先清空容器

        If Not IsNothing(m_collection) Then '判断行列之积和卡片数量是否相等
            If (m_collection.count <> m_rows * m_columns) Then
                Throw New Exception("卡片数量为:" & CStr(m_collection.count) & "格子数量为:" & CStr(m_rows * m_columns))
            End If

            '///////////////////////////////////

            m_last = -2 '初始化,因为从0开始是第一个格子,所以初始值为-2

            m_collection.setfalse() '因为开始一次排序就会把所有的卡片pic的double属性全都设置为true。所以,这里要全都设置回false

            m_collection.shuffle() '将卡片弄混

            Dim cardcount As Integer = 0 '卡片指针
            Dim row, column As Integer

            For row = 0 To m_rows - 1
                For column = 0 To m_columns - 1
                    Dim apic As pic = CType(m_collection(cardcount), pic)
                    '加入到me的控件集合
                    Me.Controls.Add(apic)
                    '控件集合中的原有卡片进行遍历,看是否有单个的与新加入的同一个图片的卡片
                    Dim rint As Integer = contrains(apic)

                    Select Case rint
                        Case 0 '匹配排列
                            apic.Left = m_double.Left + m_spacing + my_namespace.pic.m_maxlen
                            apic.Top = m_double.Top
                        Case 1 '没有匹配项,间隔排列

                            '行,注意一定要使用int进行转化,否则会四舍五入。
                            Dim r As Integer = Int(m_last / (m_rows))
                            '列
                            Dim c As Integer = m_last Mod (m_rows)
                            '取得行列后就可以直接设置位置了。
                            apic.Left = c * (pic.m_maxlen + m_spacing) + m_spacing
                            apic.Top = r * (pic.m_maxheight + m_spacing) + m_spacing

                    End Select
                    cardcount += 1 '下一个卡片
                Next
            Next
            MessageBox.Show("排序完成!")

        End If
    End Sub
    '排序的函数
    Public Function contrains(ByVal p As pic) As Integer
        m_double = Nothing '初始值为空,每次排序前要设置为空。
        Dim apic As pic
        Dim i As Integer
        Dim count As Integer = Me.Controls.Count - 1
        For i = 0 To count - 1 '从0到末尾-1,把自己排除掉,自己和自己不必要去比较
            apic = CType(Me.Controls(i), pic)
            If (apic.id = p.id) And apic.doubles = False Then  'And i <> count
                apic.doubles = True '匹配
                p.doubles = True '匹配
                m_double = apic

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