2016-10-23 43 views
0

我已經從.dll加載窗體窗體,它顯示正確,我可以執行該.dll中創建的方法。從DLL實例化的窗體上不更新標籤文本

Main window with Form1 window opened (from the dll)

注意在Form1窗口的文本標籤。在我的主窗口中,單擊調試,然後選擇一個應該將文本標籤更改爲另一個字符串的選項。但是字符串拒絕改變。我已經檢查過Form1中的方法正在觸發,並且label.text已被更改,但顯示從未改變。

注意:這也發生在我測試過的其他控件(文本框/列表框等​​)。

public void Command(string cmd, string param1, string param2, string param3) 
     { 
      if (cmd == "TEST") 
      { 
       this.label1.Text = "This should now change"; 
       MessageBox.Show("DONE"); 
      } 
     } 

MessageBox中顯示爲預期,label.text發生了變化,所有事件觸發正確的(我創建了一個點擊事件,其作品標籤),它只是似乎該標籤實際上並沒有更新。我也試過在標籤上使用Refresh。

如果可能的話,還有一個問題:)是否有一種特殊的方式可以在我可以提供給Form1的主窗體上創建一個回調?我設想的某種代表?

我從DLL加載這樣

try 
    { 
     Type interfaceType = typeof(IPlugin); 
     // Fetch all the types that implement the interface IPlugin and are a class 
     Type[] types = AppDomain.CurrentDomain.GetAssemblies() 
      .SelectMany(a => a.GetTypes()) 
      .Where(p => interfaceType.IsAssignableFrom(p) && p.IsClass) 
      .ToArray(); 
     foreach (Type type in types) 
     { 
      // Create a new instance of all found types 
      PluginLists.All.Add((IPlugin)Activator.CreateInstance(type)); 
      Console.WriteLine("Plugin loaded: {0}", type.ToString()); 
     } 
     Console.WriteLine("Plugins loaded: {0}", PluginLists.All.Count); 
    } 

而且,每個DLL實現其啓動的形式

public void Plugin_Start(DockPanel _dockPanel) 
{ 
    // 
    var miscForm = new frmMiscellaneousTest(); 
    miscForm.Show(_dockPanel, DockState.DockRight); 
} 

感謝您給予任何幫助的方法,這是大加讚賞。

+0

通話無效的方法 –

+0

@vivek:我已經嘗試過了,在我的OP中沒有提及它,但並沒有改變: – polomint

+0

您是否嘗試在更改值之後刷新控件或整個窗體?Form1.Refresh()或Label1.Refresh() – Hadi

回答

0

我用下面的代碼(現在註釋掉)展現形式,但我已經完全忘記了我已經在形式,並沒有需要重新初始化它,:(

public void Plugin_Start() 
{ 
    // 
    this.Show(); 
    //var MiscForm = new frmMiscellaneousTest(); 
    //MiscForm.Show(); 
}