private void listBox1_DrawItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); if (e.Index >= 0) { if ((e.State & DrawItemState.Selected) != 0) { e.DrawFocusRectangle(); } SessionVariable sv = listBox1.Items[e.Index] as SessionVariable; Type t = sv.ValueType; Image img; if (!imgs.TryGetValue(t, out img)) { img = VPLUtil.GetTypeIcon(t); imgs.Add(t, img); } System.Drawing.Rectangle rc = new System.Drawing.Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); e.Graphics.DrawImage(img, rc.X, rc.Y); rc.X += 16; if (rc.Width > 16) { rc.Width -= 16; } e.Graphics.DrawString(sv.ToString(), this.Font, Brushes.Black, rc); } }
public void LoadData(SessionVariableCollection owner, SessionVariable defValue) { _owner = owner; _defVal = defValue; if (_defVal != null) { textBox1.Text = _defVal.Name; } }
public PropertyDescriptorSessionVariable(SessionVariable s, SessionVariableCollection owner) : base(s.Name, new Attribute[] { new WebClientMemberAttribute() , new WebServerMemberAttribute() }) { _owner = owner; _variable = s; }
private void buttonOK_Click(object sender, EventArgs e) { string nm = textBox1.Text.Trim(); if (string.IsNullOrEmpty(nm)) { MessageBox.Show(this, "Name cannot be empty", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { bool bExists = false; if (_owner != null) { if (!(_defVal != null && string.Compare(_defVal.Name, nm, StringComparison.OrdinalIgnoreCase) == 0)) { bExists = (_owner[nm] != null); } } if (bExists) { MessageBox.Show(this, "Name is in use", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { Return = new SessionVariable(); Return.Name = nm; Type t; if (listBox1.SelectedIndex >= 0) { t = _types[listBox1.Items[listBox1.SelectedIndex] as string]; } else { t = typeof(JsString); } Return.Value = Activator.CreateInstance(t) as IJavascriptType; ReturnName = nm; ReturnType = Return.Value; this.DialogResult = DialogResult.OK; } } }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (context != null && context.Instance != null && provider != null) { IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (edSvc != null) { SessionVariable sv = context.Instance as SessionVariable; SessionVariableCollection svc = context.Instance as SessionVariableCollection; if (svc == null) { LimnorWebApp wa = context.Instance as LimnorWebApp; if (wa != null) { svc = wa.GlobalVariables; } else { SessionVariableCollection.PropertyDescriptorNewSessionVariable psdv = context.PropertyDescriptor as SessionVariableCollection.PropertyDescriptorNewSessionVariable; if (psdv != null) { svc = psdv.Owner; } else { SessionVariableCollection.PropertyDescriptorSessionVariable psdv0 = context.PropertyDescriptor as SessionVariableCollection.PropertyDescriptorSessionVariable; if (psdv0 != null) { svc = psdv0.Owner; } } } } if (svc != null) { DlgSessionVariable dlg = new DlgSessionVariable(); dlg.LoadData(svc, sv); if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK) { if (sv != null) { sv.Name = dlg.Return.Name; sv.Value = dlg.Return.Value; } else { svc.Add(dlg.Return); } value = dlg.Return; IDevClassReferencer dcr = svc.Owner as IDevClassReferencer; if (dcr != null) { IDevClass dc = dcr.GetDevClass(); if (dc != null) { dc.NotifyChange(dcr, context.PropertyDescriptor.Name); } } } } } } return(value); }