Birdman
Birdman

Reputation: 1524

Issue outputting text to textBox (WinForms)

It's my first time using winforms. I'm having some issues.

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

        private void TextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Text = "FORM1";
            textBox1.AppendText("SOME TEXT");
        }
    }

I've tried this. My textbox is set to fill so it fills up the whole form. I set the multi-line propery to true and dock property to fill.

From what I can try as a first time WinForms user, the Form1_Load should run as soon as the form is created. I've tried some various ways to print text, nothing works. I noticed visual studios says "0 references" next to my function. I'm not sure what this means, maybe part of my issue? Please help.

enter image description here

enter image description here

Upvotes: 0

Views: 243

Answers (2)

AyrtonSenna
AyrtonSenna

Reputation: 79

Have you checked following things are done in properties:

Go to Form1->Properties window and check for events. Now check for Load event and it should be attached to your Form1_Load method.

enter image description here

Upvotes: 1

Michał Turczyn
Michał Turczyn

Reputation: 37367

Having 0 references to method means that it's never used in code. So your issue is that you defined method, which looks like should be executed on form load event, but it's just the definition. I suggest that you copy body of your method to clipboard, go to design page of your form, on the right side, you can browse events, that form generates, find Load event, double-click it, Visual Studio should generate code with empty method definition, paste there your code.

When you right-click your method name and click Find all references you should get something like this at the bottom:

enter image description here

Upvotes: 3

Related Questions