When we are developing applications then sometimes we need to show message. In both C# and vb.net it is possible to show a message. There are two type of messages that I am going to explain and you will find the code of example in both C# and vb.net.
- Simple Message
- Message Box Result Option
Here you will find the way. How and where we can use these two?
Simple Message: Simple message is a message which tells to user that you have done a particular thing. On this message box there is not one button named "OK".
How can you use this (Simple Message)?C#
this.ShowMessageBox("You
message will be there");
vb.net
Me.ShowMessageBox("Your message will be there")
Message Box Result Option: Message box result option is providing options to users. It provides the four options. These are as follow.
In this message option, user will get the option to perform action on the base of selected option. There may be more than 1 button options but not more than 3 buttons these button will work differently. I am going to take an example of two buttons.
How can you use this (Message Box Option)?
Before going to use this you have to Import a namespace ("System.Windows").
C#
using System.Windows;
Code:
dynamic MsgResult = this.ShowMessageBox("Do you want to cancel all pending changes ?",
"Cancel Changes", MessageBoxOption.YesNo);
// in the place of dynamic we can also use System.Windows.MessageBoxResult
if (MsgResult == System.Windows.MessageBoxResult.Yes)
{
// Perform your action
on the click on Yes button
}
else
{
// Perform your action
on the click on No button
}
vb.net
Imports System.Windows
Code:
Dim MsgResult As
System.Windows.MessageBoxResult = Me.ShowMessageBox("Do you want to cancel all pending changes ?",
"Cancel Changes", MessageBoxOption.YesNo)
If MsgResult = MessageBoxResult.Yes Then
// Perform your action on
the click on Yes button
Else
// Perform your action
on the click on No button
End If
1 comment:
Great
C# Training
Post a Comment