【发布时间】:2018-08-15 01:20:44
【问题描述】:
我是 C# 和 Visual Studio 的新手。我编写了一个简单的表单应用程序,在调试时效果很好。当我构建并运行 exe 时,一切正常,除了 MessageBox.Show() 没有弹出任何消息。所以我用一个表单、一个按钮和一个事件处理程序构建了一个新项目。
果然。使用 Start With Debugging 时会弹出消息框。
当我使用 Start without Debugging 单击按钮时没有任何反应。
一些研究指出:
[ComVisibleAttribute(true)]
public enum UIPermissionWindow { AllWindows }
我添加了它,但仍然没有从任何消息框中弹出。 该项目尽可能地用于故障排除。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
[ComVisibleAttribute(true)]
public enum UIPermissionWindow { AllWindows }
namespace Form462
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) => MessageBox.Show("Help!");
}
}
【问题讨论】:
-
您使用的是哪个环境?视觉工作室 2017?如果手动执行Debug文件夹下的.exe文件,是否有效?
-
当我从 Debug 文件夹运行 exe 时。表单会加载,但是当您单击按钮时,不会出现任何消息框。在 VS 中通过调试运行它,单击按钮会按预期弹出窗口。
-
我看到了,1 条消息。消息 IDE1006 命名规则违规:这些单词必须以大写字符开头:button1_Click
-
将其更改为
=> Close();并检查表单是否关闭。如果是这样,那么问题出在消息框上。如果没有,它甚至不会调用您的方法。但我想不出那个弹出窗口不显示的原因。你有多显示器设置吗? -
我想知道它是否弹出屏幕
标签: c# visual-studio