C
C#9mo ago
Wei Wuxian

❔ windows form

Hi I just started learning c# in school since last week and I have to use my code via windows forms but I'm not sure how to connect my code with each label and button, if anything I would appreciate some advices or help how to do it. Here's a picture of the code I did and a picture of how the form should look like.
No description
No description
37 Replies
Angius
Angius9mo ago
Well, first and foremost, you need to use a Winforms project, not a console project $newproject
MODiX
MODiX9mo ago
When creating a new project, prefer using .NET over .NET Framework, unless you have a very specific reason to be using .NET Framework. .NET Framework is now legacy code and only get security fix updates, it no longer gets new features and is not recommended. https://cdn.discordapp.com/attachments/569261465463160900/899381236617855016/unknown.png
Wei Wuxian
Wei Wuxian9mo ago
Yup created one But from there on don't know anything Or how to use the toolbox
Angius
Angius9mo ago
Just drag&drop the controls
Wei Wuxian
Wei Wuxian9mo ago
No description
Wei Wuxian
Wei Wuxian9mo ago
Okay did that
Angius
Angius9mo ago
Nice
Wei Wuxian
Wei Wuxian9mo ago
But should I add labels as well for the numbers Like labels to show info infront of price vat and total
Angius
Angius9mo ago
Well, you probably want to display that data somehow, so yes
Wei Wuxian
Wei Wuxian9mo ago
okay should I put any name in for the lable like that or just leave it blank
No description
Angius
Angius9mo ago
Names are how you can reference those labels, so yes, they would be useful
Wei Wuxian
Wei Wuxian9mo ago
I mean currently the labes names are just label 1 to 6 But I meant for the text in the label
Angius
Angius9mo ago
Ah, yeah, the text can be empty, or 0, or whatever else
Wei Wuxian
Wei Wuxian9mo ago
If I remove the text in the label how can I click it again
Angius
Angius9mo ago
It should still be taking some space in the UI
Wei Wuxian
Wei Wuxian9mo ago
Okay so is that good?
No description
Angius
Angius9mo ago
Looks good to me
Wei Wuxian
Wei Wuxian9mo ago
Okay Now how can I connect my code with each label and button
Angius
Angius9mo ago
https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/how-to-add-an-event-handler?view=netdesktop-7.0 here's how to add a click event to the button Then you would write your code in that event handler method
Wei Wuxian
Wei Wuxian9mo ago
Does this mean I set the click event to the button or
No description
Wei Wuxian
Wei Wuxian9mo ago
Cuz I see two clicks xd
Angius
Angius9mo ago
Well, seems like you have two methods that can handle the click Or you have one, and it asks if you want to create another one button1_Click should do
Wei Wuxian
Wei Wuxian9mo ago
Ok
Wei Wuxian
Wei Wuxian9mo ago
Is this right for the above?
No description
Angius
Angius9mo ago
This is an event handler for when the user inputs something into that textbox, I believe If you need it, sure, use it But maybe name the handler in a way that makes sense. It's not label1 whose event you're handling, and it's not a Click event you're handling either
Wei Wuxian
Wei Wuxian9mo ago
F I dunno what I did but crashed
Wei Wuxian
Wei Wuxian9mo ago
Now I don't even have button click ;w;]
No description
Wei Wuxian
Wei Wuxian9mo ago
What is good naming for my labels Is it possible for you to help me in vc
Angius
Angius9mo ago
The usual convention is, I believe, lblName with Name being what this label is supposed to show So lblSum, lblTotal, lblUserName, etc
Wei Wuxian
Wei Wuxian9mo ago
Okay I changed the lbl names to be more readable for the code
No description
No description
No description
Wei Wuxian
Wei Wuxian9mo ago
But I still don't have the button click option on the determine vat label
No description
Wei Wuxian
Wei Wuxian9mo ago
What should I do I'm in dev vc 1 if it's easier to share screen so I can learn and see what to do with the code <a:cat_cri:1115006734776418314>
Angius
Angius9mo ago
Wait, you had an option here, now you no longer do?
Wei Wuxian
Wei Wuxian9mo ago
Few things happened but now it's solved
Angius
Angius9mo ago
Nice
Wei Wuxian
Wei Wuxian9mo ago
Thanks for the help to you and the others
Accord
Accord9mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.