Weird Thing Building New Form Project

ellpee

Active member
Joined
Apr 16, 2023
Messages
27
Programming Experience
10+
Okay, so first (since I haven't posted in this thread before), total C# newbie, multi-years on VBA but struggling through the early C# learning curve.

So here's my deal this time.
1. created a new Windows Form project, result, empty form.
2. added some controls (widgets if you prefer).
3. double-clicked on several widgets to let the designer write the code for me. Result, two stub methods, one for a textBox (text changed), one for a Button (on-click event).

Realize, up to this point I haven't written a single character of code, the designer did it all. But the textBox stub came out fine, while the Button stub had all sorts of complaints. Following shows both:
C#:
private void textBox3_TextChanged(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{

}
The debugger doesn't like private, diesn't like sender, and doesn't like e. I can post the full text of the error messages for each, but my question is more basic than that: since the designer wrote all this code, not me, why is it unhappy with the result? I didn't change a single thing about all the stuff at the top, using statements, namespace, etc., etc., etc., so I am baffled at why this is happening. No fair, I'm just a beginner! Can anybody 'splain me what's up?
 
Last edited by a moderator:
Solution
Spot on, SkyDiver. Totally my bad. While deleting white space to keep as much code on my screen as possible, I apparently deleted a squiggly bracket unintentionally. After putting it back, all good.
Show us the exact errors. If I were to guess, you may have accidentally deleted the closing curly brace on line 4.
 
OT: Unless it's just a meaningless test, you should not have controls named textBox3 and button1. You should give everything a meaningful name. It's especially important when there are multiple controls of the same type. I've lost count of the number of times things aren't working the way people expect because they are using the wrong control because they accepted the default names that don't mean anything.
 
Spot on, SkyDiver. Totally my bad. While deleting white space to keep as much code on my screen as possible, I apparently deleted a squiggly bracket unintentionally. After putting it back, all good.
 
Solution
Back
Top Bottom