画布画笔画刷测试
1.画布分类
画布可以分为窗体画布和控价画布两类
声明窗体画布
Dim 画布 As Graphics = Me.CreateGraphics
声明控件画布
Dim 按钮画布 As Graphics = Button4.CreateGraphics
2. 画笔
声明方式
Dim 画笔 As New Pen(Color.Red)
3. 画刷
4. 其他色刷
具体细节没看,用到再说。
5. 程序过程
-
画面设计
-
模块设计
Module 文件
Public Sub 生成指定文件(路径 As String)
IO.File.Create(路径)
End Sub
Public Sub 删除指定文件(路径 As String)
Try
IO.File.Delete(路径)
Catch ex As Exception
End Try
End Sub
End Module
- 背景程序
Imports Microsoft.Office.Interop
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a As String = "D:\2.txt"
文件.删除指定文件(a)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim a As String = "D:\2.txt"
文件.生成指定文件(a)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Button3.BackColor = Color.FromArgb(255, 255, 0, 0)
Dim myLoc As New Point(100, 100)
Button3.Location = myLoc
Dim mySize As New Size(200, 200)
Dim myRec As New Rectangle(0, 0, 180, 200) '起始坐标和宽高
Dim myRec2 As New Rectangle(myLoc, mySize)
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim 画布 As Graphics = Me.CreateGraphics
Dim 画笔 As New Pen(Color.Red)
Dim 起点位置 As New Point(10, 50)
Dim 终点位置 As New Point(200, 200)
画布.DrawLine(画笔, 起点位置, 终点位置)
画布.DrawRectangle(画笔, 200, 20, 200, 300) '画矩形
'画重载
'在按钮上创建画布
Dim 按钮画布 As Graphics = Button4.CreateGraphics
按钮画布.DrawLine(画笔, 0, 0, 10, 20)
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
End Sub
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
Dim 画布 As Graphics = Me.CreateGraphics
画布.Clear(Color.Coral)
Dim 色刷 As New SolidBrush(Color.SaddleBrown) '单色色刷
画布.FillEllipse(色刷, 10, 10, Width - 200, Height - 100)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
BackColor = Color.Coral
End Sub
End Class
以上
r As Object, e As EventArgs) Handles Me.Load
BackColor = Color.Coral
End Sub
End Class
*以上*