如何右对齐标签中的输出?
How do you right align output in a label?
这是我的代码,(GUI 应用程序):
const double TIPSTEP = 0.05;
double dinnerPrice = 10.00;
double tipRate;
double tip;
double lowRate, maxRate, minDinner, maxDinner;
lowRate = Convert.ToDouble(txtLowTip.Text);
maxRate = Convert.ToDouble(txtHighTip.Text);
minDinner = Convert.ToDouble(txtLowDinner.Text);
maxDinner = Convert.ToDouble(txtHighDinner.Text);
lblOutput.Text = " Price";
for (tipRate = lowRate; tipRate <= maxRate; tipRate += TIPSTEP)
lblOutput.Text += String.Format("{0, 8}", tipRate.ToString("F"));
lblOutput.Text += "\n-----------------------------------------------------------------\n";
tipRate = lowRate;
while (dinnerPrice <= maxDinner)
{
lblOutput.Text += String.Format("{0, 8}", dinnerPrice.ToString("C"));
while (tipRate <= maxRate)
{
tip = dinnerPrice * tipRate;
lblOutput.Text += String.Format("{0, 8}", tip.ToString("F"));
tipRate += 0.05;
}
dinnerPrice += minDinner;
tipRate = lowRate;
lblOutput.Text += "\n";
}
我认为我做得对。我首先将其作为控制台应用程序编写,并且它完美地排列在一起。这次数字没有像应该的那样正确对齐,有什么建议吗?
I wrote this first as a console app and it lined up perfectly.
控制台windows使用固定宽度的字体。
当您切换到 Windows GUI 应用程序时,您现在拥有可变宽度字体。 'M' 比 'i' 宽得多。
您可以将标签的字体设置为 Courier 或其他一些固定宽度的字体。
这是我的代码,(GUI 应用程序):
const double TIPSTEP = 0.05;
double dinnerPrice = 10.00;
double tipRate;
double tip;
double lowRate, maxRate, minDinner, maxDinner;
lowRate = Convert.ToDouble(txtLowTip.Text);
maxRate = Convert.ToDouble(txtHighTip.Text);
minDinner = Convert.ToDouble(txtLowDinner.Text);
maxDinner = Convert.ToDouble(txtHighDinner.Text);
lblOutput.Text = " Price";
for (tipRate = lowRate; tipRate <= maxRate; tipRate += TIPSTEP)
lblOutput.Text += String.Format("{0, 8}", tipRate.ToString("F"));
lblOutput.Text += "\n-----------------------------------------------------------------\n";
tipRate = lowRate;
while (dinnerPrice <= maxDinner)
{
lblOutput.Text += String.Format("{0, 8}", dinnerPrice.ToString("C"));
while (tipRate <= maxRate)
{
tip = dinnerPrice * tipRate;
lblOutput.Text += String.Format("{0, 8}", tip.ToString("F"));
tipRate += 0.05;
}
dinnerPrice += minDinner;
tipRate = lowRate;
lblOutput.Text += "\n";
}
我认为我做得对。我首先将其作为控制台应用程序编写,并且它完美地排列在一起。这次数字没有像应该的那样正确对齐,有什么建议吗?
I wrote this first as a console app and it lined up perfectly.
控制台windows使用固定宽度的字体。
当您切换到 Windows GUI 应用程序时,您现在拥有可变宽度字体。 'M' 比 'i' 宽得多。
您可以将标签的字体设置为 Courier 或其他一些固定宽度的字体。