@@ -30,7 +30,6 @@ public FloatingForm(string text, int textSize, string loc, Screen screen = null)
3030 }
3131
3232 private void ApplySupersampling ( string text , int textSize ) {
33- // 参数校验,防止 textSize 无效导致 ArgumentException
3433 if ( string . IsNullOrEmpty ( text ) || textSize <= 0 )
3534 return ;
3635
@@ -48,33 +47,44 @@ private void ApplySupersampling(string text, int textSize) {
4847 graphics . SmoothingMode = System . Drawing . Drawing2D . SmoothingMode . AntiAlias ;
4948 graphics . Clear ( Color . Transparent ) ;
5049
51- Color customColor = Color . FromArgb ( 255 , 128 , 0 ) ;
5250 using ( Font font = new Font ( "Calibri" , textSize , FontStyle . Bold , GraphicsUnit . World ) ) {
53- using ( Brush brush = new SolidBrush ( Color . FromArgb ( 255 , 128 , 0 ) ) ) {
54- graphics . DrawString ( text , font , brush , new PointF ( 0 , 0 ) ) ;
55- }
56-
5751 PointF point = new PointF ( 0 , 0 ) ;
5852 for ( int i = 0 ; i < lines . Length ; i ++ ) {
5953 string [ ] parts = lines [ i ] . Split ( ':' ) ;
6054 if ( parts . Length > 1 ) {
61- string title = parts [ 0 ] . Trim ( ) ;
62- customColor = GetColorForTitle ( title ) ;
63- using ( Brush brush = new SolidBrush ( customColor ) ) {
64- for ( int j = 1 ; j <= i ; j ++ )
65- title = '\n ' + title ;
66- graphics . DrawString ( title , font , brush , point ) ;
67- }
55+ string title = parts [ 0 ] . Trim ( ) + ":" ;
56+ string value = " " + parts [ 1 ] . Trim ( ) ;
57+ Color titleColor = GetColorForTitle ( parts [ 0 ] . Trim ( ) ) ;
58+
59+ // 单独绘制标题
60+ string titleWithNewlines = title ;
61+ for ( int j = 0 ; j < i ; j ++ )
62+ titleWithNewlines = '\n ' + titleWithNewlines ;
63+ SizeF titleSize = graphics . MeasureString ( titleWithNewlines , font ) ;
64+ using ( Brush brush = new SolidBrush ( titleColor ) )
65+ graphics . DrawString ( titleWithNewlines , font , brush , point ) ;
66+
67+ // 单独绘制值,紧接标题之后
68+ string valueWithNewlines = value ;
69+ for ( int j = 0 ; j < i ; j ++ )
70+ valueWithNewlines = '\n ' + valueWithNewlines ;
71+ using ( Brush brush = new SolidBrush ( Color . FromArgb ( 255 , 128 , 0 ) ) )
72+ graphics . DrawString ( valueWithNewlines , font , brush , new PointF ( titleSize . Width , point . Y ) ) ;
73+ } else {
74+ string lineWithNewlines = lines [ i ] ;
75+ for ( int j = 0 ; j < i ; j ++ )
76+ lineWithNewlines = '\n ' + lineWithNewlines ;
77+ using ( Brush brush = new SolidBrush ( Color . FromArgb ( 255 , 128 , 0 ) ) )
78+ graphics . DrawString ( lineWithNewlines , font , brush , point ) ;
6879 }
6980 }
7081 }
7182 }
7283
73- // 先释放旧图像,再赋新值
7484 var oldImage = displayPictureBox . Image ;
7585 displayPictureBox . Image = newBitmap ;
7686 displayPictureBox . Size = newBitmap . Size ;
77- oldImage ? . Dispose ( ) ; // Dispose 放在赋值之后,避免控件引用悬空
87+ oldImage ? . Dispose ( ) ;
7888
7989 if ( IsHandleCreated )
8090 RenderLayered ( newBitmap ) ;
0 commit comments