Inserting image in a message box

37,654

Quick and dirty way to achieve this is to create another windows form that will have same buttons as message box but that will also have an image.

enter image description here

  • Create public Boolean property in this form that will be named something like OKButtonClicked that will tell you whether OK or Cancel was clicked
  • Set ControlBox property to False so that minimize, maximize and close buttons are not shown

Here is a code behind for this form

public partial class MazeForm : Form
{
    public MazeForm()
    {
        InitializeComponent();
    }

    private bool okButton = false;

    public bool OKButtonClicked
    {
        get { return okButton; }
    }

    private void btnOK_Click(object sender, EventArgs e)
    {
        okButton = true;
        this.Close();
    }

    private void btnCancel_Click(object sender, EventArgs e)
    {
        okButton = false;
        this.Close();
    }
}

Finally in your main form you can do something like this

MazeForm m = new MazeForm();
m.ShowDialog();

bool okButtonClicked = m.OKButtonClicked;

Note that this is something I quickly created in 15 min and that it probably needs more work but it will get you in the right direction.

Share:
37,654
Azul_Echo
Author by

Azul_Echo

I don't like assholes. If you don't have anything helpful or nice to say then don't talk. The know-it-all pricks that live their lives on this site are the reason I try to avoid it.

Updated on February 06, 2020

Comments

  • Azul_Echo
    Azul_Echo about 4 years

    I was wondering how I would make an image appear inside a messagebox that I set up so that whenever the mouse enters a label, it displays the messagebox. What would the code be for the image insertion?