Skip to content

Commit fa0613a

Browse files
authored
Merge pull request #201 from Hgnim/develop
Repair and Enhancement.
2 parents 8db8a78 + b11efed commit fa0613a

File tree

7 files changed

+187
-71
lines changed

7 files changed

+187
-71
lines changed

src/ReaLTaiizor/Controls/Button/PoisonButton.cs

+26-1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ public bool UseSelectable
141141
[DefaultValue(false)]
142142
[Category(PoisonDefaults.PropertyCategory.Appearance)]
143143
public bool Highlight { get; set; } = false;
144+
145+
private bool useCustomFont = false;
146+
[DefaultValue(false)]
147+
[Category(PoisonDefaults.PropertyCategory.Appearance)]
148+
public bool UseCustomFont {
149+
get => useCustomFont;
150+
set { useCustomFont = value; Refresh(); }
151+
}
152+
144153
[DefaultValue(PoisonButtonSize.Small)]
145154
[Category(PoisonDefaults.PropertyCategory.Appearance)]
146155
public PoisonButtonSize FontSize { get; set; } = PoisonButtonSize.Small;
@@ -154,6 +163,22 @@ public bool UseSelectable
154163

155164
#endregion
156165

166+
#region Routing Fields
167+
public override Font Font {
168+
get {
169+
if (useCustomFont)
170+
return base.Font;
171+
else
172+
return PoisonFonts.Button(FontSize, FontWeight);
173+
}
174+
set {
175+
base.Font = value;
176+
Refresh();
177+
}
178+
}
179+
180+
#endregion
181+
157182
#region Constructor
158183

159184
public PoisonButton()
@@ -283,7 +308,7 @@ protected virtual void OnPaintForeground(PaintEventArgs e)
283308
e.Graphics.DrawRectangle(p, borderRect);
284309
}
285310

286-
TextRenderer.DrawText(e.Graphics, Text, PoisonFonts.Button(FontSize, FontWeight), ClientRectangle, foreColor, PoisonPaint.GetTextFormatFlags(TextAlign));
311+
TextRenderer.DrawText(e.Graphics, Text, Font, ClientRectangle, foreColor, PoisonPaint.GetTextFormatFlags(TextAlign));
287312

288313
OnCustomPaintForeground(new PoisonPaintEventArgs(Color.Empty, foreColor, e.Graphics));
289314

src/ReaLTaiizor/Controls/CheckBox/PoisonCheckBox.cs

+27-9
Original file line numberDiff line numberDiff line change
@@ -137,26 +137,44 @@ public bool UseSelectable
137137
[DefaultValue(false)]
138138
[Category(PoisonDefaults.PropertyCategory.Appearance)]
139139
public bool DisplayFocus { get; set; } = false;
140+
141+
private bool useCustomFont = false;
142+
[DefaultValue(false)]
143+
[Category(PoisonDefaults.PropertyCategory.Appearance)]
144+
public bool UseCustomFont {
145+
get => useCustomFont;
146+
set { useCustomFont = value; Refresh(); }
147+
}
148+
140149
[DefaultValue(PoisonCheckBoxSize.Small)]
141150
[Category(PoisonDefaults.PropertyCategory.Appearance)]
142151
public PoisonCheckBoxSize FontSize { get; set; } = PoisonCheckBoxSize.Small;
143152
[DefaultValue(PoisonCheckBoxWeight.Regular)]
144153
[Category(PoisonDefaults.PropertyCategory.Appearance)]
145154
public PoisonCheckBoxWeight FontWeight { get; set; } = PoisonCheckBoxWeight.Regular;
146155

147-
[Browsable(false)]
148-
public override Font Font
149-
{
150-
get => base.Font;
151-
set => base.Font = value;
152-
}
153-
154156
private bool isHovered = false;
155157
private bool isPressed = false;
156158
private bool isFocused = false;
157159

158160
#endregion
159161

