From d0056c092816b484a880aa2fac25800d69478bb0 Mon Sep 17 00:00:00 2001 From: "13997737+wolframhaussig@users.noreply.github.com" <13997737+wolframhaussig@users.noreply.github.com> Date: Tue, 27 Feb 2024 06:00:32 +0100 Subject: [PATCH] fix weird looks for long texts in StylableComboBox because of wrapped text --- .../Controls/StylableComboBox.cs | 27 +++---------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/StylableWinFormsControls/StylableWinFormsControls/Controls/StylableComboBox.cs b/StylableWinFormsControls/StylableWinFormsControls/Controls/StylableComboBox.cs index 8e7f869..c523b15 100644 --- a/StylableWinFormsControls/StylableWinFormsControls/Controls/StylableComboBox.cs +++ b/StylableWinFormsControls/StylableWinFormsControls/Controls/StylableComboBox.cs @@ -187,35 +187,16 @@ private Rectangle getDownRectangle() } private void drawComboBox(Graphics graphics) - { - Rectangle drawArea = ClientRectangle; - using SolidBrush backBrush = new(BackColor); - using SolidBrush foreBrush = new(ForeColor); - - using StringFormat stringFormat = new() - { - LineAlignment = StringAlignment.Center - }; - - graphics.FillRectangle(backBrush, drawArea); - - Rectangle textDrawArea = drawArea; - textDrawArea.X += 4; - graphics.DrawString( - Text, - Font, - foreBrush, - textDrawArea, - stringFormat); + { + TextRenderer.DrawText(graphics, Text, Font, ClientRectangle, ForeColor, BackColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.WordEllipsis); ComboBoxRenderer.DrawDropDownButton(graphics, getDownRectangle(), System.Windows.Forms.VisualStyles.ComboBoxState.Normal); - Rectangle borderRectangle = drawArea; - graphics.DrawRectangle(_borderColorPen, borderRectangle); + graphics.DrawRectangle(_borderColorPen, ClientRectangle); if (Focused && ShowFocusCues) { - ControlPaint.DrawFocusRectangle(graphics, borderRectangle); + ControlPaint.DrawFocusRectangle(graphics, ClientRectangle); } } }