C#表单应用程序 - 检索通知图标文件app.config

时间:2014-03-12 19:39:43

标签: c# path ico

我正在尝试开发一个到目前为止工作正常的Windows窗体应用程序。 我有4个app.config文件,我正确配置了所有内容。

当我尝试获取通知图标的密钥时出现问题。

我总是收到一条消息,说它无法将字符串转换为Drawing.Icon。 有人可以给我一个暗示吗?

App.config中:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="customer" value="Customer" />
    <add key="link" value="http://link.i.need" />
    <add key="icopath" value="Properties.Resources.firstlogo" />
  </appSettings>
</configuration> 

功能正常的表格:

private void formresize(object sender, EventArgs e)
        {
            if (WindowState == FormWindowState.Minimized)
            {
                ShowInTaskbar = true;
                notification.Visible = true;
                notification.BalloonTipText = "running in background...";
                **System.Drawing.Icon ico = Properties.Resources.firstlogo;**
                notification.Icon = ico;
                notification.ShowBalloonTip(1000);
            }
        }

表格不是:

private void formresize(object sender, EventArgs e)
        {
            if (WindowState == FormWindowState.Minimized)
            {
                ShowInTaskbar = true;
                notification.Visible = true;
                notification.BalloonTipText = "running in background...";
                **System.Drawing.Icon ico = ConfigurationManager.AppSettings["icopath"].ToString();**
                notification.Icon = ico;
                notification.ShowBalloonTip(1000);
            }
        }

谢谢。

1 个答案:

答案 0 :(得分:0)

试试这个:

System.Drawing.Icon ico = (System.Drawing.Icon)Properties.Resources.ResourceManager.GetObject(ConfigurationManager.AppSettings["icopath"].ToString());

谢谢, 埃里克