162+
#region Routing Fields
163+
public override Font Font {
164+
get {
165+
if (useCustomFont)
166+
return base.Font;
167+
else
168+
return PoisonFonts.CheckBox(FontSize, FontWeight);
169+
}
170+
set {
171+
base.Font = value;
172+
Refresh();
173+
}
174+
}
175+
176+
#endregion
177+
160178
#region Constructor
161179

162180
public PoisonCheckBox()
@@ -326,7 +344,7 @@ protected virtual void OnPaintForeground(PaintEventArgs e)
326344
}
327345

328346

329-
TextRenderer.DrawText(e.Graphics, Text, PoisonFonts.CheckBox(FontSize, FontWeight), textRect, foreColor, PoisonPaint.GetTextFormatFlags(TextAlign, !AutoSize));
347+
TextRenderer.DrawText(e.Graphics, Text, Font, textRect, foreColor, PoisonPaint.GetTextFormatFlags(TextAlign, !AutoSize));
330348

331349
OnCustomPaintForeground(new PoisonPaintEventArgs(Color.Empty, foreColor, e.Graphics));
332350

@@ -471,7 +489,7 @@ public override Size GetPreferredSize(Size proposedSize)
471489
using (Graphics g = CreateGraphics())
472490
{
473491
proposedSize = new(int.MaxValue, int.MaxValue);
474-
preferredSize = TextRenderer.MeasureText(g, Text, PoisonFonts.CheckBox(FontSize, FontWeight), proposedSize, PoisonPaint.GetTextFormatFlags(TextAlign));
492+
preferredSize = TextRenderer.MeasureText(g, Text, Font, proposedSize, PoisonPaint.GetTextFormatFlags(TextAlign));
475493
preferredSize.Width += 16;
476494

477495
if (CheckAlign is ContentAlignment.TopCenter or ContentAlignment.BottomCenter)

src/ReaLTaiizor/Controls/ComboBox/PoisonComboBox.cs

+33-14
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ public override string Text
190190
}
191191
}
192192

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+
193202
[DefaultValue(PoisonComboBoxSize.Medium)]
194203
[Category(PoisonDefaults.PropertyCategory.Appearance)]
195204
public PoisonComboBoxSize FontSize { get; set; } = PoisonComboBoxSize.Medium;
@@ -220,13 +229,6 @@ public string PromptText
220229

221230
private bool drawPrompt = false;
222231

223-
[Browsable(false)]
224-
public override Font Font
225-
{
226-
get => base.Font;
227-
set => base.Font = value;
228-
}
229-
230232
private AutoCompleteMode autoCompleteMode = AutoCompleteMode.None;
231233
public new AutoCompleteMode AutoCompleteMode
232234
{
@@ -273,6 +275,23 @@ public override Font Font
273275

274276
#endregion
275277

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+
276295
#region Constructor
277296

278297
public PoisonComboBox()
@@ -296,7 +315,7 @@ public PoisonComboBox()
296315
textBox.Location = new System.Drawing.Point(0, 0);
297316
textBox.FontSize = (PoisonTextBoxSize)FontSize;
298317
textBox.FontWeight = (PoisonTextBoxWeight)FontWeight;
299-
textBox.WaterMarkFont = PoisonFonts.ComboBox(FontSize, FontWeight);
318+
textBox.WaterMarkFont = Font;
300319
textBox.Size = Size;
301320
textBox.TabIndex = 0;
302321
textBox.Margin = new Padding(0);
@@ -443,11 +462,11 @@ protected virtual void OnPaintForeground(PaintEventArgs e)
443462

444463
if (Enabled)
445464
{
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);
447466
}
448467
else
449468
{
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);
451470
}
452471

453472
OnCustomPaintForeground(new PoisonPaintEventArgs(Color.Empty, foreColor, e.Graphics));
@@ -493,12 +512,12 @@ protected override void OnDrawItem(DrawItemEventArgs e)
493512
if (DropDownStyle != ComboBoxStyle.DropDown)
494513
{
495514
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);
497516
}
498517
else
499518
{
500519
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);
502521
}
503522
}
504523
else
@@ -524,7 +543,7 @@ private void DrawTextPrompt(Graphics g)
524543
}
525544

