Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting image in a message box

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?

like image 477
Azul_Echo Avatar asked Mar 22 '23 08:03

Azul_Echo


1 Answers

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.

like image 78
JdMR Avatar answered Apr 01 '23 03:04

JdMR