无法调整 UserControl 的大小

Cant resize UserControl

提问人:artodoro 提问时间:11/9/2023 最后编辑:artodoro 更新时间:11/9/2023 访问量:50

问:

我正在尝试为VBIDE编写一个简单的扩展。我的问题是UserControl(WinForm)不会拉伸到可停靠窗口的宽度,并且在调整窗口大小时不会调整大小。

这是具有控件的 ToolWindow: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);

}

我试图在显示窗口后更改为在课堂上,但是:control.DockDockStyle.FillExtensioncontrol = 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());
            }
        }
//
    }
}

编辑:

这是一个变体,它应该(我猜)分配一个值来控制,但它也没有这样做:

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

我做错了什么?

C# .NET COM 加载项 VBIDE

评论

0赞 shingo 11/9/2023
你在哪里为控制变量赋值?我不知道这个函数是做什么的,但是这种传递参数的方法不能为变量赋值。CreateToolWindow
0赞 artodoro 11/9/2023
你是对的。这是一个变体,它应该(我猜)为控件分配一个值,但它也不这样做: ''' object control = null terminalWindow = _wrapper。VBE的。Windows.CreateToolWindow( _addin, “VBATerminal.Terminal”, { “终端”, “EE7EEC61-E607-44B8-830F-34839672CD30”, ref control);
0赞 shingo 11/9/2023
控制仍然为空吗?正如我所说,我不知道这个函数是做什么的,也许作者犯了同样的错误。CreateToolWindow
0赞 artodoro 11/9/2023
是的,执行函数后 control = null。这是关于它的文档:learn.microsoft.com/en-us/office/vba/language/reference/...
0赞 shingo 11/9/2023
我的意思是您的代码显示这是一个包装器,返回值可能会被错误地忽略。

答: 暂无答案