⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imagecubeform.vb

📁 Mastering VBNet Include Source Code
💻 VB
字号:
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    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
    Friend WithEvents bttnDrawCube As System.Windows.Forms.Button
    
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.Container

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.bttnDrawCube = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'bttnDrawCube
        '
        Me.bttnDrawCube.BackColor = System.Drawing.SystemColors.Control
        Me.bttnDrawCube.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte))
        Me.bttnDrawCube.Location = New System.Drawing.Point(8, 8)
        Me.bttnDrawCube.Name = "bttnDrawCube"
        Me.bttnDrawCube.Size = New System.Drawing.Size(168, 32)
        Me.bttnDrawCube.TabIndex = 0
        Me.bttnDrawCube.Text = "Draw Cube"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.SandyBrown
        Me.ClientSize = New System.Drawing.Size(608, 501)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.bttnDrawCube})
        Me.Name = "Form1"
        Me.Text = "ImageCube "
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub bttnDrawCube_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnDrawCube.Click
        Dim G As Graphics
        G = GetGraphicsObject()
        G.Clear(Color.SandyBrown)
        G.TranslateTransform(250, 200)

        Dim images(2) As Image
        Dim path As String
        path = Application.StartupPath & "\.."
        images(0) = Image.FromFile(path & "\image1.jpg")
        images(1) = Image.FromFile(path & "\image2.jpg")
        images(2) = Image.FromFile(path & "\image3.jpg")

        Dim face1(2) As Point   ' the three points that define the front face of the cube
        face1(0) = New Point(-150, -20)
        face1(1) = New Point(150, -20)
        face1(2) = New Point(-150, 230)

        Dim face2(2) As Point   ' the three points that define the upper face of the cube
        face2(0) = New Point(-30, -140)
        face2(1) = New Point(270, -140)
        face2(2) = New Point(-150, -20)

        Dim face3(2) As Point   ' the three points that define the side face of the cube
        face3(0) = New Point(150, -20)
        face3(1) = New Point(270, -140)
        face3(2) = New Point(150, 230)

        Dim imgIndex As Integer
        Dim rnd As New System.Random()
        ' pick up an image randomly
        imgIndex = rnd.Next(0, 3)
        ' and display it on face1
        G.DrawImage(images(imgIndex), face1)
        ' pick up an image randomly
        imgIndex = rnd.Next(0, 3)
        ' and display it on face1
        G.DrawImage(images(imgIndex), face2)
        ' pick up an image randomly
        imgIndex = rnd.Next(0, 3)
        ' and display it on face1
        G.DrawImage(images(imgIndex), face3)
    End Sub

    Function GetGraphicsObject() As Graphics
        Dim bmp As Bitmap
        bmp = New Bitmap(Me.Width, Me.Height)
        Dim G As Graphics
        Me.BackgroundImage = bmp
        G = Graphics.FromImage(bmp)
        Return G
    End Function

End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -