Trouble with resizable winform control in Excel VSTO application
-
יום שלישי 17 יולי 2012 19:16
Hi Everyone,
In my application-level VSTO 2.0/C#/.NET4.0 excel add-in, I am adding a Winforms control to an Excel worksheet. The control inherits from ListView and simply adds the ability for a user to resize it by "grabbing" the bottom right corner, like so:
//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 ? htBottom return; } } base.WndProc(ref m); } }
This control gets added to my worksheet:
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");
With this, I am able to make the control smaller by grabbing the bottom right corner and dragging it left/upwards.
The problem is that I am not able to make it larger because it won't allow dragging the cursor past the right/bottom borders of MyListView. After doing some investigation, I believe that this is occurring because all controls that get added to the worksheet via VSTO are parented by a control called VSTOContainerControl, who's size is always set to be the same as it's child control. This fact is confirmed on an MSDN blog here. I discovered that if I programatically increase the size of the parent VSTOContainerControl, the child MyListView automatically increases as well. However, I need the ability for the user to manually increase the size at will. How can I achieve this?
כל התגובות
-
יום שישי 20 יולי 2012 06:37מנחה דיון
Hi daniel.ling.sungard,
Thanks for posting in the MSDN Forum.
I will involve some experts into this issue to see whether they can help you out. There might be some time delay, appreciate for you patience.
Have a good day,
Tom
Tom Xu [MSFT]
MSDN Community Support | Feedback to us
-
יום שישי 20 יולי 2012 09:02מנחה דיון
Daniel,
Would you please clarify the VS and Office version? VSTO 2.0 should be with VS 2005, so "VSTO 2.0/C#/.NET4.0" is kind of confusing.
Thanks.
Forrest Guo | MSDN Community Support | Feedback to manager