/// <summary> /// Binds the control to a property and owner</summary> /// <param name="context">Context for property editing control</param> public void Bind(PropertyEditorControlContext context) { if (m_textBox.Focused) { Flush(); } m_context = context; m_descriptor = m_context.Descriptor; bool visible = m_context != null; base.Visible = visible; if (visible) { SetTextBoxFromProperty(); bool editButtonVisible = false; if (!m_context.IsReadOnly) { UITypeEditor editor = WinFormsPropertyUtils.GetUITypeEditor(m_descriptor, this); if (editor != null) { editButtonVisible = true; m_editButton.Modal = (editor.GetEditStyle(this) == UITypeEditorEditStyle.Modal); } } m_editButton.Visible = editButtonVisible; // a standard set of values that can be picked from a list, like enum (but only if we're not readonly) if (!m_context.IsReadOnly && (m_descriptor.Converter != null)) { TypeDescriptorContext tdcontext = new TypeDescriptorContext(m_context.LastSelectedObject, m_descriptor, null); if (m_descriptor.Converter.GetStandardValuesExclusive(tdcontext)) { // this will redraw the control before we get to the invalidate below m_textBox.AutoCompleteMode = AutoCompleteMode.None; m_textBox.AutoCompleteCustomSource.Clear(); AutoCompleteStringCollection standardVals = new AutoCompleteStringCollection(); ICollection values = m_descriptor.Converter.GetStandardValues(tdcontext); foreach (object item in values) { standardVals.Add(item.ToString()); } m_textBox.AutoCompleteCustomSource = standardVals; // this will redraw the control before we get to the invalidate below m_textBox.AutoCompleteSource = AutoCompleteSource.CustomSource; m_textBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend; } else { // this will redraw the control before we get to the invalidate below m_textBox.AutoCompleteMode = AutoCompleteMode.None; m_textBox.AutoCompleteSource = AutoCompleteSource.None; m_textBox.AutoCompleteCustomSource.Clear(); } } else { // this will redraw the control before we get to the invalidate below m_textBox.AutoCompleteMode = AutoCompleteMode.None; m_textBox.AutoCompleteSource = AutoCompleteSource.None; m_textBox.AutoCompleteCustomSource.Clear(); } PerformLayout(); Invalidate(); } }
/// <summary> /// Binds the control to a property and owner</summary> /// <param name="context">Context for property editing control</param> public void Bind(PropertyEditorControlContext context) { if (m_textBox.Focused) Flush(); m_context = context; m_descriptor = m_context.Descriptor; bool visible = m_context != null; base.Visible = visible; if (visible) { SetTextBoxFromProperty(); bool editButtonVisible = false; if (!m_context.IsReadOnly) { UITypeEditor editor = WinFormsPropertyUtils.GetUITypeEditor(m_descriptor, this); if (editor != null) { editButtonVisible = true; m_editButton.Modal = (editor.GetEditStyle(this) == UITypeEditorEditStyle.Modal); } } m_editButton.Visible = editButtonVisible; // a standard set of values that can be picked from a list, like enum (but only if we're not readonly) if (!m_context.IsReadOnly && (m_descriptor.Converter != null)) { TypeDescriptorContext tdcontext = new TypeDescriptorContext(m_context.LastSelectedObject, m_descriptor, null); if (m_descriptor.Converter.GetStandardValuesExclusive(tdcontext)) { // this will redraw the control before we get to the invalidate below m_textBox.AutoCompleteMode = AutoCompleteMode.None; m_textBox.AutoCompleteCustomSource.Clear(); AutoCompleteStringCollection standardVals = new AutoCompleteStringCollection(); ICollection values = m_descriptor.Converter.GetStandardValues(tdcontext); foreach (object item in values) standardVals.Add(item.ToString()); m_textBox.AutoCompleteCustomSource = standardVals; // this will redraw the control before we get to the invalidate below m_textBox.AutoCompleteSource = AutoCompleteSource.CustomSource; m_textBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend; } else { // this will redraw the control before we get to the invalidate below m_textBox.AutoCompleteMode = AutoCompleteMode.None; m_textBox.AutoCompleteSource = AutoCompleteSource.None; m_textBox.AutoCompleteCustomSource.Clear(); } } else { // this will redraw the control before we get to the invalidate below m_textBox.AutoCompleteMode = AutoCompleteMode.None; m_textBox.AutoCompleteSource = AutoCompleteSource.None; m_textBox.AutoCompleteCustomSource.Clear(); } PerformLayout(); Invalidate(); } }