VS2010旗舰版的VB.NET数字操作系统FORM7程序代码

Imports System.Drawing.Imaging
Imports System.IO
Imports System.Drawing

Public Class Form7

Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    Dim s As String = TextBox1.Text

    '建一个与 PictureBox 大小相同的 Bitmap 对象
    Dim bitmap As New Bitmap(PictureBox1.Width, PictureBox1.Height)

    Using g As Graphics = Graphics.FromImage(bitmap)
        g.Clear(PictureBox1.BackColor) '清空之前的内容

        Dim font As New Font("Arial", 20) '创建一个新的字体对象
        Dim xPosition As Integer = 0 '记录水平绘制位置
        Dim yPosition As Integer = 0 '记录垂直绘制位置

        For i As Integer = 1 To s.Length

            Select Case s.Substring(i - 1, 1)

                Case " "
                    Dim blackBrush As New SolidBrush(Color.FromArgb(0, 0, 0)) '创建黑色画刷
                    g.DrawString(" ", font, blackBrush, New Point(xPosition, yPosition))
                    xPosition += 20 '增加水平偏移量

                Case "0"
                    Dim whiteBrush As New SolidBrush(Color.FromArgb(255, 255, 255)) '创建白色画刷
                    g.DrawString("■", font, whiteBrush, New Point(xPosition, yPosition))
                    xPosition += 20 '增加水平偏移量

                Case "1"


                    Dim whiteBrush As New SolidBrush(Color.FromArgb(255, 0, 0)) '创建白色画刷
                    g.DrawString("■", font, whiteBrush, New Point(xPosition, yPosition))
                    xPosition += 20 '增加水平偏移量
                Case "2"


                    Dim whiteBrush As New SolidBrush(Color.FromArgb(255, 165, 0)) '创建白色画刷
                    g.DrawString("■", font, whiteBrush, New Point(xPosition, yPosition))
                    xPosition += 20 '增加水平偏移量
                Case "3"


                    Dim whiteBrush As New SolidBrush(Color.FromArgb(255, 255, 0)) '创建白色画刷
                    g.DrawString("■", font, whiteBrush, New Point(xPosition, yPosition))
                    xPosition += 20 '增加水平偏移量

                Case "4"


                    Dim whiteBrush As New SolidBrush(Color.FromArgb(0, 255, 0)) '创建白色画刷
                    g.DrawString("■", font, whiteBrush, New Point(xPosition, yPosition))
                    xPosition += 20 '增加水平偏移量



                Case "5"


                    Dim whiteBrush As New SolidBrush(Color.FromArgb(0, 255, 255)) '创建白色画刷
                    g.DrawString("■", font, whiteBrush, New Point(xPosition, yPosition))
                    xPosition += 20 '增加水平偏移量
                Case "6"

                    Dim whiteBrush As New SolidBrush(Color.FromArgb(0, 0, 255)) '创建白色画刷
                    g.DrawString("■", font, whiteBrush, New Point(xPosition, yPosition))
                    xPosition += 20 '增加水平偏移量
                Case "7"


                    Dim whiteBrush As New SolidBrush(Color.FromArgb(128, 0, 128)) '创建白色画刷
                    g.DrawString("■", font, whiteBrush, New Point(xPosition, yPosition))
                    xPosition += 20 '增加水平偏移量
                Case "8"


                    Dim whiteBrush As New SolidBrush(Color.FromArgb(0, 0, 0)) '创建白色画刷
                    g.DrawString("■", font, whiteBrush, New Point(xPosition, yPosition))
                    xPosition += 20 '增加水平偏移量
                Case "9"


                    Dim whiteBrush As New SolidBrush(Color.FromArgb(0, 0, 0)) '创建白色画刷
                    g.DrawString("□", font, whiteBrush, New Point(xPosition, yPosition))
                    xPosition += 20 '增加水平偏移量
                Case "/"

                    yPosition += 20 '增加行高,假设行高为 20

            End Select
        Next
    End Using

    PictureBox1.Image = bitmap '绘制好的图像设置到 PictureBox 上
End Sub

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

    PictureBox1.AutoSize = True
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    PictureBox1.Image = Nothing
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    TextBox1.Text = ""
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

    Dim s As String = "0123456789/ "
    For i As Integer = 0 To 100
        Dim r As Integer = CInt(Rnd() * (Len(s)))
        TextBox1.Text = TextBox1.Text & Int(Rnd() * r) & Int(Rnd() * r) & Int(Rnd() * r) & Int(Rnd() * r) & Int(Rnd() * r) & Int(Rnd() * r) & Int(Rnd() * r) & Int(Rnd() * r) & Int(Rnd() * r) & Int(Rnd() * r) & Int(Rnd() * r) & Int(Rnd() * r) & Int(Rnd() * r) & Int(Rnd() * r) & Int(Rnd() * r)
    Next
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    '创建保存文件对话框
    Dim saveFileDialog As New SaveFileDialog()
    saveFileDialog.Filter = "PNG 文件|*.png|JPEG 文件|*.jpg|BMP 文件|*.bmp"

    If saveFileDialog.ShowDialog() = DialogResult.OK Then
        Dim filePath As String = saveFileDialog.FileName
        Dim extension As String = Path.GetExtension(filePath).ToLower()

        '根据文件扩展名确定保存格式
        Dim imageFormat As ImageFormat
        If extension = ".png" Then
            imageFormat = ImageFormat.Png
        ElseIf extension = ".jpg" Then
            imageFormat = ImageFormat.Jpeg
        ElseIf extension = ".bmp" Then
            imageFormat = ImageFormat.Bmp
        End If

        '将绘制好的 Bitmap 保存到指定路径
        Using bitmap As Bitmap = DirectCast(PictureBox1.Image, Bitmap)
            bitmap.Save(filePath, imageFormat)
        End Using
    End If
End Sub

End Class

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

EYYLTV

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值