**Please watch in 1080p**
This video demonstrates how to create a message box in C# and how to code the button to perform certain tasks. The syntax is very similar to VB.NET (and presumably C++) – just make sure when doing this in C# that you add the ; to the end of the statement!
—————————————
General Syntax:
If you don’t have already it, add the following namespace to the top of your C# code as shown in the video:
using System.Windows.Forms;
This is a default namespace, so it should be there already!
To create a simple message box, use the following syntax:
MessageBox.Show(“Message Box Text Here”, “Message Box Caption/Title Bar Text Here”, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
You can obviously adapt this code, as shown in the video.
—————————————
Making the buttons execute code using an IF statement and a boolean:
if(MessageBox.Show(“Message Box Text Here”, “Message Box Caption/Title Bar Text Here”, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
{
// code to execute if yes is selected
}
else
{
// code to execute if no is selected
}
Remember that you do no need the ; at the end of an IF statement.
Nguồn:https://wijstaanvooronzegrondrechten.org/