在列表框中填充项目? [英] Padding items in a list box ?

查看:98
本文介绍了在列表框中填充项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含2列数字的列表框我想用零或空格填充数字,这样它们就等于3个字符,所以它们对齐。我尝试了以下代码 但我必须遗漏一些东西。


看起来像这样


4 786


123 265


34 123


128 2


我希望它看起来像这样


004 786


123 265


034 123


123 002

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


For Each c As Char in ListBox1 .Items
Dim i As String =" 1234567890"
Dim count As Integer = 0
如果i.Count = 1则
i.PadLeft(2).ToString()
ElseIf i.Count = 1则
i.PadLeft(1).ToString()
End if
Next

End Sub




解决方案

您好


将ListBox字体设置为MonoSpaced字体 - 例如Courier New或其他几个字体。


您看到这种效果的原因是大多数字体按比例间隔,因此3个空格的宽度不等于3'E'字符(例如)。 / p>

另一个选择是使用VbTab而不是Padding。


I have a list box with 2 columns of numbers I would like to pad the numbers with zeros or spaces, so that they equal 3 characters so they align. I tried the following code but I must be missing something.

Looks like this

4 786

123 265

34 123

128 2

I want it to look like this

004 786

123 265

034 123

123 002

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


        For Each c As Char In ListBox1.Items
            Dim i As String = "1234567890"
            Dim count As Integer = 0
            If i.Count = 1 Then
                i.PadLeft(2).ToString()
            ElseIf i.Count = 1 Then
                i.PadLeft(1).ToString()
            End If
        Next

    End Sub

解决方案

Hi

Set the ListBox font to a MonoSpaced Font - such as Courier New or one of the other few.

The reason you are seeing that effect is that most fonts are proportionally spaced and so 3 spaces are not equal in width to 3 'E' characters (for example).

Another option is to use VbTab instead of Padding.


这篇关于在列表框中填充项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