ComponentRefListBox.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Drawing;
  4. using System.ComponentModel;
  5. using FastReport.Utils;
  6. namespace FastReport.Controls
  7. {
  8. internal class ComponentRefListBox : ListBox
  9. {
  10. public Base SelectedObject
  11. {
  12. get { return SelectedIndex <= 0 ? null : Items[SelectedIndex] as Base; }
  13. }
  14. protected override void OnDrawItem(DrawItemEventArgs e)
  15. {
  16. e.DrawBackground();
  17. if (e.Index >= 0)
  18. {
  19. Base c = Items[e.Index] as Base;
  20. Image img = this.GetImage(c == null ? 76 : RegisteredObjects.FindObject(c).ImageIndex);
  21. string text = c == null ? Res.Get("Misc,None") : c.Name;
  22. this.DrawImageAndText(e, img, text);
  23. }
  24. }
  25. public void PopulateList(Base parent, Type componentType, object instance)
  26. {
  27. Items.Clear();
  28. Items.Add(0);
  29. FastReport.ObjectCollection list = parent.AllObjects;
  30. foreach (Base c in list)
  31. {
  32. if (c != instance && (c.GetType() == componentType || c.GetType().IsSubclassOf(componentType)))
  33. Items.Add(c);
  34. }
  35. }
  36. public ComponentRefListBox()
  37. {
  38. ItemHeight = 19;
  39. BorderStyle = BorderStyle.None;
  40. DrawMode = DrawMode.OwnerDrawFixed;
  41. Height = 8 * ItemHeight;
  42. }
  43. }
  44. }