@@ -190,6 +190,15 @@ public override string Text
190
190
}
191
191
}
192
192
193
+ private bool useCustomFont = false ;
194
+ [ DefaultValue ( false ) ]
195
+ [ Category ( PoisonDefaults . PropertyCategory . Appearance ) ]
196
+ public bool UseCustomFont {
197
+ get => useCustomFont ;
198
+ set { useCustomFont = value ; Refresh ( ) ; }
199
+ }
200
+
201
+
193
202
[ DefaultValue ( PoisonComboBoxSize . Medium ) ]
194
203
[ Category ( PoisonDefaults . PropertyCategory . Appearance ) ]
195
204
public PoisonComboBoxSize FontSize { get ; set ; } = PoisonComboBoxSize . Medium ;
@@ -220,13 +229,6 @@ public string PromptText
220
229
221
230
private bool drawPrompt = false ;
222
231
223
- [ Browsable ( false ) ]
224
- public override Font Font
225
- {
226
- get => base . Font ;
227
- set => base . Font = value ;
228
- }
229
-
230
232
private AutoCompleteMode autoCompleteMode = AutoCompleteMode . None ;
231
233
public new AutoCompleteMode AutoCompleteMode
232
234
{
@@ -273,6 +275,23 @@ public override Font Font
273
275
274
276
#endregion
275
277
278
+ #region Routing Fields
279
+ public override Font Font {
280
+ get {
281
+ if ( useCustomFont )
282
+ return base . Font ;
283
+ else
284
+ return PoisonFonts . ComboBox ( FontSize , FontWeight ) ;
285
+ }
286
+ set {
287
+ base . Font = value ;
288
+ Refresh ( ) ;
289
+ }
290
+ }
291
+
292
+ #endregion
293
+
294
+
276
295
#region Constructor
277
296
278
297
public PoisonComboBox ( )
@@ -296,7 +315,7 @@ public PoisonComboBox()
296
315
textBox . Location = new System . Drawing . Point ( 0 , 0 ) ;
297
316
textBox . FontSize = ( PoisonTextBoxSize ) FontSize ;
298
317
textBox . FontWeight = ( PoisonTextBoxWeight ) FontWeight ;
299
- textBox . WaterMarkFont = PoisonFonts . ComboBox ( FontSize , FontWeight ) ;
318
+ textBox . WaterMarkFont = Font ;
300
319
textBox . Size = Size ;
301
320
textBox . TabIndex = 0 ;
302
321
textBox . Margin = new Padding ( 0 ) ;
@@ -443,11 +462,11 @@ protected virtual void OnPaintForeground(PaintEventArgs e)
443
462
444
463
if ( Enabled )
445
464
{
446
- TextRenderer . DrawText ( e . Graphics , Text , PoisonFonts . ComboBox ( FontSize , FontWeight ) , textRect , foreColor , TextFormatFlags . Left | TextFormatFlags . VerticalCenter ) ;
465
+ TextRenderer . DrawText ( e . Graphics , Text , Font , textRect , foreColor , TextFormatFlags . Left | TextFormatFlags . VerticalCenter ) ;
447
466
}
448
467
else
449
468
{
450
- ControlPaint . DrawStringDisabled ( e . Graphics , Text , PoisonFonts . ComboBox ( FontSize , FontWeight ) , PoisonPaint . ForeColor . ComboBox . Disabled ( Theme ) , textRect , TextFormatFlags . Left | TextFormatFlags . VerticalCenter ) ;
469
+ ControlPaint . DrawStringDisabled ( e . Graphics , Text , Font , PoisonPaint . ForeColor . ComboBox . Disabled ( Theme ) , textRect , TextFormatFlags . Left | TextFormatFlags . VerticalCenter ) ;
451
470
}
452
471
453
472
OnCustomPaintForeground ( new PoisonPaintEventArgs ( Color . Empty , foreColor , e . Graphics ) ) ;
@@ -493,12 +512,12 @@ protected override void OnDrawItem(DrawItemEventArgs e)
493
512
if ( DropDownStyle != ComboBoxStyle . DropDown )
494
513
{
495
514
Rectangle textRect = new ( 0 , e . Bounds . Top , e . Bounds . Width , e . Bounds . Height ) ;
496
- TextRenderer . DrawText ( e . Graphics , GetItemText ( Items [ e . Index ] ) , PoisonFonts . ComboBox ( FontSize , FontWeight ) , textRect , foreColor , TextFormatFlags . Left | TextFormatFlags . VerticalCenter ) ;
515
+ TextRenderer . DrawText ( e . Graphics , GetItemText ( Items [ e . Index ] ) , Font , textRect , foreColor , TextFormatFlags . Left | TextFormatFlags . VerticalCenter ) ;
497
516
}
498
517
else
499
518
{
500
519
Rectangle textRect = new ( 0 , e . Bounds . Top , textBox . Width , e . Bounds . Height ) ;
501
- TextRenderer . DrawText ( e . Graphics , GetItemText ( Items [ e . Index ] ) , PoisonFonts . ComboBox ( FontSize , FontWeight ) , textRect , foreColor , TextFormatFlags . Left | TextFormatFlags . VerticalCenter ) ;
520
+ TextRenderer . DrawText ( e . Graphics , GetItemText ( Items [ e . Index ] ) , Font , textRect , foreColor , TextFormatFlags . Left | TextFormatFlags . VerticalCenter ) ;
502
521
}
503
522
}
504
523
else
@@ -524,7 +543,7 @@ private void DrawTextPrompt(Graphics g)
524
543
}
525
544
526
545
Rectangle textRect = new ( 2 , 2 , Width - 20 , Height - 4 ) ;
527
- TextRenderer . DrawText ( g , promptText , PoisonFonts . ComboBox ( FontSize , FontWeight ) , textRect , SystemColors . GrayText , backColor , TextFormatFlags . Left | TextFormatFlags . VerticalCenter | TextFormatFlags . EndEllipsis ) ;
546
+ TextRenderer . DrawText ( g , promptText , Font , textRect , SystemColors . GrayText , backColor , TextFormatFlags . Left | TextFormatFlags . VerticalCenter | TextFormatFlags . EndEllipsis ) ;
528
547
}
529
548
530
549
#endregion
@@ -662,7 +681,7 @@ public override Size GetPreferredSize(Size proposedSize)
662
681
{
663
682
string measureText = Text . Length > 0 ? Text : "MeasureText" ;
664
683
proposedSize = new ( int . MaxValue , int . MaxValue ) ;
665
- preferredSize = TextRenderer . MeasureText ( g , measureText , PoisonFonts . ComboBox ( FontSize , FontWeight ) , proposedSize , TextFormatFlags . Left | TextFormatFlags . LeftAndRightPadding | TextFormatFlags . VerticalCenter ) ;
684
+ preferredSize = TextRenderer . MeasureText ( g , measureText , Font , proposedSize , TextFormatFlags . Left | TextFormatFlags . LeftAndRightPadding | TextFormatFlags . VerticalCenter ) ;
666
685
preferredSize . Height += 4 ;
667
686
}
668
687
0 commit comments