0

I am making a clipboard utility that pastes data into the (last) active application by updating the clipboard like this:

System.Windows.Clipboard.SetText("Some Text",System.Windows.TextDataFormat.Text);
SendKeys.Send("^v");

My main application method is using the [STAThread] attribute and for some reason the SetText() method resizes my form to half the size and moves it to the center of the screen in some way that I thought was scaling it but it remains 1.0 for all the controls, maybe it is increasing the DPI?

Does anyone know what could be causing the form to resize? Or an alternative to SetText (and the other Clipboard.Set* methods) for updating the clipboard?

tkefauver
  • 491
  • 5
  • 19
  • 1
    This is something that can happen on recent Win10 versions, the SetProcessDPIAware() function is immediately effective instead of having to be called at program startup. Which revealed a lot of bugs in utilities and libraries, the kind that must never make this call. WPF is a notable violator. Seeing this happen for Clipboard.SetText() is pretty unusual, but possible on machines that have a clipboard listener utility running. The best way to find that evil code is by using Task Manager, Processes tab. Kill processes one by one until the behavior disappears. – Hans Passant Sep 21 '19 at 09:19
  • @HansPassant Thank you for the info! I neglected to mention the important fact I'm on a Mac running Windows 10 on Parallels with graphics set to "Enhance for Retina Display" and I added a call to SetProcessDPIAware() before InitializeComponent() in the problematic form and it works fine now. I have 3 displays and Windows is on one w/ a much lower resolution/DPI than my main MBP monitor and the call to SetText was changing the Form's DPI to my main monitors. – tkefauver Sep 21 '19 at 11:45
  • Do favor using the manifest: https://stackoverflow.com/a/13228495/17034 – Hans Passant Sep 21 '19 at 12:24

0 Answers0