C# 在消息框中插入图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18907190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Inserting image in a message box
提问by Azul_Echo
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?
我想知道如何使图像出现在我设置的消息框内,以便每当鼠标进入标签时,它就会显示消息框。图像插入的代码是什么?
采纳答案by JdMR
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.
实现这一目标的快速而肮脏的方法是创建另一个窗口窗体,该窗体将具有与消息框相同的按钮,但也将具有图像。
- 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
- 以这种形式创建公共布尔属性,该属性将命名为 OKButtonClicked 之类的东西,它会告诉您是单击了确定还是取消
- 将 ControlBox 属性设置为 False,以便不显示最小化、最大化和关闭按钮
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.
请注意,这是我在 15 分钟内快速创建的内容,它可能需要更多的工作,但它会让您朝着正确的方向前进。