/// <summary> /// Edits the specified object's value using the editor style indicated by the /// <see cref="M:System.Drawing.Design.UITypeEditor.GetEditStyle"/> method. /// </summary> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that can be /// used to gain additional context information.</param> /// <param name="provider">An <see cref="T:System.IServiceProvider"/> that this editor can use to /// obtain services.</param> /// <param name="value">The object to edit.</param> /// <returns> /// The new value of the object. If the value of the object has not changed, this should return the /// same object it was passed. /// </returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { var svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService; if (svc != null) { using (var editorForm = new GrhUITypeEditorForm(value)) { var pt = context.PropertyDescriptor.PropertyType; if (svc.ShowDialog(editorForm) == DialogResult.OK) { var sel = editorForm.SelectedValue; // Handle setting the value based on the type we are working with if (pt == typeof(GrhIndex) || pt == typeof(GrhIndex?)) { value = sel; } else if (pt == typeof(Grh)) { var asGrh = value as Grh; if (asGrh != null) { asGrh.SetGrh(sel); } else { value = new Grh(sel, AnimType.Loop, 0); } } else if (pt == typeof(GrhData)) { value = GrhInfo.GetData(sel); } else { const string errmsg = "Don't know how to handle the source property type `{0}`. In value: {1}. Editor type: {2}"; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, pt, value, editorForm.GetType()); } Debug.Fail(string.Format(errmsg, pt, value, editorForm.GetType())); } } else { if (pt == typeof(GrhIndex?)) { value = null; } } } } return(value); }
/// <summary> /// Edits the specified object's value using the editor style indicated by the /// <see cref="M:System.Drawing.Design.UITypeEditor.GetEditStyle"/> method. /// </summary> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that can be /// used to gain additional context information.</param> /// <param name="provider">An <see cref="T:System.IServiceProvider"/> that this editor can use to /// obtain services.</param> /// <param name="value">The object to edit.</param> /// <returns> /// The new value of the object. If the value of the object has not changed, this should return the /// same object it was passed. /// </returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { var svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService; if (svc != null) { using (var editorForm = new GrhUITypeEditorForm(value)) { var pt = context.PropertyDescriptor.PropertyType; if (svc.ShowDialog(editorForm) == DialogResult.OK) { var sel = editorForm.SelectedValue; // Handle setting the value based on the type we are working with if (pt == typeof(GrhIndex) || pt == typeof(GrhIndex?)) value = sel; else if (pt == typeof(Grh)) { var asGrh = value as Grh; if (asGrh != null) asGrh.SetGrh(sel); else value = new Grh(sel, AnimType.Loop, 0); } else if (pt == typeof(GrhData)) value = GrhInfo.GetData(sel); else { const string errmsg = "Don't know how to handle the source property type `{0}`. In value: {1}. Editor type: {2}"; if (log.IsErrorEnabled) log.ErrorFormat(errmsg, pt, value, editorForm.GetType()); Debug.Fail(string.Format(errmsg, pt, value, editorForm.GetType())); } } else { if (pt == typeof(GrhIndex?)) value = null; } } } return value; }
/// <summary> /// Handles the <see cref="Button.Click"/> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param> protected override void OnClick(EventArgs e) { base.OnClick(e); if (DesignMode) return; var currSelected = GetCurrentlySelectedGrhData(); using (var frm = new GrhUITypeEditorForm(currSelected)) { var result = frm.ShowDialog(this); if (result == DialogResult.Abort || result == DialogResult.Cancel || result == DialogResult.Ignore) return; var newSelectedIndex = frm.SelectedValue; var newSelected = GrhInfo.GetData(newSelectedIndex); if (GrhDataSelected != null) GrhDataSelected.Raise(this, EventArgsHelper.Create(newSelected)); } }