日期:2008-12-09  浏览次数:20567 次


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