private void OnLinkLabelLinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { Debug.Assert(!ActionPanel.InMethodInvoke, "Nested method invocation"); ActionPanel.InMethodInvoke = true; try { _methodItem.Invoke(); } catch (Exception ex) { if (ex is TargetInvocationException) { ex = ex.InnerException; } //NOTE: We had code to rethrow if this was one of [NullReferenceException, StackOverflowException, OutOfMemoryException, //ThreadAbortException]. Removing this rethrow. StackOverflow and ThreadAbort can't be meaningfully caught, and //NullRef and OutOfMemory really shouldn't be caught. Out of these, OOM is the most correct one to call, but OOM is //thrown by GDI+ for pretty much any problem, so isn't reliable as an actual indicator that you're out of memory. If //you really are out of memory, it's very likely you'll get another OOM shortly. ActionPanel.ShowError(string.Format(SR.DesignerActionPanel_ErrorInvokingAction, _methodItem.DisplayName, Environment.NewLine + ex.Message)); } finally { ActionPanel.InMethodInvoke = false; } }
private void ActivateDropDown() { if (_editor != null) { try { object newValue = _editor.EditValue(TypeDescriptorContext, this, Value); SetValue(newValue); } catch (Exception ex) { ActionPanel.ShowError(string.Format(SR.DesignerActionPanel_ErrorActivatingDropDown, ex.Message)); } } else { ListBox listBox = new ListBox { BorderStyle = BorderStyle.None, IntegralHeight = false, Font = ActionPanel.Font }; listBox.SelectedIndexChanged += new EventHandler(OnListBoxSelectedIndexChanged); listBox.KeyDown += new KeyEventHandler(OnListBoxKeyDown); TypeConverter.StandardValuesCollection standardValues = GetStandardValues(); if (standardValues != null) { foreach (object o in standardValues) { string newItem = PropertyDescriptor.Converter.ConvertToString(TypeDescriptorContext, CultureInfo.CurrentCulture, o); listBox.Items.Add(newItem); if ((o != null) && o.Equals(Value)) { listBox.SelectedItem = newItem; } } } // All measurement code borrowed from WinForms PropertyGridView.cs int maxWidth = 0; // The listbox draws with GDI, not GDI+. So, we use a normal DC here. using (var hdc = new User32.GetDcScope(listBox.Handle)) { using var hFont = new Gdi32.ObjectScope(listBox.Font.ToHFONT()); using var fontSelection = new Gdi32.SelectObjectScope(hdc, hFont); var tm = new Gdi32.TEXTMETRICW(); if (listBox.Items.Count > 0) { foreach (string s in listBox.Items) { var textSize = new Size(); Gdi32.GetTextExtentPoint32W(hdc, s, s.Length, ref textSize); maxWidth = Math.Max(textSize.Width, maxWidth); } } Gdi32.GetTextMetricsW(hdc, ref tm); // border + padding + scrollbar maxWidth += 2 + tm.tmMaxCharWidth + SystemInformation.VerticalScrollBarWidth; listBox.Height = Math.Max(tm.tmHeight + 2, Math.Min(ListBoxMaximumHeight, listBox.PreferredHeight)); listBox.Width = Math.Max(maxWidth, EditRegionSize.Width); _ignoreDropDownValue = false; } try { ShowDropDown(listBox, SystemColors.ControlDark); } finally { listBox.SelectedIndexChanged -= new EventHandler(OnListBoxSelectedIndexChanged); listBox.KeyDown -= new KeyEventHandler(OnListBoxKeyDown); } if (!_ignoreDropDownValue) { if (listBox.SelectedItem != null) { SetValue(listBox.SelectedItem); } } } }