Public Class Form1
Dim sb As New System.Text.StringBuilder
Dim newFont As New Font("MS Sans Serif", 10)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim rangeStart As Integer = 1
Dim rangeEnd As Integer = 1
Dim lines(4) As String
For y As Integer = 1 To 5
For x As Integer = -9 To -2
If x >= rangeStart Then
lines(y - 1) &= Math.Abs(x).ToString
End If
Next
For x As Integer = 1 To 9
If x <= rangeEnd Then
lines(y - 1) &= x.ToString
End If
Next
If y > 1 Then rangeStart -= 2 Else rangeStart -= 4
rangeEnd += 2
Next
Dim newLines As New List(Of String)
For y As Integer = 5 To 1 Step -1
If y = 5 Then
newLines.Add(String.Format("{0,-1}{1}", "", lines(y - 1)))
Else
newLines.Add(String.Format("{0," & -((Math.Abs(y - 5) * 4) + 1) & "}{1}", "", lines(y - 1)))
End If
Next
newLines.Reverse()
sb.Append(String.Join(Environment.NewLine, newLines.ToArray))
Dim gr As Graphics = Graphics.FromHwnd(Me.Handle)
Dim maxWidth As Integer = CInt(gr.MeasureString(newLines(newLines.Count - 1), newFont).Width)
Dim maxHeight As Integer = CInt(gr.MeasureString(newLines(newLines.Count - 1), newFont).Height) * 5
Me.SetClientSizeCore(maxWidth + 100, maxHeight + 100)
Me.Invalidate()
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawString(sb.ToString, newFont, Brushes.Black, New Point(50, 50))
End Sub
End Class