先贴代码:
如下是控件的部分代码:    public partial class GridControlEx : GridControl
    {
       public GridControlEx()
        {
            InitializeComponent();
        }        private void InitializeComponent()
        {
            ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
            this.SuspendLayout();
            // 
            // GridControlEx
            // 
            this.EmbeddedNavigator.Buttons.Append.Visible = false;
            this.EmbeddedNavigator.Buttons.CancelEdit.Visible = false;
            this.EmbeddedNavigator.Buttons.Edit.Visible = false;
            this.EmbeddedNavigator.Buttons.EndEdit.Visible = false;
            this.EmbeddedNavigator.Buttons.First.Visible = false;
            this.EmbeddedNavigator.Buttons.Last.Visible = false;
            this.EmbeddedNavigator.Buttons.Next.Visible = false;
            this.EmbeddedNavigator.Buttons.NextPage.Visible = false;
            this.EmbeddedNavigator.Buttons.Prev.Visible = false;
            this.EmbeddedNavigator.Buttons.PrevPage.Visible = false;
            this.EmbeddedNavigator.Buttons.Remove.Visible = false;
            this.EmbeddedNavigator.CustomButtons.AddRange(
                new DevExpress.XtraEditors.NavigatorCustomButton[] {
            new DevExpress.XtraEditors.NavigatorCustomButton(0, -1, true, true, "首页", "FirstPage"),
            new DevExpress.XtraEditors.NavigatorCustomButton(1, -1, true, true, "上一页", "PrevPage"),
            new DevExpress.XtraEditors.NavigatorCustomButton(2, -1, true, true, "下一页", "NextPage"),
            new DevExpress.XtraEditors.NavigatorCustomButton(3, -1, true, true, "尾页", "LastPage")});

            this.EmbeddedNavigator.TextStringFormat = "记录 {0}/{1}";
            this.EmbeddedNavigator.ButtonClick += new DevExpress.XtraEditors.NavigatorButtonClickEventHandler(this.GridControlEx_EmbeddedNavigator_ButtonClick);
            this.UseEmbeddedNavigator = true;
            ((System.ComponentModel.ISupportInitialize)(this)).EndInit();
            this.ResumeLayout(false);        }如下是控件使用生成的代码:            // 
            // gridControlEx1
            // 
            this.gridControlEx1.EmbeddedNavigator.Buttons.Append.Visible = false;
            this.gridControlEx1.EmbeddedNavigator.Buttons.CancelEdit.Visible = false;
            this.gridControlEx1.EmbeddedNavigator.Buttons.Edit.Visible = false;
            this.gridControlEx1.EmbeddedNavigator.Buttons.EndEdit.Visible = false;
            this.gridControlEx1.EmbeddedNavigator.Buttons.First.Visible = false;
            this.gridControlEx1.EmbeddedNavigator.Buttons.Last.Visible = false;
            this.gridControlEx1.EmbeddedNavigator.Buttons.Next.Visible = false;
            this.gridControlEx1.EmbeddedNavigator.Buttons.NextPage.Visible = false;
            this.gridControlEx1.EmbeddedNavigator.Buttons.Prev.Visible = false;
            this.gridControlEx1.EmbeddedNavigator.Buttons.PrevPage.Visible = false;
            this.gridControlEx1.EmbeddedNavigator.Buttons.Remove.Visible = false;
            this.gridControlEx1.EmbeddedNavigator.CustomButtons.AddRange(new DevExpress.XtraEditors.NavigatorCustomButton[] {
            new DevExpress.XtraEditors.NavigatorCustomButton(0, -1, true, true, "首页", "FirstPage"),
            new DevExpress.XtraEditors.NavigatorCustomButton(1, -1, true, true, "上一页", "PrevPage"),
            new DevExpress.XtraEditors.NavigatorCustomButton(2, -1, true, true, "下一页", "NextPage"),
            new DevExpress.XtraEditors.NavigatorCustomButton(3, -1, true, true, "尾页", "LastPage")});

            this.gridControlEx1.EmbeddedNavigator.TextStringFormat = "记录 {0}/{1}";
            this.gridControlEx1.Location = new System.Drawing.Point(329, 157);
            this.gridControlEx1.Name = "gridControlEx1";
            this.gridControlEx1.PageIndex = 0;
            this.gridControlEx1.PageSize = 10;
            this.gridControlEx1.RecordCount = 0;
            this.gridControlEx1.Size = new System.Drawing.Size(400, 200);
            this.gridControlEx1.TabIndex = 3;
            this.gridControlEx1.UseEmbeddedNavigator = true;我怎样才能让使用时不重复,
红色部分是按钮,本意是只生成4个按钮,但使用控件时却变成了8个,主要原因是后面的代码自动添加了重复的代码,请问我怎样处理

解决方案 »

  1.   

    GridControl是个三方控件吧,没用过这个类。
      

  2.   

    this.gridControlEx1.EmbeddedNavigator.CustomButtons.AddRange
    就是这个地方的问题,控件初始化定义了一次,窗口中又自动生成了一次,其实所有的属性都重复了只不过没关系,但按钮就有问题了
      

  3.   


            //隐藏设计属性
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
            //重新设置默认值
            [DefaultValue(typeof(HorizontalAlignment), "Right")]
            public new HorizontalAlignment TextAlign
            {
                get { return base.TextAlign; }
            }控件被继承,你可以考虑重写被继承的属性,但要记得加new,不知我这样回答是不是你想要的。
      

  4.   

    你继承的时候可以覆盖那几个按钮的new方法,不让当然是8个了,而且你的父类好像应该写成虚方法,这样在子类里实现就不会产生多出来的按钮了
      

  5.   

    通过设置这个属性,解决了问题
     [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]