KuysChan
KuysChan

Reputation: 1

C# Forms | Code for Metro Framework Message Box Button

How can I put a code that will be executed when I click a Button in MetroFramework Message Box. I am still learning how to use hte framework. I found it difficult because unlike the regular Message Box, you can code through the use of Dialog Result. But I don't know if it has a counterpart in the Metro Framework. Thanks in advance! :)

Below is my code. I don't know how can I make an If Statement from the YesNo button.

 MetroFramework.MetroMessageBox.Show(this, "\n\nContinue Logging Out?", "EMPLOYEE MODULE | LOG OUT", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

Upvotes: 0

Views: 19155

Answers (4)

Zunaid Hossain
Zunaid Hossain

Reputation: 1

    private void hand_Click(object sender, EventArgs e)
    {
        MetroFramework.MetroMessageBox.Show(this, "OK", "message", MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
    private void button2_Click_2(object sender, EventArgs e)
    {
        MetroFramework.MetroMessageBox.Show(this, "OK", "message", MessageBoxButtons.YesNo, MessageBoxIcon.Stop);
    }

    private void btninformation_Click(object sender, EventArgs e)
    {
        MetroFramework.MetroMessageBox.Show(this, "Data saved successfully. \n Thank You.", "Successfull", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }

for more info : see this link : https://www.youtube.com/watch?v=WzVNRsssG5I&list=PLB2zkXAmYx8qrLCll1jJqAo8aJzsks1S5&index=3&t=339s

Upvotes: 0

Joshua Dela Cruz
Joshua Dela Cruz

Reputation: 235

First you need to use the reference of the MetroFramework. This code will let you insert your MetroFramework UI events like MetroMessageBoxwithout typing the whole code extension again on the same form.

using MetroFramework;
using MetroFramework.Forms;

Then insert this code:

DialogResult dr = MetroMessageBox.Show(this, "\n\nContinue Logging Out?", "EMPLOYEE MODULE | LOG OUT", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if(dr == DialogResult.Yes)
{
     YourEventsHere;
}
else
{
     YourElseEvents;
}

Hope this helps. Thanks!

Upvotes: 3

reformed
reformed

Reputation: 4790

Use DialogResult just like MessageBox:

var result = MetroFramework.MetroMessageBox.Show(
    this,
    "\n\nContinue Logging Out?", "EMPLOYEE MODULE | LOG OUT",
    MessageBoxButtons.YesNo,
    MessageBoxIcon.Question
);

if (result == DialogResult.Yes)
{
    // Do Yes stuff
}
else
{
    // No stuff
}

Upvotes: 0

Gabriel GM
Gabriel GM

Reputation: 6639

MetroMessageBox function exactly the same as a normal MessageBox. Only the skin is different. You have to use the DialogResult.

Here is it's source code :

public sealed class MetroMessageBox : MetroForm

If DialogResult is not enough, then you have to create your own form.

Upvotes: 0

Related Questions