C
C#2w ago
Nightswyng

✅ Addition Tutor Program

So the program is supposed to generate two random numbers and then the user inputs the answer, once the check answer is clicked it will say if its incorrect or correct. I can't get the numbers(num1 box and num2 box) to show up first for the user. I have to put in a number without knowing to get the rest of the program to continue. What am I missing? (My college book is outdated just FYI) https://paste.mod.gg/wxmeinkktnjr/0
BlazeBin - wxmeinkktnjr
A tool for sharing your source code with the world!
20 Replies
Anchy
Anchy2w ago
You want to subscribe to the OnLoad event for your form and then populate your textboxes from there, at the moment you are only populating them when you click the check button
Nightswyng
NightswyngOP2w ago
I am not sure I understand
Anchy
Anchy2w ago
when your form (the window) has finished loading, you need to populate the first and second text box yes?
Nightswyng
NightswyngOP2w ago
Yes
Anchy
Anchy2w ago
right, so you need to subscribe / listen to the form load event which is fired when your form (the window) has finished loading inside of that callback you need to place your code to fill in those two text boxes I believe you can add a listener from the form designer page, in events something along the lines of: - open the designer (form preview) - click on the form (the window) - go to the properties section - click the events tab (I think it's a lightning icon?) - double click the form load event to generate the callback function - place your code in that callback function its been a hot minute since I've used winforms
Nightswyng
NightswyngOP2w ago
Unfortuantely, I am not seeing anything like that, there is load but its only give my 3 original options, not a call back
Nightswyng
NightswyngOP2w ago
No description
Nightswyng
NightswyngOP2w ago
would it be easier to add a generate button, to "start" the program and achieve what i am looking for?
Anchy
Anchy2w ago
double click the blank area next to load and it should generate it for you it should generate a callback in your code-behind similar to additionTutor_Load(object? sender, EventArgs e)
Nightswyng
NightswyngOP2w ago
it added that to the bottom
No description
Anchy
Anchy2w ago
right, so this is the callback function that will be called when the form has/is loading, you can run your code here to populate those two text boxes make sure you remove the code to populate those textboxes from the button click, otherwise they will be regenerated when you want to check the answer
Nightswyng
NightswyngOP2w ago
oh ok! and i want that at the bottom of my code?
Anchy
Anchy2w ago
the callback can sit anywhere in your code-behind file as far as I know, the Designer has its own file something along the name of Form.Designer.cs which is generated by the designer this is where the event is subscribed to I believe this is a partial class, so this designer file can see your callback in your code-behind file
Nightswyng
NightswyngOP2w ago
it does say public partial class at the top
Anchy
Anchy2w ago
yeah, you shouldnt change anything in this file however because it is generated there is no guarantee that the changes will stay in there
Nightswyng
NightswyngOP2w ago
ok, since i am still learning, I know with other coding programs, you can use a display code, is there something like that in C# or is that very dependant on what is being worked on? similar to MessageBox.show
Anchy
Anchy2w ago
I am not sure what you mean
Nightswyng
NightswyngOP2w ago
I am not sure how to explain it, not even sure myself since I am learning a new program each semester i guess, like in python print is the display, is there something similar or is that the .text
Anchy
Anchy2w ago
if you want a quick way to just display some text on the screen you could use MessageBox.Show, yes
Nightswyng
NightswyngOP2w ago
ok, thats what i was originally unclear on, the book was confusing me with the resources available online I got it to generate thank you so much! Just need to tweak a few things and I am all set!

Did you find this page helpful?