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

📄 form.vb

📁 Visual.Basic.NET实用编程百例-47.6M.zip
💻 VB
字号:
Imports System
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D

Public Class Form
    Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "
    Private SColor As Color
    Private EColor As Color
    Private Direction As LinearGradientMode
    Dim g As Graphics

    Public Sub New()
        MyBase.New()

        InitializeComponent()
        SColor = Color.Red
        EColor = Color.White
        Direction = LinearGradientMode.Vertical
    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

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意:以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
    Friend WithEvents StartColor As System.Windows.Forms.MenuItem
    Friend WithEvents EndColor As System.Windows.Forms.MenuItem
    Friend WithEvents MenuDirection As System.Windows.Forms.MenuItem
    Friend WithEvents leftup As System.Windows.Forms.MenuItem
    Friend WithEvents mupdown As System.Windows.Forms.MenuItem
    Friend WithEvents rightup As System.Windows.Forms.MenuItem
    Friend WithEvents leftright As System.Windows.Forms.MenuItem
    Friend WithEvents menu_exit As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.MainMenu1 = New System.Windows.Forms.MainMenu
        Me.MenuItem1 = New System.Windows.Forms.MenuItem
        Me.MenuDirection = New System.Windows.Forms.MenuItem
        Me.mupdown = New System.Windows.Forms.MenuItem
        Me.leftright = New System.Windows.Forms.MenuItem
        Me.leftup = New System.Windows.Forms.MenuItem
        Me.rightup = New System.Windows.Forms.MenuItem
        Me.StartColor = New System.Windows.Forms.MenuItem
        Me.EndColor = New System.Windows.Forms.MenuItem
        Me.menu_exit = New System.Windows.Forms.MenuItem
        Me.MenuItem2 = New System.Windows.Forms.MenuItem
        '
        'MainMenu1
        '
        Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})
        '
        'MenuItem1
        '
        Me.MenuItem1.Index = 0
        Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuDirection, Me.StartColor, Me.EndColor, Me.MenuItem2, Me.menu_exit})
        Me.MenuItem1.Text = "操作"
        '
        'MenuDirection
        '
        Me.MenuDirection.Index = 0
        Me.MenuDirection.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mupdown, Me.leftright, Me.leftup, Me.rightup})
        Me.MenuDirection.Text = "选择渐变方向"
        '
        'mupdown
        '
        Me.mupdown.Checked = True
        Me.mupdown.Index = 0
        Me.mupdown.Text = "从上到下"
        '
        'leftright
        '
        Me.leftright.Index = 1
        Me.leftright.Text = "从左到右"
        '
        'leftup
        '
        Me.leftup.Index = 2
        Me.leftup.Text = "从左上到右下"
        '
        'rightup
        '
        Me.rightup.Index = 3
        Me.rightup.Text = "从右上到左下"
        '
        'StartColor
        '
        Me.StartColor.Index = 1
        Me.StartColor.Text = "选择起始颜色"
        '
        'EndColor
        '
        Me.EndColor.Index = 2
        Me.EndColor.Text = "选择终止颜色"
        '
        'menu_exit
        '
        Me.menu_exit.Index = 4
        Me.menu_exit.Text = "退出"
        '
        'MenuItem2
        '
        Me.MenuItem2.Index = 3
        Me.MenuItem2.Text = "-"
        '
        'Form
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(480, 273)
        Me.Menu = Me.MainMenu1
        Me.Name = "Form"
        Me.Text = "渐变的窗体背景"

    End Sub

#End Region


    Private Sub Startcolor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartColor.Click
        Dim MyDialog As New ColorDialog
        MyDialog.AllowFullOpen = False
        MyDialog.ShowDialog()
        '显示对话框     
        SColor = MyDialog.Color
        '将在对话框中选择的颜色保存到SColor     

        Me.Invalidate()
        '重画窗口
    End Sub

    Private Sub EndColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EndColor.Click
        Dim MyDialog As New ColorDialog
        MyDialog.AllowFullOpen = False
        MyDialog.ShowDialog()
        '显示对话框     
        EColor = MyDialog.Color
        '将在对话框中选择的颜色保存到EColor     

        Me.Invalidate()
        '重画窗口
    End Sub

    Private Sub leftup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles leftup.Click
        Direction = LinearGradientMode.ForwardDiagonal
        '设置渐变方向
        Me.Invalidate()
        '重画窗口
    End Sub

    Private Sub rightup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rightup.Click
        Direction = LinearGradientMode.BackwardDiagonal
        Me.Invalidate()
        '设置渐变方向并重画窗口

    End Sub

    Private Sub leftright_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles leftright.Click
        Direction = LinearGradientMode.Horizontal
        Me.Invalidate()
        '设置渐变方向并重画窗口
    End Sub

    Private Sub mupdown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mupdown.Click
        Direction = LinearGradientMode.Vertical
        Me.Invalidate()
        '设置渐变方向并重画窗口
    End Sub


    Private Sub Form_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        g = e.Graphics
        Dim lb As New LinearGradientBrush(ClientRectangle, SColor, EColor, Direction)
        g.FillRectangle(lb, ClientRectangle)
        '绘制窗口背景
    End Sub

    Private Sub Form_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
        Me.Invalidate()
        '当改变窗口大小时重画全部窗口
    End Sub

    Private Sub Menu_exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menu_exit.Click
        Me.Close()
        '关闭窗口
    End Sub

    Private Sub Form_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 + -