FormHelper.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using System.Windows.Forms;
  7. using CoreFS.CA06;
  8. namespace Core.Mes.Client.Comm.Control
  9. {
  10. /// <summary>
  11. /// Form处理类
  12. /// </summary>
  13. public class FormHelper
  14. {
  15. /// <summary>
  16. /// 打开其他工程中的窗体
  17. /// </summary>
  18. /// <param name="vParentFrm">主窗体 (this.MdiParent)</param>
  19. /// <param name="vKey">一般为窗体的全称 + 配置信息(可无)</param>
  20. /// <param name="vAssemblyName">程序集名</param>
  21. /// <param name="vClassName">窗体的全称</param>
  22. /// <param name="vCaption">窗体的中文名</param>
  23. public static void OpenOtherAssemblyForm(Form vParentFrm, string vKey, string vAssemblyName,
  24. string vClassName, string vCaption)
  25. {
  26. //检查窗体是否已经打开
  27. foreach (Form mdiChild in vParentFrm.MdiChildren)
  28. {
  29. if ((mdiChild as FrmBase).Key == vKey)
  30. {
  31. mdiChild.Activate();
  32. return;
  33. }
  34. }
  35. //实例化窗体并打开
  36. try
  37. {
  38. Assembly baseFormAssembly = Assembly.Load(vAssemblyName);
  39. Type type = baseFormAssembly.GetType(vClassName);
  40. System.Diagnostics.Debug.Assert(type.IsSubclassOf(typeof(FrmBase)));
  41. FrmBase form = Activator.CreateInstance(type, true) as FrmBase;
  42. form.MdiParent = vParentFrm;
  43. form.Text = vCaption;
  44. form.Key = vKey;
  45. form.Show();
  46. }
  47. catch (Exception ex)
  48. {
  49. Console.WriteLine(ex.Message);
  50. }
  51. }
  52. }
  53. }