Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 具有适当间距的可变长度字符串的串联_Vb.net - Fatal编程技术网

Vb.net 具有适当间距的可变长度字符串的串联

Vb.net 具有适当间距的可变长度字符串的串联,vb.net,Vb.net,我所做的就是在变量之间手动插入空格。虽然它可以工作,但是如果变量有点长,它会向右移动。以下是我所做的编码 lstOutput.Items.Add("Items Quantity Prices") lstOutput.Items.Add("Pizza Slices

我所做的就是在变量之间手动插入空格。虽然它可以工作,但是如果变量有点长,它会向右移动。以下是我所做的编码

lstOutput.Items.Add("Items                                         Quantity                                         Prices")
lstOutput.Items.Add("Pizza Slices                                   " & quanPizza & "                                             " & FormatCurrency(pricePizza, 2))
lstOutput.Items.Add("Fries                                               " & quanFries & "                                             " & FormatCurrency(priceFries, 2))
lstOutput.Items.Add("Soft Drinks                                    " & quanSoftDrinks & "                                             " & FormatCurrency(priceSoftDrinks, 2))
lstOutput.Items.Add("")
lstOutput.Items.Add("Total                                                                                                " & FormatCurrency(totalPrice, 2))

这里是变量有点长的时候

如何使其保持在列中?

您可以使用它按预期格式化字符串。如下所示:

lstOutput.Items.Add("Items".PadRight(30) & "Quantity".PadRight(30) & "Prices".PadRight(30))
lstOutput.Items.Add("Pizza Slices".PadRight(30) & quanPizza.PadRight(30) & FormatCurrency(pricePizza, 2).ToString().PadRight(30))

这是给你的。

你会考虑使用ListVIEW或DATAGIDVIEW吗?唯一的方法是在使用比例字体的ListBox中的列中对齐文本,以设置物理标签位置,使用(考虑到部件的平均长度来衡量,你可以看到一个例子)。你可能不想那样。正如建议的那样,使用列表视图:没有计算,没有奇怪的填充,没有麻烦。