标题:用VB.NET如何画网格
只看楼主
xo1437404152
Rank: 1
等 级:新手上路
帖 子:17
专家分:1
注 册:2014-3-19
结帖率:100%
 问题点数:0 回复次数:2 
用VB.NET如何画网格
搜索更多相关主题的帖子: VB.NET 网格 
2018-01-06 20:53
zcsor
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:19
专家分:105
注 册:2018-2-5
得分:0 
Public Class Form1
    Private WithEvents PnlShow As New Panel

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Size = New Size(600, 600)
        PnlShow.Size = New Size(500, 500)
        PnlShow.BorderStyle = BorderStyle.FixedSingle
        PnlShow.Location = New Point(50, 50)
        Me.Controls.Add(PnlShow)
    End Sub

    Private Sub PnlShow_Paint(sender As Object, e As PaintEventArgs) Handles PnlShow.Paint
        Dim MaxX As Integer = PnlShow.Width - 25
        Dim MaxY As Integer = PnlShow.Height - 25

        For y As Integer = 25 To MaxY Step 50
            e.Graphics.DrawLine(Pens.Black, 25, y, MaxX, y)
            e.Graphics.DrawString(y, Me.Font, SystemBrushes.AppWorkspace, MaxX + 5, y)
        Next
        For x As Integer = 25 To MaxX Step 50
            e.Graphics.DrawLine(Pens.Black, x, 25, x, MaxY)
            e.Graphics.DrawString(x, Me.Font, Brushes.Black, x, MaxY + 5)
        Next

        e.Graphics.DrawBezier(Pens.Red, New Point(25, 25), New Point(50, 300), New Point(200, 400), New Point(450, 450))
    End Sub

End Class
2018-02-16 10:46
zcsor
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:19
专家分:105
注 册:2018-2-5
得分:0 
加上字符位置矫正就是这样
Public Class Form1
    Private WithEvents PnlShow As New Panel

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Size = New Size(600, 600)
        PnlShow.Size = New Size(500, 500)
        PnlShow.BorderStyle = BorderStyle.FixedSingle
        PnlShow.Location = New Point(50, 50)
        Me.Controls.Add(PnlShow)
    End Sub

    Private Sub PnlShow_Paint(sender As Object, e As PaintEventArgs) Handles PnlShow.Paint
        Dim MaxX As Integer = PnlShow.Width - 25
        Dim MaxY As Integer = PnlShow.Height - 25
        Dim Offset = e.Graphics.MeasureString("2", Me.Font)

        For y As Integer = 25 To MaxY Step 50
            e.Graphics.DrawLine(Pens.Black, 25, y, MaxX, y)
            e.Graphics.DrawString(y, Me.Font, SystemBrushes.AppWorkspace, MaxX + 5, y - Offset.Height / 2)
        Next
        For x As Integer = 25 To MaxX Step 50
            e.Graphics.DrawLine(Pens.Black, x, 25, x, MaxY)
            e.Graphics.DrawString(x, Me.Font, Brushes.Black, x - x.ToString.Length * Offset.Width / 2, MaxY + 5)
        Next

        e.Graphics.DrawBezier(Pens.Red, New Point(25, 25), New Point(50, 300), New Point(200, 400), New Point(450, 450))



    End Sub

End Class
2018-02-16 10:50



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-484030-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.106362 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved