RightButton in ultratexteditor allways adds by itself after changing form which ultratexteditor in and compiling.
The reason is sentense "UltraTextEditor.RightButton.Add(DropdownEditorButton1)" in file .designer.cs executed several times.
How can I resolve it? Thanks.
I'm not sure what your question is. If you have the line in the designer.cs file, that means that .NET serialized a button that was added at design-time. Are you saying that the button wasn't there originally and that it's being added when you copy and paste the control onto another form? I'm not sure how that would happen, unless you subclassed the UltraTextEditor and are doing your own processing.
-Matt
Hi Matt,
The Steps to Reproduce the question as folows:
1.Create a new Component base on UltraTextEditor, then add a right button to the ultraTextEditor.
2.compile
3.Create a new form,drag the component created in step 1 to the form.
4.compile
5.Relocate the component, and then Compile.
6.Close the form, and then open the form.Now the component has tows right buttons.
7.Repeat the steps 5,6. The right button in the component add byitself one at a time.
Thanks.
If you're deriving from the control, which it sounds like you are, you will have to make sure that you're not adding the same button multiple times. Where are you adding the button? What's happening here is that you add the button and the code serializes the ButtonsRight collection, so you'll have serialized code adding the button. Now when you re-load the designer, your constructor will add a button and then the designer will load the serialized button, leading to you having two buttons. One approach might be to override OnCreateControl, call the base first, and then check to see if the button's Key exists in the ButtonsRight collection before adding it.
Thanks, I resolved the problem followes you said. The Code I writen as follows:
public partial class GridCombo : UltraTextEditor { public GridCombo() { InitializeComponent(); }
protected override void OnCreateControl() { base.OnCreateControl(); if (DesignMode || ButtonsRight.Exists("DropDownButton")) return;
DropDownEditorButton editorButton = new DropDownEditorButton(); editorButton.Key = "DropDownButton"; editorButton.RightAlignDropDown = Infragistics.Win.DefaultableBoolean.False; editorButton.AutoFocus = false; editorButton.Control = popGrid1; // popGrid1 is an User Control
ButtonsRight.Add(editorButton); } }