Working in c# with System.Windows.Forms objects in .NET Framework 4.6.1, I have implemented a context menu item to copy a text to the Windows clipboard. When this method is entered, the size of the form is reduced by roughly 20%.
public override void copyXmlTextToClipboard()
{
string xmlText = xmlNode.OuterXml;
System.Windows.Clipboard.SetText(xmlText);
}
If I remove the reference to the Windows clipboard by commenting the line like this
public override void copyXmlTextToClipboard()
{
string xmlText = xmlNode.OuterXml;
// System.Windows.Clipboard.SetText(xmlText);
}
then the method executes without modifying the form size (but of course also doesn't copy anything to the clipboard). So the problem is definitely related to the reference to the clipboard.
The funny thing is that just entering the method causes the problem before the clipboard is actually accessed. I set a breakpoint on the first opening curly bracket of the method. On hitting the breakpoint, the form size is OK, but on the first single-step into the method before executing the first line, the form size is changed.
This is the appearance before entering the method:
This is the appearance after the method has been entered, but before any line of code in it has been executed:
Can anyone explain this behavior or propose a solution?