1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System;
- using System.Windows.Forms;
- using System.Drawing;
- using System.ComponentModel;
- using FastReport.Utils;
- namespace FastReport.Controls
- {
- internal class ComponentRefListBox : ListBox
- {
- public Base SelectedObject
- {
- get { return SelectedIndex <= 0 ? null : Items[SelectedIndex] as Base; }
- }
- protected override void OnDrawItem(DrawItemEventArgs e)
- {
- e.DrawBackground();
- if (e.Index >= 0)
- {
- Base c = Items[e.Index] as Base;
- Image img = this.GetImage(c == null ? 76 : RegisteredObjects.FindObject(c).ImageIndex);
- string text = c == null ? Res.Get("Misc,None") : c.Name;
- this.DrawImageAndText(e, img, text);
- }
- }
- public void PopulateList(Base parent, Type componentType, object instance)
- {
- Items.Clear();
- Items.Add(0);
- FastReport.ObjectCollection list = parent.AllObjects;
- foreach (Base c in list)
- {
- if (c != instance && (c.GetType() == componentType || c.GetType().IsSubclassOf(componentType)))
- Items.Add(c);
- }
- }
- public ComponentRefListBox()
- {
- ItemHeight = 19;
- BorderStyle = BorderStyle.None;
- DrawMode = DrawMode.OwnerDrawFixed;
- Height = 8 * ItemHeight;
- }
- }
- }
|