Question no center align?

adma

New member
Joined
Mar 20, 2010
Messages
1
Programming Experience
Beginner
i have a homework, it must show this:

*
***
*****
*
*
*
*
*​

it should look like an arrow. but as we all know, there is no center align in vb.net. i've been working on it for hours already, and i still can't make it right. somebody please help me. so far, this is what i've done, but i can't make it work.

ListBox1.Items.Clear()
a = "*"
s = " "

For m As Integer = 3 To 1 Step -1

ListBox1.Items.Add(s & a)
a += "**"
s -= " "
 
Provide meaningful thread titles when posting, something that in short terms explains WHAT you need help with. Thread title changed.

To center align the item text in ListBox you must ownerdraw it by setting DrawMode property and handle DrawItem event. When you call DrawString method you must provide a StringFormat instance that specifies the alignment.
 
How about this?

VB.NET:
		Dim y As Integer = 1
		ListBox1.Items.Clear()
		For m As Integer = 3 To 1 Step -1
			ListBox1.Items.Add(Space(m) & StrDup(y, "*"))
			y = y + 2
		Next m
		For m As Integer = 1 To 5
			ListBox1.Items.Add(Space(3) & "*")
		Next m
 
How about this?

VB.NET:
		Dim y As Integer = 1
		ListBox1.Items.Clear()
		For m As Integer = 3 To 1 Step -1
			ListBox1.Items.Add(Space(m) & StrDup(y, "*"))
			y = y + 2
		Next m
		For m As Integer = 1 To 5
			ListBox1.Items.Add(Space(3) & "*")
		Next m

Please don't just do people's homework for them. It reduces their opportunity to learn by thinking for themselves and it's not fair on other members of the class who don't have someone else to do their work for them.
 
You are correct. I should have simply posted some hints.

But that was just a hackneyed version using little-known (?) string methods the student may not have learned in class. There were several other ways to solve the problem, and I'm guessing the requirements were to use simpler methods.
 
Back
Top