【问题标题】:MessageBox not showing any text in C SharpMessageBox 在 C Sharp 中不显示任何文本
【发布时间】:2011-04-22 03:20:59
【问题描述】:

我的消息框应该会弹出并询问用户是否要下载应用程序的新版本,如果他们说不,它会退出并告诉他们需要下载新副本才能继续。如果他们说是,它会打开浏览器访问上述网址。现在,弹出消息框,什么也没有出现。但是,每当我将代码提供给我的朋友并且他尝试过时,它就起作用了。这里有什么问题?我使用 Microsoft Framework 4.0 编译。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ProjectTest
{
   public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        Form1_FormClosing();
    }

    private void Form1_FormClosing()
   {
   const string message =
    "There's an updated version of this program available. Would you like to download now?";
const string caption = "Please update";
var result = MessageBox.Show(message, caption,
                             MessageBoxButtons.YesNo,
                             MessageBoxIcon.Question);

// If the no button was pressed ...
if (result == DialogResult.No)
{
    MessageBox.Show("Program will close now. If you want to use this program please update to the newest version.", "Please update");
    this.Close();
}
else if (result == DialogResult.Yes)
{
    System.Diagnostics.Process.Start("http://www.google.com");
    this.Close();
}
}

    }
}

【问题讨论】:

  • 您的代码似乎应该可以工作。你给它的朋友,他和你运行的是同一个操作系统吗?小部件的大小和样式因版本而异,导致显示方式不同。
  • 问题是,我在 Windows 7 上使用 Visual Studio 2008 和 2010 运行并编译了它,但它不起作用。然后我在 XP 上使用 VS 2010 运行它,但它仍然无法正常工作。试过4.0和3.5,还是不行。现在不知所措。
  • 我进行了更改,但消息框仍然显示为空白。
  • 你可以尝试在Process.Start中使用'@'字符串文字吗
  • 您是说消息框中什么都没有显示,或者网络浏览器没有出现?

标签: c#


【解决方案1】:

试试这个:

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ProjectTest
{
   public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        this.Close();
    }

    private void Form1_FormClosing()
   {
   const string message =
    "There's an updated version of this program available. Would you like to download now?";
const string caption = "Please update";
var result = MessageBox.Show(message, caption,
                             MessageBoxButtons.YesNo,
                             MessageBoxIcon.Question);

// If the no button was pressed ...
if (result == DialogResult.No)
{
    MessageBox.Show("Program will close now. If you want to use this program please update to the newest version.", "Please update");
                e.Cancel = false;
}
else if (result == DialogResult.Yes)
{
    System.Diagnostics.Process.Start("http://www.google.com");
                e.Cancel = false;
}
}

    }
}

【讨论】:

  • 错误 1 ​​需要类、委托、枚举、接口或结构
  • 好的~我发布了整个代码,我想你可能会丢失一些“}”或其他符号或错误的命名空间来获取这些错误消息。 错误 1 ​​预期的类、委托、枚举、接口或结构
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多