Apply changes to mainforms Form.Icon at runtime

后端 未结 4 1006
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-07 01:57

I have a System.Windows.Forms.Form and want to change the Form.Icon at runtime to display a status. I\'ve managed to load the icon from the projects ressources:



        
4条回答
  •  一个人的身影
    2020-12-07 02:26

    Ok, Siva and Hans where right: GetObject returned null, because the name of the ressource wasn't right. With the following change it works:

    Type type = this.GetType(); 
    System.Resources.ResourceManager resources = 
    new System.Resources.ResourceManager(type.Namespace + ".Properties.Resources", this.GetType().Assembly);
    
    // here it comes, call GetObject just with the resource name, no namespace and no extension
    this.Icon = (System.Drawing.Icon)resources.GetObject(statusText); 
    

    Thanks for all your help.

提交回复
热议问题