Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C# (http://www.programmingforums.org/forum16.html)
-   -   Inserting text into a textbox (http://www.programmingforums.org/showthread.php?t=13171)

357mag May 19th, 2007 6:30 AM

Inserting text into a textbox
 
Just fooling around with a simple Windows program. What I'm trying to do is when the user presses a button, a line of text saying "Hello There!" will display in a textbox above the button he just clicked. Here's what I got so far but it's not working:

:

private void button1_Click(object sender, EventArgs e)
        {
            string = "Hello There!";
            textBox1.Text.Insert(0,string);
        }


I've tried lots of different ways to get the text to display in the textbox, but every way fails.

cloud- May 19th, 2007 6:39 AM

:

  1. textBox1.Text = string;


357mag May 19th, 2007 6:41 AM

Ah, I figured out a solution. I failed to create a variable of type string:

:

string text = "Hello There!";
            textBox1.Text = text;


Now it works. But could you tell me why when I'm in the design mode I can't move my form on the screen? It seems locked in one spot, and the Locked Property is already set to false.

Ghost May 19th, 2007 7:01 AM

It is located because the form is just the form, its position on the screen can be changed using a property of the form.

Basically, it is just there in the middle cause it is easy to edit there. Look for the property 'StarPostion' and change that to get your form to start in a new position. Hope that helps.

357mag May 19th, 2007 7:55 AM

Yeah, when I change the property to center screen the form does move to the center during runtime. But it seems to me that I should also be able to have the form where I want it during design time. And I can't change it. Can't move it at all. Its locked over to the left side of the screen. I'd rather have the form in the center of the screen even when I'm in design mode and adding controls to it.

DaWei May 19th, 2007 9:01 AM

Speak to the designers of your form editor.

melbolt May 19th, 2007 1:07 PM

Quote:

Originally Posted by 357mag (Post 128015)
Ah, I figured out a solution. I failed to create a variable of type string:

:

string text = "Hello There!";
            textBox1.Text = text;


Now it works. But could you tell me why when I'm in the design mode I can't move my form on the screen? It seems locked in one spot, and the Locked Property is already set to false.

FYI:
While this works it is by no means necessary. You do not need to have a variable on the right hand side of your assignment operator. A string literal will work just fine.

like so:
:

            textBox1.Text = "Hello There!";


also, I do not understand why you would want to move the form position in the designer?

Booooze May 19th, 2007 1:25 PM

If you want to center it, you can change the width of the solution explorer, and toolbox so it's bigger. it will center your form, but it's a pretty big waste of space. I think your code view will be cut down as well though.

Ghost May 19th, 2007 8:35 PM

Sadly I dont think there is enough demand for what you are asking 357mag. And should it really matter if it is in the middle of the screen or not? It is a relative object and it should matter in my opinion.

Booooze you are correct, you can center it by adjusting the widths of your side tool bars, but you would loose the code area.


All times are GMT -5. The time now is 2:09 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC