EDN Admin
Well-known member
Hi!
I have created a custom UITypeEditor for creating a gradient backcolor on a component.
The Editor shows up nicely in the propertygrid.
But for some reason each time i open the editor from the property window it duplicates my events.
I have a label in the editor in which on click will display a color select dialog but when o close the editor and opens it again it show the color select dialog a second time hence duplicated my onclick event for the label.
This is my code for the usercontrol displayed by the Editor:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public GradientEditorControl(Gradient EditGradient, IWindowsFormsEditorService editorService)
{
InitializeComponent();
<span style="color:Green; // Cache the gradient value provided by the
<span style="color:Green; // design-time environment.
<span style="color:Blue; this.gradientValue = EditGradient;
<span style="color:Blue; this.editorService = editorService;
First_Marker.BackColor = GradientValue.Markers[0].GradientColor;
Last_Marker.BackColor = GradientValue.Markers[GradientValue.Markers.Count - 1].GradientColor;
First_Marker.Click += <span style="color:Blue; new EventHandler(First_Marker_Click);
Last_Marker.Click += <span style="color:Blue; new EventHandler(Last_Marker_Click);
<span style="color:Blue; for (<span style="color:Blue; int i = 1; i < GradientValue.Markers.Count - 1; i++)
{
<span style="color:Green; //GradientValue.Markers.Editable
<span style="color:Blue; this.Controls.Add(GradientValue.Markers);
GradientValue.Markers.BringToFront();
GradientValue.Markers.Location = <span style="color:Blue; new Point(Convert.ToInt32(GradientValue.Markers.Position*194+34), 36);
GradientValue.Markers.Move += <span style="color:Blue; new EventHandler(GradientEditorControl_Move);
GradientValue.Markers.DoubleClick += <span style="color:Blue; new EventHandler(GradientEditorControl_DoubleClick);
}
<span style="color:Blue; this.Invalidate(<span style="color:Blue; true);
}
<span style="color:Blue; void GradientEditorControl_DoubleClick(<span style="color:Blue; object sender, EventArgs e)
{
GradientMarker m = (GradientMarker)sender;
ColorSelect.Color = m.GradientColor;
<span style="color:Blue; if (ColorSelect.ShowDialog() == DialogResult.OK)
{
m.GradientColor = ColorSelect.Color;
<span style="color:Blue; this.Invalidate(<span style="color:Blue; true);
}
}
[/code]
<br/>
How come it register the event each time i open the editor, and how do i get rid of it...?
View the full article
I have created a custom UITypeEditor for creating a gradient backcolor on a component.
The Editor shows up nicely in the propertygrid.
But for some reason each time i open the editor from the property window it duplicates my events.
I have a label in the editor in which on click will display a color select dialog but when o close the editor and opens it again it show the color select dialog a second time hence duplicated my onclick event for the label.
This is my code for the usercontrol displayed by the Editor:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public GradientEditorControl(Gradient EditGradient, IWindowsFormsEditorService editorService)
{
InitializeComponent();
<span style="color:Green; // Cache the gradient value provided by the
<span style="color:Green; // design-time environment.
<span style="color:Blue; this.gradientValue = EditGradient;
<span style="color:Blue; this.editorService = editorService;
First_Marker.BackColor = GradientValue.Markers[0].GradientColor;
Last_Marker.BackColor = GradientValue.Markers[GradientValue.Markers.Count - 1].GradientColor;
First_Marker.Click += <span style="color:Blue; new EventHandler(First_Marker_Click);
Last_Marker.Click += <span style="color:Blue; new EventHandler(Last_Marker_Click);
<span style="color:Blue; for (<span style="color:Blue; int i = 1; i < GradientValue.Markers.Count - 1; i++)
{
<span style="color:Green; //GradientValue.Markers.Editable
<span style="color:Blue; this.Controls.Add(GradientValue.Markers);
GradientValue.Markers.BringToFront();
GradientValue.Markers.Location = <span style="color:Blue; new Point(Convert.ToInt32(GradientValue.Markers.Position*194+34), 36);
GradientValue.Markers.Move += <span style="color:Blue; new EventHandler(GradientEditorControl_Move);
GradientValue.Markers.DoubleClick += <span style="color:Blue; new EventHandler(GradientEditorControl_DoubleClick);
}
<span style="color:Blue; this.Invalidate(<span style="color:Blue; true);
}
<span style="color:Blue; void GradientEditorControl_DoubleClick(<span style="color:Blue; object sender, EventArgs e)
{
GradientMarker m = (GradientMarker)sender;
ColorSelect.Color = m.GradientColor;
<span style="color:Blue; if (ColorSelect.ShowDialog() == DialogResult.OK)
{
m.GradientColor = ColorSelect.Color;
<span style="color:Blue; this.Invalidate(<span style="color:Blue; true);
}
}
[/code]
<br/>
How come it register the event each time i open the editor, and how do i get rid of it...?
View the full article