简体   繁体   English

如何在Visual Basic 2010 Express中使用组合框更改msgbox上的按钮?

[英]How to change buttons on a msgbox using a combo box in visual basic 2010 express?

I want to display a msgbox that contains information provided by a combo box . 我想显示一个包含组合框提供的信息的msgbox Specifically, if the combo box contains "Warning" I want the msgbox to display the warning icon. 具体来说,如果组合框包含“警告”,则希望msgbox显示警告图标。

Basically I need to know how to put the input from the combo box into the msgbox without having to make it have MsgBoxStyle.Critical or something like that. 基本上,我需要知道如何将组合框的输入放入msgbox,而不必使其具有MsgBoxStyle.Critical或类似的东西。

What I thought would work: 我认为可行:

Private Sub Button1_Click(ByVal sender As system.object, ByVal e As System.EventArgs) Handles Button1.Click

If ComboBox1.SelectedItem = "Warning" Then
   ComboOutput = Msgboxstyle.critical

Hopefully my question is clear. 希望我的问题很清楚。

The following should work: 以下应该工作:

We load all the enum values on form load. 我们在表单加载时加载所有枚举值。 Then on click we parse the name and display the message box. 然后单击,我们解析名称并显示消息框。

Private Sub Form5_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    ComboBox1.DataSource = [Enum].GetNames(GetType(MessageBoxIcon))
End Sub

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim value = [Enum].Parse(GetType(MessageBoxIcon), CStr(ComboBox1.SelectedItem))
    MessageBox.Show("Text", "Caption", MessageBoxButtons.OK, CType(value, MessageBoxIcon))
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM