Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net Excel VSTO应用程序中可调整大小的winform控件出现问题_.net_Winforms_Vsto - Fatal编程技术网

.net Excel VSTO应用程序中可调整大小的winform控件出现问题

.net Excel VSTO应用程序中可调整大小的winform控件出现问题,.net,winforms,vsto,.net,Winforms,Vsto,我正在将Winforms控件添加到Excel工作表中。该控件继承自ListView,只需添加用户通过抓住右下角来调整其大小的功能,如下所示: //This solution taken from //http://stackoverflow.com/questions/1535826/resize-borderless-window-on-bottom-right-corner/1535943#1535943 public class MyListView : ListView { p

我正在将Winforms控件添加到Excel工作表中。该控件继承自ListView,只需添加用户通过抓住右下角来调整其大小的功能,如下所示:

//This solution taken from 
//http://stackoverflow.com/questions/1535826/resize-borderless-window-on-bottom-right-corner/1535943#1535943
public class MyListView : ListView
{
    protected override void WndProc(ref Message m)
    {
        const int wmNcHitTest = 0x84;
        const int htBottomLeft = 16;
        const int htBottomRight = 17;
        if (m.Msg == wmNcHitTest)
        {
            int x = (int)(m.LParam.ToInt64() & 0xFFFF);
            int y = (int)((m.LParam.ToInt64() & 0xFFFF0000) >> 16);
            Point pt = PointToClient(new Point(x, y));
            Size clientSize = ClientSize;
            if (pt.X >= clientSize.Width - 16 && pt.Y >= clientSize.Height - 16 && clientSize.Height >= 16)
            {
                m.Result = (IntPtr)(IsMirrored ? htBottomLeft : htBottomRight);
                return;
            }
        }
        base.WndProc(ref m);
    }
}
此控件将添加到我的工作表中:

MyListView listView = new MyListView();

Microsoft.Office.Tools.Excel.Worksheet worksheet =
  Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.Sheets[1]);

worksheet.Controls.AddControl(listView, 0, 0, 100, 100, "myListView01");
有了这个,我可以通过抓住右下角并向左/向上拖动来缩小控件


问题是我无法将其放大,因为它不允许将光标拖过MyListView的右/下边框。在做了一些调查之后,我认为这是因为通过VSTO添加到工作表中的所有控件都由一个名为VSTOContainerControl的控件作为父控件,该控件的大小总是设置为与其子控件相同。这一事实在MSDN博客上得到了证实。我发现,如果通过编程增加父VSTOContainerControl的大小,子MyListView也会自动增加。但是,我需要用户能够随意手动增加大小。如何实现这一点?

我建议在listview和容器控件之间留出一个小的边距,这样您就可以将调整大小手柄拖动几个像素,并通过编程将容器的大小固定为新的大小+边距。可以在事件处理程序中对用户尝试调整大小时触发的任何事件调整容器大小。

我建议在listview和容器控件之间留出一小段空白,以便您可以拖动调整大小处理程序几个像素,并通过编程将容器的大小固定为新的大小+边距。当用户尝试调整容器大小时,可以在事件处理程序中为触发的任何事件调整容器大小