0

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?

6
  • Where did you assign a value to the control variable? I don't know what this CreateToolWindow function does, but this method of passing argument cannot assign any value to the variable. Commented Nov 9, 2023 at 8:50
  • You're right. 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); ``` Commented Nov 9, 2023 at 8:57
  • Is control still null? As I said I don't know what this CreateToolWindow function does, maybe the author made the same mistake. Commented Nov 9, 2023 at 9:24
  • yes, control = null after the function is executed. Here is the documentation on it: learn.microsoft.com/en-us/office/vba/language/reference/… Commented Nov 9, 2023 at 9:29
  • I mean your code shows that is a wrapper, the return value may be ignored by mistake. Commented Nov 9, 2023 at 10:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.