public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (provider == null) { return(value); } _context = context; IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (edSvc == null) { return(value); } if (_binaryUI == null) { // child modal dialog -launching in System Aware mode _binaryUI = DpiHelper.CreateInstanceInSystemAwareContext(() => new BinaryUI(this)); } _binaryUI.Value = value; if (edSvc.ShowDialog(_binaryUI) == DialogResult.OK) { value = _binaryUI.Value; } _binaryUI.Value = null; return(value); }
/// <summary> /// Gets the mask property value fromt the MaskDesignerDialog. /// The IUIService is used to show the mask designer dialog within VS so it doesn't get blocked if focus /// is moved to anoter app. /// </summary> internal static string EditMask(ITypeDiscoveryService discoverySvc, IUIService uiSvc, MaskedTextBox instance, IHelpService helpService) { Debug.Assert(instance != null, "Null masked text box."); string mask = null; // Launching modal dialog in System aware mode. MaskDesignerDialog dlg = DpiHelper.CreateInstanceInSystemAwareContext(() => new MaskDesignerDialog(instance, helpService)); try { dlg.DiscoverMaskDescriptors(discoverySvc); // fine if service is null. // Show dialog from VS. DialogResult dlgResult = uiSvc != null?uiSvc.ShowDialog(dlg) : dlg.ShowDialog(); if (dlgResult == DialogResult.OK) { mask = dlg.Mask; // ValidatingType is not browsable so we don't need to set the property through the designer. if (dlg.ValidatingType != instance.ValidatingType) { instance.ValidatingType = dlg.ValidatingType; } } } finally { dlg.Dispose(); } // Will return null if dlgResult != OK. return(mask); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (provider is null) { return(value); } IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (edSvc is null) { return(value); } if (_linkAreaUI is null) { IHelpService helpService = (IHelpService)provider.GetService(typeof(IHelpService)); // child modal dialog -launching in System Aware mode _linkAreaUI = DpiHelper.CreateInstanceInSystemAwareContext(() => new LinkAreaUI(this, helpService)); } string text = string.Empty; PropertyDescriptor prop = null; if (context != null && context.Instance != null) { prop = TypeDescriptor.GetProperties(context.Instance)["Text"]; if (prop != null && prop.PropertyType == typeof(string)) { text = (string)prop.GetValue(context.Instance); } } string originalText = text; _linkAreaUI.SampleText = text; _linkAreaUI.Start(edSvc, value); if (edSvc.ShowDialog(_linkAreaUI) == DialogResult.OK) { value = _linkAreaUI.Value; text = _linkAreaUI.SampleText; if (!originalText.Equals(text) && prop != null && prop.PropertyType == typeof(string)) { prop.SetValue(context.Instance, text); } } _linkAreaUI.End(); return(value); }