526545
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);
528547
}
529548

530549
#endregion
@@ -662,7 +681,7 @@ public override Size GetPreferredSize(Size proposedSize)
662681
{
663682
string measureText = Text.Length > 0 ? Text : "MeasureText";
664683
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);
666685
preferredSize.Height += 4;
667686
}
668687

src/ReaLTaiizor/Controls/DateTime/PoisonDateTime.cs

+27-9
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ public bool UseSelectable
137137
public bool DisplayFocus { get; set; } = false;
138138
[DefaultValue(PoisonDateTimeSize.Medium)]
139139
[Category(PoisonDefaults.PropertyCategory.Appearance)]
140+
141+
private bool useCustomFont = false;
142+
[DefaultValue(false)]
143+
[Category(PoisonDefaults.PropertyCategory.Appearance)]
144+
public bool UseCustomFont {
145+
get => useCustomFont;
146+
set { useCustomFont = value; Refresh(); }
147+
}
148+
140149
public PoisonDateTimeSize FontSize { get; set; } = PoisonDateTimeSize.Medium;
141150
[DefaultValue(PoisonDateTimeWeight.Regular)]
142151
[Category(PoisonDefaults.PropertyCategory.Appearance)]
@@ -150,19 +159,28 @@ public bool UseSelectable
150159
set => base.ShowUpDown = false;
151160
}
152161

153-
[Browsable(false)]
154-
public override Font Font
155-
{
156-
get => base.Font;
157-
set => base.Font = value;
158-
}
159-
160162
private bool isHovered = false;
161163
private bool isPressed = false;
162164
private bool isFocused = false;
163165

164166
#endregion
165167

