当前位置: 动力学知识库 > 问答 > 编程问答 >

vb.net - Print diamond shape multiline textbox in Visual Basic using loops in windows forms

问题描述:

I have to write a program which on button click, generates a diamond shape. The diamond shape must be of size 32 (rows and columns) and each row/column increments by +/- 2 beginning at 1.

Here is what I have come up with so far, how can I display this diamond in a multiline textbox?

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim row As Integer

Dim column As Integer

For i As Integer = 0 To 15 Step 2

If row = i Or _

column = i Then

TextBox1.Lines(i) = "O"

End If

Next

For o As Integer = 16 To 32 Step -2

If row = o Or _

column = o Then

TextBox1.Lines(o) = "O"

End If

Next

End Sub

End Class

Not looking for a full solution here, just a push in the right direction. Thanks in advance!

网友答案:

Hint:

    TextBox1.Font = New System.Drawing.Font("Courier New", 9.0F)
    Dim n As Integer = 7
    For i As Integer = 1 To 15 Step 2
        Dim s As String = ""
        s = StrDup(n, " ") & StrDup(i, "*")
        TextBox1.Text = TextBox1.Text & s & vbCrLf
        n = n - 1
    Next
分享给朋友:
您可能感兴趣的文章:
随机阅读: