おそらく内部ではGetDpiForMonitorを呼び出しているだろうと思われるが、GetDpiForMonitorはuintを返すのにDeviceDpiNew,DeviceDpiOldプロパティはなぜint型なのか
Control.DeviceDpiがintになっているのでこれのせいだと思いますが理由が良く分かりませんね。
負数を扱う箇所を見つけられれば理由がわかると思いますが探せませんでした。
あとGetDpiForMonitorはWin8.1時代のDPI処理のAPIなのでWin10の内部ではGetDpiForWindowが使用されます。
そもそもなぜSystem.ComponentModel.CancelEventArgsの派生クラスとして定義されているのか、Cancelプロパティは何を行うのか?
該当する処理は以下。自前で処理を行いたい場合にキャンセルすれば4.7で実装されたDpi変更処理が実施されないということだと思います。
C#
1 protected virtual void OnDpiChanged ( DpiChangedEventArgs e )
2 {
3 if ( e . DeviceDpiNew != e . DeviceDpiOld )
4 {
5 CommonProperties . xClearAllPreferredSizeCaches ( this ) ;
6 DpiChangedEventHandler dpiChangedEventHandler = ( DpiChangedEventHandler ) base . Events [ Form . EVENT_DPI_CHANGED ] ;
7 if ( dpiChangedEventHandler != null )
8 {
9 dpiChangedEventHandler ( this , e ) ;
10 }
11 if ( ! e . Cancel )
12 {
13 float num = ( float ) e . DeviceDpiNew / ( float ) e . DeviceDpiOld ;
14 base . SuspendAllLayout ( this ) ;
15 try
16 {
17 SafeNativeMethods . SetWindowPos ( new HandleRef ( this , base . HandleInternal ) , NativeMethods . NullHandleRef , e . SuggestedRectangle . X , e . SuggestedRectangle . Y , e . SuggestedRectangle . Width , e . SuggestedRectangle . Height , 20 ) ;
18 if ( base . AutoScaleMode != AutoScaleMode . Font )
19 {
20 this . Font = new Font ( this . Font . FontFamily , this . Font . Size * num , this . Font . Style ) ;
21 base . FormDpiChanged ( num ) ;
22 }
23 else
24 {
25 base . ScaleFont ( num ) ;
26 base . FormDpiChanged ( num ) ;
27 }
28 }
29 finally
30 {
31 base . ResumeAllLayout ( this , false ) ;
32 }
33 }
34 }
35 }
36
2017/09/29 02:21
2017/09/29 02:42
2017/09/29 03:26