0

The ContextMenuStrip doesn't scale when its parent Form is dragged between monitors of different resolution/scaling. The ContextMenuStrip is correctly shown with correct scaling for whatever screen it is first displayed on but then it (incorrectly) keeps that same scaling when shown on any other screen (even if that other screen requires different scaling).

For example, when displayed for the first time on a 1920x1080/100% Scaling screen, the ContextMenuStrip scaling is correct:

Image of contextmenustrip with correct scaling

If the Form is then moved to a 4k/250% Scaling screen, the ContextMenuStrip is shown at 1:1 scaling and, as a result, is far too small on the high DPI screen:

Image of contextmenustrip with incorrect scaling

What is the best work-around for this issue?

JohnC
  • 81
  • 1
  • 5

1 Answers1

0

A brute-force solution is to regenerate the ContextMenuStrip each time it is shown. A possibly lower overhead, though still inelegant, solution is to regenerate the ContextMenuStrip on DpiChanged events as shown below. It doesn't appear that calling Refresh(), PerformLayout() or Invalidate() on the ContextMenuStrip is sufficient to force it to scale. But generating a new ContextMenuStrip even without regenerating the menu items does seem to force rescaling.

private void Form1_DpiChanged(object sender, DpiChangedEventArgs e)
    {
    this.ContextMenuStrip = new ContextMenuStrip(components);
    this.ContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
    this.menu1ToolStripMenuItem,
    this.menu2ToolStripMenuItem});
    }

Is there a cleaner solution than this?

JohnC
  • 81
  • 1
  • 5
  • For me it's still not sufficient: I have to regenerate the items as well to rescale. VS2022, Win11, 100% (primary) & 175%. – Daniel Feb 01 '23 at 16:54