C
C#15mo 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
Angius15mo ago
Well, first and foremost, you need to use a Winforms project, not a console project $newproject
MODiX
MODiX15mo 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 WuxianOP15mo ago
Yup created one But from there on don't know anything Or how to use the toolbox
Angius
Angius15mo ago
Just drag&drop the controls
Wei Wuxian
Wei WuxianOP15mo ago
No description
Wei Wuxian
Wei WuxianOP15mo ago
Okay did that
Angius
Angius15mo ago
Nice
Wei Wuxian
Wei WuxianOP15mo ago
But should I add labels as well for the numbers Like labels to show info infront of price vat and total
Angius
Angius15mo ago
Well, you probably want to display that data somehow, so yes
Wei Wuxian
Wei WuxianOP15mo ago
okay should I put any name in for the lable like that or just leave it blank
No description
Angius
Angius15mo ago
Names are how you can reference those labels, so yes, they would be useful
Wei Wuxian
Wei WuxianOP15mo ago
I mean currently the labes names are just label 1 to 6 But I meant for the text in the label
Angius
Angius15mo ago
Ah, yeah, the text can be empty, or 0, or whatever else
Wei Wuxian
Wei WuxianOP15mo ago
If I remove the text in the label how can I click it again
Angius
Angius15mo ago
It should still be taking some space in the UI
Wei Wuxian
Wei WuxianOP15mo ago
Okay so is that good?
No description
Angius
Angius15mo ago
Looks good to me
Wei Wuxian
Wei WuxianOP15mo ago
Okay Now how can I connect my code with each label and button
Angius
Angius15mo 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 WuxianOP15mo ago
Does this mean I set the click event to the button or
No description
Wei Wuxian
Wei WuxianOP15mo ago
Cuz I see two clicks xd
Angius
Angius15mo 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 WuxianOP15mo ago
Ok
Wei Wuxian
Wei WuxianOP15mo ago
Is this right for the above?
No description
Angius
Angius15mo 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 WuxianOP15mo ago
F I dunno what I did but crashed
Wei Wuxian
Wei WuxianOP15mo ago
Now I don't even have button click ;w;]
No description
Wei Wuxian
Wei WuxianOP15mo ago
What is good naming for my labels Is it possible for you to help me in vc
Angius
Angius15mo 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 WuxianOP15mo ago
Okay I changed the lbl names to be more readable for the code
No description
No description
No description
Wei Wuxian
Wei WuxianOP15mo ago
But I still don't have the button click option on the determine vat label
No description
Wei Wuxian
Wei WuxianOP15mo 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
Angius15mo ago
Wait, you had an option here, now you no longer do?
Wei Wuxian
Wei WuxianOP15mo ago
Few things happened but now it's solved
Angius
Angius15mo ago
Nice
Wei Wuxian
Wei WuxianOP15mo ago
Thanks for the help to you and the others
Accord
Accord15mo 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.
Want results from more Discord servers?
Add your server