【问题标题】:Config file - help in trying to get it to work with paths and Mouse hover配置文件 - 帮助尝试使其与路径和鼠标悬停一起使用
【发布时间】:2014-08-19 15:38:54
【问题描述】:

我在尝试让我的 Windows 窗体应用程序与配置文件一起工作时遇到问题,我在这里和其他地方阅读了很多帖子,但我仍然无法弄清楚如何让它工作,因此我的问题在这里,我正在开发我的第一个应用程序。我已将 Configuration.Manager .dll 添加到我的项目中。我也试图通过配置文件路径让 MouseHover 工作。

配置文件是这样读取的

<configuration>
  <appSettings>
    <add key="Google" value="http://www.google.com/"/>
   </appSettings>
</configuration>

应用中的前一个路径字符串

//public static string Google = @"http://www.google.com/";

下面的第一行运行良好。

//System.Diagnostics.Process.Start(Google);

但这我根本无法工作,我尝试了各种示例。

System.Diagnostics.Process.Start(ConfigurationManager.AppSettings["Google"]);

一起编码

private void GoogleW_Click(object sender, EventArgs e)
{
  try
  {
    //System.Diagnostics.Process.Start(Google);
    System.Diagnostics.Process.Start(ConfigurationManager.AppSettings["Google"]);
  }
  catch (Exception e)
        {
            MessageBox.Show(e.Message);
        }
 }

与鼠标悬停相同,它适用于

//ToolTip1.SetToolTip(this.GoogleW, @Google);

但不是这样,我找不到任何说明您可以将配置文件用于鼠标悬停文本。

ToolTip1.SetToolTip(this.GoogleW, (ConfigurationManager.AppSettings["Google"]));

一起编码

private void GoogleW_MouseHover(object sender, EventArgs e)
{
  System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
  //ToolTip1.SetToolTip(this.GoogleW, @Google);
  ToolTip1.SetToolTip(this.GoogleW, (ConfigurationManager.AppSettings["Google"]));

【问题讨论】:

  • 您在上面有多个 explorer.exe (exploror.exe) 的拼写 - 我也认为您的意思是 iexplore.exe
  • 空的 Try-Catch 并不能帮助您查看代码中发生的情况。您必须描述“不工作”的含义。确保您的活动已连接。
  • @LarsTech 感谢您的回复,我在应用程序的其他地方确实有一些填充的 Try-Catch 块,代表我的草率编程没有在这里上传完整的代码......
  • @ajg 拼写错误是由于凌晨 1 点 30 分输入代码造成的……我将上面的代码更改为链接到 Google,因为我的应用程序实际上指向了工作地点。我打开了 explorer.exe 的 UNC 路径,是的 iexplore.exe 可能用于 Web 链接,但我会忽略它,以便用户默认浏览器打开页面。
  • @LarsTech 我得到的错误是 - 无法启动进程,因为没有提供文件名......所以似乎配置文件中的密钥没有被拾取。 google.com/">; Process.Start(ConfigurationManager.AppSettings["Google"]);

标签: c# winforms config mouseover


【解决方案1】:

您是否尝试在您的web.config 文件中添加http://www.google.com/ 而不是www.google.com/

更新:也正如上面@ajg 提到的,它是explorer.exe 而不是exploror.exe

【讨论】:

  • 谢谢,我会尝试 (app.config) 文件中的完整路径。拼写错误已排序。
【解决方案2】:

您确实不需要指定进程的名称,除非您特别需要打开 Internet Explorer,而不是系统默认的 Web 浏览器。我个人讨厌程序强制打开 Internet Explorer,而不是我的默认浏览器。

Process.Start(ConfigurationManager.AppSettings["Google"]);

【讨论】:

  • 同意“我个人讨厌程序强制打开 Internet Explorer,而不是我的默认浏览器。”我将免费提供特定于代码浏览器的代码。
【解决方案3】:

搞定了!

App.config 文件

<add key="Google"  value="http://www.google.com/" />

代码

private void GoogleS_Click(object sender, EventArgs e)
        {
            try
            {
                //MessageBox.Show(ConfigurationManager.AppSettings["Google"]);
                string GoogleS = ConfigurationManager.AppSettings["Google"];
                Process.Start(GoogleS);
            }
            catch (Exception GoogleErr)
            {
                MessageBox.Show(GoogleErr.Message);
            }
        }

        private void GoogleS_MouseHover(object sender, EventArgs e)
        {
            System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
            ToolTip1.SetToolTip(this.GoogleS, (ConfigurationManager.AppSettings["Google"]));
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-02
    • 2018-10-09
    • 1970-01-01
    • 2012-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多