Cant resize UserControl

53 views Asked by At

I am trying to write a simple extension for VBIDE. My problem is that the UserControl (WinForm) does not stretch to the width of the dockable window and does not resize when the window is resized.

This is ToolWindow with control: enter image description here

Control.Designer.cs:

private void InitializeComponent()
{
    this.components = new System.ComponentModel.Container();
    this.commandLineBox = new System.Windows.Forms.RichTextBox();
    this.resultLabel = new System.Windows.Forms.Label();
    this.resultToolTip = new System.Windows.Forms.ToolTip(this.components);
    this.SuspendLayout();
    // 
    // commandLineBox
    // 
    this.commandLineBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
    this.commandLineBox.Dock = System.Windows.Forms.DockStyle.Top;
    this.commandLineBox.Location = new System.Drawing.Point(0, 0);
    this.commandLineBox.Name = "commandLineBox";
    this.commandLineBox.TabIndex = 0;
    this.commandLineBox.Text = "";
    this.commandLineBox.Enter += new System.EventHandler(this.commandLineBox_Enter);
    this.commandLineBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.commandLineBox_KeyDown);
    // 
    // resultLabel
    // 
    this.resultLabel.AutoSize = true;
    this.resultLabel.Dock = System.Windows.Forms.DockStyle.Top;
    this.resultLabel.Location = new System.Drawing.Point(0, 38);
    this.resultLabel.Name = "resultLabel";
    this.resultLabel.TabIndex = 1;
    this.resultLabel.TextChanged += new System.EventHandler(this.resultLabel_TextChanged);
    // 
    // Terminal
    // 
    this.Controls.Add(this.resultLabel);
    this.Controls.Add(this.commandLineBox);
    this.Name = "Terminal";
    this.Dock = System.Windows.Forms.DockStyle.Fill;
    this.ResumeLayout(false);

}

I'm trying to change control.Dock to DockStyle.Fill in the Extension class after displaying the window, but control = null:

enter image description here

    public class Extension : IDTExtensibility2
    {
        private VBEWrapper _wrapper;
        private VB.AddIn _addin;
        private VB.Window terminalWindow;
        public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
        {
            _wrapper = VBEWrapper.GetInstance((VB.VBE)Application);
            _addin = (VB.AddIn)AddInInst;
            
            switch (ConnectMode)
            {   
                case ext_ConnectMode.ext_cm_AfterStartup:
                    CreateWindow();
                    break;
                case ext_ConnectMode.ext_cm_Startup:
                    break;
            }
        }

        private void CreateWindow()
        {
            Termin control = null;
            try
            {
                terminalWindow = _wrapper.VBE.Windows.CreateToolWindow(
                            _addin,
                            "VBATerminal.Terminal",
                            "Terminal",
                            "EE7EEC61-E607-44B8-830F-34839672CD30",
                             control);
                terminalWindow.Visible = true;
                const int defaultWidth = 350;
                const int defaultHeight = 200;

                if (terminalWindow.Width < defaultWidth)
                {
                    terminalWindow.Width = defaultWidth;
                }

                if (terminalWindow.Height < defaultHeight)
                {
                    terminalWindow.Height = defaultHeight;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
//
    }
}

EDIT:

Here's a variant that should (I guess) assign a value to control, but it doesn't do that either:

object control = null
terminalWindow = _wrapper.VBE.Windows.CreateToolWindow(
            _addin,
            "VBATerminal.Terminal",
            "terminal",
            "EE7EEC61-E607-44B8-830F-34839672CD30",
             ref control);

What am I doing wrong?

0

There are 0 answers