//private string GetObjectSiteName(object o) //{ // if (o != null) // { // IComponent component = o as IComponent; // if (component != null) // { // ISite site = component.Site; // if (site != null) // { // return site.Name; // } // } // return o.GetType().ToString(); // } // return String.Empty; //} /// <summary> /// 获取控件的显示名(所关联对象的Code) /// </summary> /// <param name="o"></param> /// <returns></returns> private string GetObjectSiteName(object o) { if (o != null) { IShellControlDev component = o as IShellControlDev; if (component != null) { return(component.GetCode()); } return(o.GetType().ToString()); } return(String.Empty); }
private void ComboBoxDrawItem(object sender, DrawItemEventArgs dea) { if (dea.Index < 0 || dea.Index >= this.comboBoxFormElementList.Items.Count) { return; } Graphics g = dea.Graphics; Brush stringColor = SystemBrushes.ControlText; if ((dea.State & DrawItemState.Selected) == DrawItemState.Selected) { if ((dea.State & DrawItemState.Focus) == DrawItemState.Focus) { g.FillRectangle(SystemBrushes.Highlight, dea.Bounds); stringColor = SystemBrushes.HighlightText; } else { g.FillRectangle(SystemBrushes.Window, dea.Bounds); } } else { g.FillRectangle(SystemBrushes.Window, dea.Bounds); } object item = this.comboBoxFormElementList.Items[dea.Index]; int xPos = dea.Bounds.X; /* * if (item is IComponent) * { * ISite site = ((IComponent)item).Site; * if (site != null) * { * string name = site.Name; * using (Font f = new Font(this.comboBoxFormElementList.Font, FontStyle.Bold)) * { * g.DrawString(name, f, stringColor, xPos, dea.Bounds.Y); * xPos += (int)g.MeasureString(name + "-", f).Width; * } * } * } */ string typeString = String.Empty; if (item is IShellControlDev) { IShellControlDev site = (IShellControlDev)item; if (site != null) { string name = site.GetCode(); using (Font f = new Font(this.comboBoxFormElementList.Font, FontStyle.Bold)) { g.DrawString(name, f, stringColor, xPos, dea.Bounds.Y); xPos += (int)g.MeasureString(name + "-", f).Width; } typeString = site.GetControlTypeName(); } } // string typeString = item.GetType().ToString(); g.DrawString(typeString, this.comboBoxFormElementList.Font, stringColor, xPos, dea.Bounds.Y); }