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

📄 form1.vb

📁 vb 应用实例 简单应用 ddddddddddddddddddddddddddddddddd
💻 VB
字号:
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form  "

    Public Sub New()
        MyBase.New()

        InitializeComponent()


    End Sub

    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

    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButton3 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButton4 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButton5 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButton6 As System.Windows.Forms.RadioButton
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.RadioButton6 = New System.Windows.Forms.RadioButton()
        Me.RadioButton5 = New System.Windows.Forms.RadioButton()
        Me.RadioButton4 = New System.Windows.Forms.RadioButton()
        Me.RadioButton3 = New System.Windows.Forms.RadioButton()
        Me.RadioButton2 = New System.Windows.Forms.RadioButton()
        Me.RadioButton1 = New System.Windows.Forms.RadioButton()
        Me.TextBox1 = New System.Windows.Forms.TextBox()
        Me.PictureBox1 = New System.Windows.Forms.PictureBox()
        Me.RichTextBox1 = New System.Windows.Forms.RichTextBox()
        Me.GroupBox2 = New System.Windows.Forms.GroupBox()
        Me.ListBox1 = New System.Windows.Forms.ListBox()
        Me.Button2 = New System.Windows.Forms.Button()
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.RadioButton6, Me.RadioButton5, Me.RadioButton4, Me.RadioButton3, Me.RadioButton2, Me.RadioButton1})
        Me.GroupBox1.Location = New System.Drawing.Point(20, 8)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(277, 120)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Copy"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(195, 88)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(61, 23)
        Me.Button1.TabIndex = 6
        Me.Button1.Text = "&Copy"
        '
        'RadioButton6
        '
        Me.RadioButton6.Location = New System.Drawing.Point(20, 96)
        Me.RadioButton6.Name = "RadioButton6"
        Me.RadioButton6.Size = New System.Drawing.Size(72, 16)
        Me.RadioButton6.TabIndex = 5
        Me.RadioButton6.Text = "All"
        '
        'RadioButton5
        '
        Me.RadioButton5.Location = New System.Drawing.Point(20, 80)
        Me.RadioButton5.Name = "RadioButton5"
        Me.RadioButton5.Size = New System.Drawing.Size(72, 16)
        Me.RadioButton5.TabIndex = 4
        Me.RadioButton5.Text = "Image"
        '
        'RadioButton4
        '
        Me.RadioButton4.Location = New System.Drawing.Point(20, 64)
        Me.RadioButton4.Name = "RadioButton4"
        Me.RadioButton4.Size = New System.Drawing.Size(72, 16)
        Me.RadioButton4.TabIndex = 3
        Me.RadioButton4.Text = "XML"
        '
        'RadioButton3
        '
        Me.RadioButton3.Location = New System.Drawing.Point(20, 48)
        Me.RadioButton3.Name = "RadioButton3"
        Me.RadioButton3.Size = New System.Drawing.Size(72, 16)
        Me.RadioButton3.TabIndex = 2
        Me.RadioButton3.Text = "RTF"
        '
        'RadioButton2
        '
        Me.RadioButton2.Location = New System.Drawing.Point(20, 32)
        Me.RadioButton2.Name = "RadioButton2"
        Me.RadioButton2.Size = New System.Drawing.Size(72, 16)
        Me.RadioButton2.TabIndex = 1
        Me.RadioButton2.Text = "HTML"
        '
        'RadioButton1
        '
        Me.RadioButton1.Checked = True
        Me.RadioButton1.Location = New System.Drawing.Point(20, 16)
        Me.RadioButton1.Name = "RadioButton1"
        Me.RadioButton1.Size = New System.Drawing.Size(72, 16)
        Me.RadioButton1.TabIndex = 0
        Me.RadioButton1.TabStop = True
        Me.RadioButton1.Text = "Text"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(20, 136)
        Me.TextBox1.Multiline = True
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(185, 120)
        Me.TextBox1.TabIndex = 2
        Me.TextBox1.Text = ""
        '
        'PictureBox1
        '
        Me.PictureBox1.Location = New System.Drawing.Point(420, 136)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(184, 120)
        Me.PictureBox1.TabIndex = 3
        Me.PictureBox1.TabStop = False
        '
        'RichTextBox1
        '
        Me.RichTextBox1.AutoSize = True
        Me.RichTextBox1.Location = New System.Drawing.Point(215, 136)
        Me.RichTextBox1.Name = "RichTextBox1"
        Me.RichTextBox1.Size = New System.Drawing.Size(184, 120)
        Me.RichTextBox1.TabIndex = 4
        Me.RichTextBox1.Text = ""
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.ListBox1, Me.Button2})
        Me.GroupBox2.Location = New System.Drawing.Point(317, 8)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(297, 120)
        Me.GroupBox2.TabIndex = 1
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "Paste"
        '
        'ListBox1
        '
        Me.ListBox1.ItemHeight = 12
        Me.ListBox1.Location = New System.Drawing.Point(20, 16)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(195, 88)
        Me.ListBox1.TabIndex = 8
        '
        'Button2
        '
        Me.Button2.Enabled = False
        Me.Button2.Location = New System.Drawing.Point(225, 88)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(62, 23)
        Me.Button2.TabIndex = 7
        Me.Button2.Text = "&Paste"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(624, 266)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.RichTextBox1, Me.PictureBox1, Me.TextBox1, Me.GroupBox1, Me.GroupBox2})
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Clipboard"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region


    Dim strText As String = "活在当下!"
    Dim strHTML As String = "活在<B><FONT color='red' size='5'><U>当下!</U></FONT></B>"
    Dim strRTF As String = "{\rtf1\ansi\ansicpg950\deff0\deflang1033\deflangfe1028{\fonttbl{\f0\fnil\fprq1\fcharset136 \'b2\'d3\'a9\'fa\'c5\'e9;}{\f1\fmodern\fprq6\fcharset136 \'b7\'73\'b2\'d3\'a9\'fa\'c5\'e9;}}{\*\generator Msftedit 5.41.15.1503;}\viewkind4\uc1\pard\lang1028\f0\fs18\'ac\'a1\'a6\'62\'b7\'ed\'a4\'55!\f1\fs20\par}"
    Dim strXML As String = "<?xml version='1.0'?><Message>活在当下!</Message>"

    Dim Image1 As New System.Drawing.Bitmap("..\..\..\girl.jpg")




    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim do1 As New DataObject()

        If RadioButton1.Checked Then
            'Text
            Clipboard.SetDataObject(strText, True)

        ElseIf RadioButton2.Checked Then
            'HTML
            do1.SetData(DataFormats.Html, strHTML)
            Clipboard.SetDataObject(do1, True)

        ElseIf RadioButton3.Checked Then
            'RTF
            do1.SetData(DataFormats.Rtf, strRTF)
            Clipboard.SetDataObject(do1, True)

        ElseIf RadioButton4.Checked Then
            'XML
            do1.SetData("MyInternalXmlFormat", strXML)
            Clipboard.SetDataObject(do1, False)

        ElseIf RadioButton5.Checked Then
            'Image
            do1.SetData(DataFormats.Bitmap, True, Image1)
            Clipboard.SetDataObject(do1, True)

        ElseIf RadioButton6.Checked Then
            'All

            'Text and unicode
            do1.SetData(DataFormats.Text, strText)
            do1.SetData(DataFormats.UnicodeText, strText)

            'HTML 
            do1.SetData(DataFormats.Html, strHTML)

            'RTF 
            do1.SetData(DataFormats.Rtf, strRTF)

            'XML 
            do1.SetData("MyInternalXmlFormat", strXML)

            'Image
            do1.SetData(DataFormats.Bitmap, True, Image1)

            'Copy -> all formats on the Clipboard
            Clipboard.SetDataObject(do1, True)
        End If

        If Not (Clipboard.GetDataObject() Is Nothing) Then
            Dim strArray() As String
            Dim i As Integer
            ListBox1.Items.Clear()
            strArray = Clipboard.GetDataObject().GetFormats()
            For i = 0 To strArray.Length - 1
                ListBox1.Items.Add(strArray(i))
            Next i

            ListBox1.SelectedIndex = 0
            'Button1.Enabled = False
            Button2.Enabled = True
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim strFormat As String 'format
        Dim obj1 As Object      'pasted data

        TextBox1.Clear()
        RichTextBox1.Clear()
        PictureBox1.Image = Nothing

        'format
        strFormat = ListBox1.Text

        If Clipboard.GetDataObject().GetDataPresent(strFormat) Then
            obj1 = Clipboard.GetDataObject().GetData(strFormat)
            If Not obj1 Is Nothing Then

                'Paste -> RichTextBox
                RichTextBox1.Paste(DataFormats.GetFormat(strFormat))

                'Paste -> TextBox
                If obj1.GetType().ToString() = "System.String" Then
                    TextBox1.AppendText(CType(obj1, String))
                Else
                    TextBox1.AppendText(obj1.GetType.ToString())
                End If

                'Paste -> PictureBox
                Try
                    PictureBox1.Image = CType(obj1, Image)
                Catch ex As Exception
                    PictureBox1.Image = Nothing
                End Try
            End If
        End If

        Button1.Enabled = True
        'Button2.Enabled = False
    End Sub

    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

⌨️ 快捷键说明

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