168+
#region Routing Fields
169+
public override Font Font {
170+
get {
171+
if (useCustomFont)
172+
return base.Font;
173+
else
174+
return PoisonFonts.DateTime(FontSize, FontWeight);
175+
}
176+
set {
177+
base.Font = value;
178+
Refresh();
179+
}
180+
}
181+
182+
#endregion
183+
166184
#region Constructor
167185
public PoisonDateTime()
168186
{
@@ -291,7 +309,7 @@ protected virtual void OnPaintForeground(PaintEventArgs e)
291309

292310
Rectangle textRect = new(2 + _check, 2, Width - 20, Height - 4);
293311

294-
TextRenderer.DrawText(e.Graphics, Text, PoisonFonts.DateTime(FontSize, FontWeight), textRect, foreColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
312+
TextRenderer.DrawText(e.Graphics, Text, Font, textRect, foreColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
295313

296314
OnCustomPaintForeground(new PoisonPaintEventArgs(Color.Empty, foreColor, e.Graphics));
297315

@@ -430,7 +448,7 @@ public override Size GetPreferredSize(Size proposedSize)
430448
{
431449
string measureText = Text.Length > 0 ? Text : "MeasureText";
432450
proposedSize = new(int.MaxValue, int.MaxValue);
433-
preferredSize = TextRenderer.MeasureText(g, measureText, PoisonFonts.DateTime(FontSize, FontWeight), proposedSize, TextFormatFlags.Left | TextFormatFlags.LeftAndRightPadding | TextFormatFlags.VerticalCenter);
451+
preferredSize = TextRenderer.MeasureText(g, measureText, Font, proposedSize, TextFormatFlags.Left | TextFormatFlags.LeftAndRightPadding | TextFormatFlags.VerticalCenter);
434452
preferredSize.Height += 10;
435453
}
436454

src/ReaLTaiizor/Controls/Label/PoisonLabel.cs

+29-5
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ public bool UseSelectable
137137

138138
private readonly DoubleBufferedTextBox baseTextBox;
139139

140+
private bool useCustomFont=false;
141+
[DefaultValue(false)]
142+
[Category(PoisonDefaults.PropertyCategory.Appearance)]
143+
public bool UseCustomFont {
144+
get => useCustomFont;
145+
set { useCustomFont = value; Refresh(); }
146+
}
147+
140148
private PoisonLabelSize poisonLabelSize = PoisonLabelSize.Medium;
141149
[DefaultValue(PoisonLabelSize.Medium)]
142150
[Category(PoisonDefaults.PropertyCategory.Appearance)]
@@ -170,6 +178,22 @@ public bool WrapToLine
170178

171179
#endregion
172180

181+
#region Routing Fields
182+
public override Font Font {
183+
get {
184+
if (useCustomFont)
185+
return base.Font;
186+
else
187+
return PoisonFonts.Label(poisonLabelSize, poisonLabelWeight);
188+
}
189+
set {
190+
base.Font = value;
191+
Refresh();
192+
}
193+
}
194+
195+
#endregion
196+
173197
#region Constructor
174198

175199
public PoisonLabel()
@@ -312,13 +336,13 @@ protected virtual void OnPaintForeground(PaintEventArgs e)
312336

313337
if (!baseTextBox.Visible)
314338
{
315-
TextRenderer.DrawText(e.Graphics, Text, PoisonFonts.Label(poisonLabelSize, poisonLabelWeight), ClientRectangle, foreColor, PoisonPaint.GetTextFormatFlags(TextAlign));
339+
TextRenderer.DrawText(e.Graphics, Text, Font, ClientRectangle, foreColor, PoisonPaint.GetTextFormatFlags(TextAlign));
316340
}
317341
}
318342
else
319343
{
320344
DestroyBaseTextbox();
321-
TextRenderer.DrawText(e.Graphics, Text, PoisonFonts.Label(poisonLabelSize, poisonLabelWeight), ClientRectangle, foreColor, PoisonPaint.GetTextFormatFlags(TextAlign, wrapToLine));
345+
TextRenderer.DrawText(e.Graphics, Text, Font, ClientRectangle, foreColor, PoisonPaint.GetTextFormatFlags(TextAlign, wrapToLine));
322346
OnCustomPaintForeground(new PoisonPaintEventArgs(Color.Empty, foreColor, e.Graphics));
323347
}
324348
}
@@ -345,7 +369,7 @@ public override Size GetPreferredSize(Size proposedSize)
345369
using (Graphics g = CreateGraphics())
346370
{
347371
proposedSize = new(int.MaxValue, int.MaxValue);
348-
preferredSize = TextRenderer.MeasureText(g, Text, PoisonFonts.Label(poisonLabelSize, poisonLabelWeight), proposedSize, PoisonPaint.GetTextFormatFlags(TextAlign));
372+
preferredSize = TextRenderer.MeasureText(g, Text, Font, proposedSize, PoisonPaint.GetTextFormatFlags(TextAlign));
349373
}
350374

351375
return preferredSize;
@@ -418,7 +442,7 @@ private void CreateBaseTextBox()
418442
baseTextBox.BackColor = Color.Transparent;
419443
baseTextBox.Visible = true;
420444
baseTextBox.BorderStyle = BorderStyle.None;
421-
baseTextBox.Font = PoisonFonts.Label(poisonLabelSize, poisonLabelWeight);
445+
baseTextBox.Font = Font;
422446
baseTextBox.Location = new(1, 0);
423447
baseTextBox.Text = Text;
424448
baseTextBox.ReadOnly = true;
@@ -544,7 +568,7 @@ private void UpdateBaseTextBox()
544568
}
545569
}
546570

547-
baseTextBox.Font = PoisonFonts.Label(poisonLabelSize, poisonLabelWeight);
571+
baseTextBox.Font = Font;
548572
baseTextBox.Text = Text;
549573
baseTextBox.BorderStyle = BorderStyle.None;
550574

0 commit comments

Comments
 (0)