public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value) { if (value is string) { IWindowsFormsEditorService editor = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (editor == null) { return(null); } CoordinatePropertyAttribute attrib = context.PropertyDescriptor.Attributes .OfType <CoordinatePropertyAttribute>().FirstOrDefault(); PropertyDescriptor coordProp = null; if (attrib != null) { PropertyDescriptorCollection propCollection = TypeDescriptor.GetProperties(context.Instance); coordProp = propCollection.Find(attrib.PropertyName, false); } UIControlLocatorForm dialog = new UIControlLocatorForm(); dialog.ControlPath = (string)value; if (coordProp != null) { dialog.Coordinate = (Point)coordProp.GetValue(context.Instance); } if (editor.ShowDialog(dialog) == DialogResult.OK) { if (coordProp != null) { coordProp.SetValue(context.Instance, dialog.Coordinate); } // Notify the instance that we changed the property; this // gives them the chance to react to the change, unlike reacting // on the property change, which can happen during XML deserialization MethodInfo method = context.Instance.GetType().GetMethod( context.PropertyDescriptor.Name + "PropertyChanging"); if (method != null) { method.Invoke(context.Instance, new object[] { dialog.ControlPath }); } return(dialog.ControlPath); } return(value); } return(base.EditValue(context, provider, value)); }
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value) { TestCase testCase = context.Instance as TestCase; if (value is string) { IntPtr mainHandle = UIControlLocatorForm.FindWindowByCaption(IntPtr.Zero, "QAliber Test Builder"); Form form = (Form)Form.FromHandle(mainHandle); DesktopMaskForm dialog = new DesktopMaskForm(); form.Visible = false; dialog.ImageFile = (string)value; try { if (dialog.ShowDialog() != DialogResult.OK) { return(value); } } finally { form.Visible = true; } string path = dialog.ImageFile; if (testCase != null && testCase.Scenario.Filename != null) { // Make a relative path if we can path = NativeMethods.MakeRelativePath(testCase.Scenario.Filename, false, path, false) ?? path; if (path.StartsWith(".\\")) { path = path.Substring(2); } } return(path); } return(base.EditValue(context, provider, value)); }