2016-10-23 40 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(); 
}