CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Textbox problem

  1. #1
    Join Date
    Feb 2004
    Location
    Seattle, USA
    Posts
    137

    Textbox problem

    I have a textbox that I wanted to use to list errors. However I can't dynamically add newline characters to make each error appear on a new line.

    Here's the code I'm using to add the errors to the textbox
    Code:
    public string[] Errors
    {
    	get
    	{
    		return errors;
    	}
    	set
    	{
    		errors = value;
    		
    		errorLabel.Text = "";
    		foreach ( string error in value )
    		{
    			if ( errorLabel.Text.Length > 0 ) errorLabel.Text += "\n";
    			errorLabel.Text += string.Format( "● {0}", error );
    		}
    		
    		errorLabel.Invalidate();
    	}
    }
    And here's what it looks like:


    AcceptReturn is set to 'true', but that only seems to affect User input rather than being able to programatically add newlines. Seems kinda odd.

    Anyone have any ideas?

  2. #2
    Join Date
    Dec 2004
    Posts
    35

    Re: Textbox problem

    The windows escape sequence is "\r\n", mabye that's it?

  3. #3
    Join Date
    Feb 2004
    Location
    Seattle, USA
    Posts
    137

    Re: Textbox problem

    Yep, that did it. Thanks LiquidShadows.

  4. #4
    Join Date
    Jul 2002
    Location
    India
    Posts
    505

    Re: Textbox problem

    Just an example. Try using the textbox's lines property.

    private void button1_Click(object sender, System.EventArgs e)
    {
    string lstrtest = "this is a test \nthis is line 2 \nand this is line 3";
    textBox1.Lines = lstrtest.Split('\n');
    }

    -Satish

  5. #5
    Join Date
    Sep 2003
    Location
    Argentina....
    Posts
    118

    Re: Textbox problem

    You must use Environtment.NewLine, don't use \n or \r...

    Diego
    My history: QB->VB->TC++->VB->VC++->VC#

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