ToolWinForm.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.ComponentModel;
  6. using System.Diagnostics;
  7. using System.Threading;
  8. using System.Runtime.InteropServices;
  9. using System.Windows.Forms;
  10. using System.Drawing.Imaging;
  11. namespace Ips.Library.DxpLib
  12. {
  13. public static class ToolWinform
  14. {
  15. public static bool IsDesignMode()
  16. {
  17. bool returnFlag = false;
  18. #if DEBUG
  19. if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
  20. {
  21. returnFlag = true;
  22. }
  23. else if (Process.GetCurrentProcess().ProcessName == "devenv")
  24. {
  25. returnFlag = true;
  26. }
  27. #endif
  28. return returnFlag;
  29. }
  30. public static void SaveCtrlValueToConfig(Control ctrl)
  31. {
  32. try
  33. {
  34. Dictionary<string, string> settings = new Dictionary<string, string>();
  35. SaveValueToSettings(ctrl, settings);
  36. ToolConfig.SetAppSetting(settings);
  37. }
  38. catch (Exception ex)
  39. {
  40. ToolMsg.ShowError("保存配置异常,错误消息:" + ex.Message);
  41. }
  42. }
  43. public static void LoadCtrlValueFromConfig(Control ctrl)
  44. {
  45. try
  46. {
  47. LoadValueFromSettings(ctrl);
  48. }
  49. catch (Exception ex)
  50. {
  51. ToolMsg.ShowError("加载配置异常,错误消息:" + ex.Message);
  52. }
  53. }
  54. private static void SaveValueToSettings(Control ctrl, Dictionary<string, string> settings)
  55. {
  56. foreach (Control item in ctrl.Controls)
  57. {
  58. if (item is TextBoxBase)
  59. {
  60. settings.Add(item.Name, item.Text);
  61. }
  62. SaveValueToSettings(item, settings);
  63. }
  64. }
  65. private static void LoadValueFromSettings(Control ctrl)
  66. {
  67. foreach (Control item in ctrl.Controls)
  68. {
  69. if (item is TextBoxBase)
  70. {
  71. item.Text = ToolConfig.GetAppSetting(item.Name);
  72. }
  73. LoadValueFromSettings(item);
  74. }
  75. }
  76. }
  77. }