❔ 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.
37 Replies
Well, first and foremost, you need to use a Winforms project, not a console project
$newproject
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
Yup created one
But from there on don't know anything
Or how to use the toolbox
Just drag&drop the controls
Okay did that
Nice
But should I add labels as well for the numbers
Like labels to show info infront of price vat and total
Well, you probably want to display that data somehow, so yes
okay should I put any name in for the lable like that or just leave it blank
Names are how you can reference those labels, so yes, they would be useful
I mean currently the labes names are just label 1 to 6
But I meant for the text in the label
Ah, yeah, the text can be empty, or
0
, or whatever elseIf I remove the text in the label how can I click it again
It should still be taking some space in the UI
Okay so is that good?
Looks good to me
Okay
Now how can I connect my code with each label and button
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
Does this mean I set the click event to the button or
Cuz I see two clicks xd
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 doOk
Is this right for the above?
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 eitherF I dunno what I did but crashed
Now I don't even have button click ;w;]
What is good naming for my labels
Is it possible for you to help me in vc
The usual convention is, I believe,
lblName
with Name
being what this label is supposed to show
So lblSum
, lblTotal
, lblUserName
, etcOkay I changed the lbl names to be more readable for the code
But I still don't have the button click option on the determine vat label
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>
Wait, you had an option here, now you no longer do?
Few things happened but now it's solved
Nice
Thanks for the help to you and the others
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.