@@ -51,9 +51,8 @@ public CustomDialog(string caption, string message, int acceptButton, int cancel
5151
5252 using ( Graphics g = this . CreateGraphics ( ) )
5353 {
54- Rectangle screen = Screen . PrimaryScreen . WorkingArea ;
55- SizeF size = g . MeasureString ( message , label . Font , screen . Width - 20 ) ;
56- Size clientSize = size . ToSize ( ) ;
54+ SizeF size = TextRenderer . MeasureText ( message , label . Font ) ;
55+ Size clientSize = new Size ( ( int ) ( size . Width * 96 / g . DpiX ) + DockPadding . Left + DockPadding . Right , ( int ) ( size . Height * 96 / g . DpiY ) + DockPadding . Top + DockPadding . Bottom ) ;
5756 Button [ ] buttons = new Button [ buttonLabels . Length ] ;
5857 int [ ] positions = new int [ buttonLabels . Length ] ;
5958 int pos = 0 ;
@@ -65,8 +64,8 @@ public CustomDialog(string caption, string message, int acceptButton, int cancel
6564 string buttonLabel = buttonLabels [ i ] ;
6665 newButton . Text = buttonLabel ;
6766 newButton . Click += new EventHandler ( ButtonClick ) ;
68- SizeF buttonSize = g . MeasureString ( buttonLabel , newButton . Font ) ;
69- newButton . Width = Math . Max ( newButton . Width , ( ( int ) Math . Ceiling ( buttonSize . Width / 8.0 ) + 1 ) * 8 ) ;
67+ SizeF buttonSize = TextRenderer . MeasureText ( buttonLabel , newButton . Font ) ;
68+ newButton . Width = Math . Max ( newButton . Width , ( ( int ) Math . Ceiling ( buttonSize . Width * 96 / g . DpiX / 8.0 ) + 1 ) * 8 ) ;
7069 positions [ i ] = pos ;
7170 buttons [ i ] = newButton ;
7271 pos += newButton . Width + 4 ;
0 commit comments