CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2009
    Posts
    10

    Issues with columns

    How do you put the text into columns? When my numbers get to high on my program it ignores the spaces... How do I align the text into columns? My code is here. generation, multiplier, starting are all input text boxes and Output is my output textbox.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;


    namespace WindowsFormsApplication1
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
    int gen, multi, start, curgen;
    double hold;
    double easy = 0.0F;
    if (generation.Text != null || multiplier.Text != null || starting.Text != null)
    {
    gen = System.Int32.Parse(generation.Text);
    multi = System.Int32.Parse(multiplier.Text);
    start = System.Int32.Parse(starting.Text);

    double[,] total = new double[gen, 4];
    Output.Text += "Starting New Run!!! \r\n";
    for (curgen = 0; curgen < gen; curgen++)
    {
    hold = (start * multi*( Math.Pow((multi + 1),curgen)) );
    total[curgen, 0] = hold;
    easy += hold;
    total[curgen, 1] = easy;
    total[curgen, 2] = easy + start;
    total[curgen, 3] = Math.Pow(multi, curgen);

    Output.Text += "G " + (curgen + 1) + "\t\t" + total[curgen, 0] +"\t\t" + total[curgen, 1] + "\t\t" + total[curgen, 2] + "\t\t" + total[curgen, 3] + "\r\n";
    }
    }



    }

    private void button2_Click(object sender, EventArgs e)
    {
    Output.Text = " ";
    }

    }
    }

  2. #2
    Join Date
    Nov 2009
    Location
    .net 3.5 csharp 2008 developer
    Posts
    36

    Re: Issues with columns

    I guess you could use the PadLeft and PadRight functions of string.

    So in your code you could do something like:
    Code:
    Output.Text += "G " + (curgen + 1).ToString().PadLeft(10) + "\t\t" + total[curgen, 0].ToString().PadLeft(10) +"\t\t" + total[curgen, 1].ToString().PadLeft(10) + "\t\t" + total[curgen, 2].ToString().PadLeft(10) + "\t\t" + total[curgen, 3].ToString().PadLeft(10) + "\r\n";
    I'm sure it could be done more elegantly, but it is almost 2.30am and I'm sleepy

  3. #3
    Join Date
    Dec 2009
    Posts
    10

    Re: Issues with columns

    Yeah I figured that. Thats why I posted this.....

  4. #4
    Join Date
    Nov 2009
    Location
    .net 3.5 csharp 2008 developer
    Posts
    36

    Re: Issues with columns

    No need to be all snarky about it.

    Given it is a rather trivial thing using PadLeft to make "columns" in a textbox, do you have any reason not to use a GridView ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured