G2DPropertyDialog.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using CommonFroms.G2D.DataGrid;
  2. using System;
  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. namespace CommonFroms.G2D
  10. {
  11. public partial class G2DPropertyDialog<T> : Form where T : class, new()
  12. {
  13. public G2DPropertyDialog(T data, params IG2DPropertyAdapter[] adds)
  14. {
  15. InitializeComponent();
  16. if (data == null)
  17. {
  18. data = new T();
  19. }
  20. this.g2DPropertyGrid1.SetSelectedObject(data, adds);
  21. this.g2DPropertyGrid1.Focus();
  22. }
  23. public T SelectedObject
  24. {
  25. get { return this.g2DPropertyGrid1.GetSelectedValue() as T; }
  26. }
  27. //----------------------------------------------------------------------------------
  28. public static T Show(string title, T data, params IG2DPropertyAdapter[] adds)
  29. {
  30. var dialog = new G2DPropertyDialog<T>(data, adds);
  31. dialog.Text = title;
  32. DialogResult res = dialog.ShowDialog();
  33. if (res == System.Windows.Forms.DialogResult.OK)
  34. {
  35. return dialog.SelectedObject;
  36. }
  37. return null;
  38. }
  39. }
  40. }