private void OnListBoxDoubleClick(object sener, EventArgs e) { IToolboxUser docDes = null; SelfHostToolboxItem selectedItem = listBox.SelectedItem as SelfHostToolboxItem; if (selectedItem == null) { return; } this.currentSelection = selectedItem.ComponentType; IDesignerHost host = (IDesignerHost)provider.GetService(typeof(IDesignerHost)); //des.ActiveDesigner; if (host != null && this.currentSelection != null) { IDesigner designer = host.GetDesigner(host.RootComponent); if (designer is IToolboxUser) { docDes = (IToolboxUser)designer; } if (docDes != null) { ToolboxItem c = ToolboxService.GetToolboxItem(this.currentSelection); Debug.Assert(c != null, "Class " + this.currentSelection.FullName + " does not exist"); if (c != null && docDes.GetToolSupported(c)) { try { docDes.ToolPicked(c); } catch (Exception ex) { IUIService uis = (IUIService)provider.GetService(typeof(IUIService)); if (uis != null) { uis.ShowError(ex); } else { MessageBox.Show("Error: " + ex.ToString()); } } } } else { object o = Activator.CreateInstance(this.currentSelection); SequentialWorkflowActivity service = host.RootComponent as SequentialWorkflowActivity; service.Activities.Add(o as Activity); host.RootComponent.Site.Container.Add(o as IComponent); } } }
//Start the drag drop when user selects and drags the tool private void OnListBoxMouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && this.listBox.SelectedItem != null) { SelfHostToolboxItem selectedItem = listBox.SelectedItem as SelfHostToolboxItem; if (selectedItem == null || selectedItem.ComponentType == null) { return; } ToolboxItem toolboxItem = ToolboxService.GetToolboxItem(selectedItem.ComponentType); IDataObject dataObject = this.SerializeToolboxItem(toolboxItem) as IDataObject; DragDropEffects effects = DoDragDrop(dataObject, DragDropEffects.Copy | DragDropEffects.Move); } }
private void OnListBoxClick(object sender, EventArgs eevent) { SelfHostToolboxItem toolboxItem = listBox.SelectedItem as SelfHostToolboxItem; if (toolboxItem != null) { this.currentSelection = toolboxItem.ComponentType; } else if (this.currentSelection != null) { int index = this.listBox.Items.IndexOf(this.currentSelection); if (index >= 0) { this.listBox.SelectedIndex = index; } } }
private void OnDrawItem(object sender, DrawItemEventArgs e) { Graphics g = e.Graphics; ListBox listBox = (ListBox)sender; object objItem = listBox.Items[e.Index]; SelfHostToolboxItem item = null; Bitmap bitmap = null; string text = null; if (objItem is string) { bitmap = null; text = (string)objItem; } else { item = (SelfHostToolboxItem)objItem; bitmap = (Bitmap)item.Glyph; // if it's not a bitmap, it's a metafile, and how likely is that? text = item.Name; } bool selected = false; bool disabled = false; if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { selected = true; } if ((int)(e.State & (DrawItemState.Disabled | DrawItemState.Grayed | DrawItemState.Inactive)) != 0) { disabled = true; } StringFormat format = new StringFormat(); format.HotkeyPrefix = HotkeyPrefix.Show; int x = e.Bounds.X + 4; x += 20; if (selected) { Rectangle r = e.Bounds; r.Width--; r.Height--; g.DrawRectangle(SystemPens.ActiveCaption, r); } else { g.FillRectangle(SystemBrushes.Menu, e.Bounds); using (Brush border = new SolidBrush(Color.FromArgb(Math.Min(SystemColors.Menu.R + 15, 255), Math.Min(SystemColors.Menu.G + 15, 255), Math.Min(SystemColors.Menu.B + 15, 255)))) g.FillRectangle(border, new Rectangle(e.Bounds.X, e.Bounds.Y, 20, e.Bounds.Height)); } if (bitmap != null) { g.DrawImage(bitmap, e.Bounds.X + 2, e.Bounds.Y + 2, bitmap.Width, bitmap.Height); } Brush textBrush = (disabled) ? new SolidBrush(Color.FromArgb(120, SystemColors.MenuText)) : SystemBrushes.FromSystemColor(SystemColors.MenuText); Font f = new Font("Courier", 8); g.DrawString(text, f, textBrush, x, e.Bounds.Y + 2, format); if (disabled) { textBrush.Dispose(); } format.Dispose(); }
public void AddToolBoxItem(SelfHostToolboxItem item) { listBox.Items.Add(item); }