ComponentRefComboBox.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #if !DEBUG
  9. [DesignTimeVisible(false)]
  10. #endif
  11. internal class ComponentRefComboBox : ComboBox
  12. {
  13. public Base SelectedObject
  14. {
  15. get { return SelectedIndex <= 0 ? null : Items[SelectedIndex] as Base; }
  16. }
  17. protected override void OnDrawItem(DrawItemEventArgs e)
  18. {
  19. e.DrawBackground();
  20. if (e.Index >= 0)
  21. {
  22. Base c = Items[e.Index] as Base;
  23. Image img = this.GetImage(c == null ? 76 : RegisteredObjects.FindObject(c).ImageIndex);
  24. string text = c == null ? Res.Get("Misc,None") : c.Name;
  25. this.DrawImageAndText(e, img, text);
  26. }
  27. }
  28. public void PopulateList(Base parent, Type componentType, object instance)
  29. {
  30. Items.Clear();
  31. Items.Add(0);
  32. FastReport.ObjectCollection list = parent.AllObjects;
  33. foreach (Base c in list)
  34. {
  35. if (c != instance && (c.GetType() == componentType || c.GetType().IsSubclassOf(componentType)))
  36. Items.Add(c);
  37. }
  38. }
  39. public ComponentRefComboBox()
  40. {
  41. ItemHeight = 19;
  42. DropDownStyle = ComboBoxStyle.DropDownList;
  43. DrawMode = DrawMode.OwnerDrawFixed;
  44. }
  45. }
  46. }