If you look at the message box we created in the previous section, you'll notice there's no Title in the blue area to the left of the red X - it's blank:
You can add a Title quite easily.
Click OK on your Message Box. Then click the Red X on your programme to exit it. This will return you to Visual C#. Go back to the coding window (press F7 on your keyboard, if you can't see it).Position your cursor after the final double quote of "My First Message", circled in red in the image below:
"Message"
Again, you need the double quotes. But your line of code should look like this:Other Button Options
Rather than having just an OK button, you can add buttons like Yes, No, and Cancel to your C# message boxes. We'll add a Yes and a No button.Return to your coding window. After the second double quote of the Title you've just added, type another comma. Hit the spacebar on your keyboard once, and you'll see the IntelliSense list appear. (If it doesn't appear, just type a capital letter "M").
Run your programme again, and click your button. Your Message Box will then look like this:
Adding Icons to a C# Message Box
Another thing you can add to brighten up your Message Box is an Icon. It's easier to see what these are than to explain!Type another comma after MessageBoxButtons.YesNo. After the comma, type a capital letter "M" again. From the IntelliSense list that appears, double click MessageBoxIcon. After MessageBoxIcon, type a full stop to see the available icons:
No comments:
Post a Comment