Как использовать Document Outline, если я создаю компонент программно? - PullRequest
0 голосов
/ 20 апреля 2020

У меня есть родительское mdi-окно MainForm, которое conatan Menu, ToolBar и StatusStrip создано из конструктора в Visual Studio.

В этом MainForm отображаются дочерние формы, содержимое которых было создано программно ( панели, текстовые поля, метки, сетки и т. д. c ...)

У меня проблема при создании DataGridView и установке Dock.Top, Dock.Fill, моя сетка скрыта за родительской панелью инструментов. Я не могу использовать Document Outline для программно созданных элементов управления. Я пытаюсь использовать BringToFront, но снова у меня возникает некоторая проблема.

Чтобы лучше понять, проверьте мой скриншот.

private void InitializeDefaultObjects()
    {
        /// SPLIT CONTAINER  

        _splitContainer = new SplitContainer()
        {
            SplitterDistance = 270,
            Panel1MinSize = 270,
            Margin = new Padding(15, 15, 15, 15),
            Dock = DockStyle.Fill,
            BackColor = Color.Gainsboro,
            BorderStyle = BorderStyle.None,
            Orientation = Orientation.Vertical,
            SplitterWidth = 4,
            FixedPanel = FixedPanel.Panel1,
            RightToLeft = RightToLeft.No,
            IsSplitterFixed = false,
            Panel1Collapsed = false,
        };
        _splitContainer.Panel1.Padding = new Padding(5, 5, 5, 5);
        _splitContainer.BringToFront();

        this.Controls.Add(this._splitContainer);

        /// TOOLSTRIP IN SPLIT CONTAINER 1
        /// This toolstrip is  merged with parent tolstrip

        _toolStrip = new System.Windows.Forms.ToolStrip();
        _toolStrip.Height = 100;
        _toolStrip.Dock = DockStyle.Bottom;
        _toolStrip.Visible = false;
        _toolStrip.SendToBack();
        _toolStrip.BringToFront();


        // Toolstrip title
        _toolStripTitleLabel = new ToolStripLabel()
        {
            Text = this.Text,
            Alignment = ToolStripItemAlignment.Left,
            Font = new Font("Segoe UI", 10F, System.Drawing.FontStyle.Bold),
            Image = this.ToolStripTitleImage,
            ImageAlign = ContentAlignment.MiddleCenter, 
            ImageScaling = ToolStripItemImageScaling.SizeToFit

        };
        // separatar
        ToolStripSeparator toolStripSeparator = new ToolStripSeparator() { Alignment = ToolStripItemAlignment.Right };

        // Close button
        ToolStripButton closeToolStripButton = new ToolStripButton()
        {
            Text = "Zatvori",
            Alignment = ToolStripItemAlignment.Right,
            Image = DFMSoftware.Core.Properties.Resource.Close_icon,
            TextImageRelation = TextImageRelation.ImageAboveText
        };

        // Close button event
        closeToolStripButton.Click += new EventHandler(closeToolStripButton_Click);

        _toolStrip.Items.Add(_toolStripTitleLabel);
        _toolStrip.Items.Add(closeToolStripButton);
        _toolStrip.Items.Add(toolStripSeparator);

        // add toolstripe to splitpanel
         this._splitContainer.Panel2.Controls.Add(_toolStrip);

        // datagridview  
        _dataGridView = new System.Windows.Forms.DataGridView();
        _dataGridView.Dock = Dock.Fill;


        // add grid to splitpanel 2
        _splitContainer.Panel2.Controls.Add(_dataGridView);


    }

Здесь в коде вы можете видеть. 1. Я создаю SplitContainer и устанавливаю BringToFront () и устанавливаю Dock.Fill 2. В SplitContainer в Panel2 я добавляю DataGridView с Dock.Fill и снова за родительским. ? Спасибо

Screensho1 Screenshot2

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...