Form3.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System;
  2. using System.Threading;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Windows.Forms.Integration;
  10. using Core.Mes.Client.Comm.WPF;
  11. namespace Core.StlMes
  12. {
  13. public partial class Form3 : Form
  14. {
  15. private System.Windows.Forms.Integration.ElementHost elementHost1;
  16. private delegate void TestDlg(System.Windows.Forms.Integration.ElementHost element);
  17. public Form3()
  18. {
  19. InitializeComponent();
  20. Thread NetServer = new Thread(new ThreadStart(test));
  21. NetServer.SetApartmentState(ApartmentState.STA);
  22. NetServer.IsBackground = true;
  23. //NetServer.Start();
  24. }
  25. private void Form3_MouseDoubleClick(object sender, MouseEventArgs e)
  26. {
  27. //System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
  28. // new TestDlg(test));
  29. this.Controls.Add(elementHost1);
  30. }
  31. private void test1(System.Windows.Forms.Integration.ElementHost element)
  32. {
  33. this.Controls.Add(element);
  34. }
  35. private void test()
  36. {
  37. if (this.Controls.Contains(Controls["elementHost1"]))
  38. return;
  39. Core.Mes.Client.Comm.WPF.DocumentViewer documentViewer1;
  40. elementHost1 = new System.Windows.Forms.Integration.ElementHost();
  41. documentViewer1 = new Core.Mes.Client.Comm.WPF.DocumentViewer();
  42. elementHost1.Dock = System.Windows.Forms.DockStyle.Fill;
  43. elementHost1.Location = new System.Drawing.Point(0, 0);
  44. elementHost1.Name = "elementHost1";
  45. elementHost1.Size = new System.Drawing.Size(763, 417);
  46. elementHost1.TabIndex = 0;
  47. elementHost1.Text = "elementHost1";
  48. elementHost1.Child = documentViewer1;
  49. String[] args = new String[] { "a" ,"b"};
  50. MessageBox.Show(ArrayToString(args," "));
  51. //this.Controls.Add(elementHost1);
  52. TestDlg dlg = new TestDlg(test1);
  53. this.Invoke(dlg, new object[] { elementHost1 });
  54. }
  55. private string ArrayToString(Array array, string separator)
  56. {
  57. string result = "";
  58. if (array != null && array.Length > 0)
  59. {
  60. for (int i = 0; i < array.Length - 1;i++ )
  61. {
  62. result += array.GetValue(i).ToString() + separator;
  63. }
  64. result += array.GetValue(array.Length-1).ToString();
  65. }
  66. return result;
  67. }
  68. private void Form3_Load(object sender, EventArgs e)
  69. {
  70. }
  71. }
  72. }