Skip to content

Commit

Permalink
- Fix center drawing
Browse files Browse the repository at this point in the history
- Edit text size to be the same

#20
#578
  • Loading branch information
Smurf-IV committed Jun 10, 2022
1 parent e2789fe commit af50181
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 55 deletions.
2 changes: 2 additions & 0 deletions Documents/Help/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

## 2022-11-xx - Build 2211 - November 2022 <!--Possible August or September release?-->
* Made enumeration `SchemeOfficeColors` public, so they can be used to make external themes
* Resolved [#578](https://github.com/Krypton-Suite/Standard-Toolkit/issues/578), ComboBox Center no longer draws text centered
* Resolved [#20](https://github.com/Krypton-Suite/Standard-Toolkit/issues/20), Selected text in ComboBox is drawn in a different font
* Resolved [#308](https://github.com/Krypton-Suite/Standard-Toolkit/issues/308), Panel AntiAlias Border Problem
* Resolved [#734](https://github.com/Krypton-Suite/Standard-Toolkit/issues/734), Disabled Text in NumericUpDown Not visible
* Resolved [#715](https://github.com/Krypton-Suite/Standard-Toolkit/issues/715), v65.22.4.94 - PaletteSparkleBlueBase.GetContentPadding: Specified argument was out of the range of valid values. Parameter name: style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ public InternalComboBox(KryptonComboBox kryptonComboBox)
// Remove from view until size for the first time by the Krypton control
ItemHeight = 15;
DropDownHeight = 200;
DrawMode = DrawMode.OwnerDrawFixed; // DrawMode = DrawMode.OwnerDrawVariable;
SetStyle(/*ControlStyles.UserPaint| */ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer, true);
//DrawMode = DrawMode.OwnerDrawFixed; // #20 fix, but this causes other problems; see #578
DrawMode = DrawMode.OwnerDrawVariable;
SetStyle(/*ControlStyles.UserPaint | */ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer, true);
}
#endregion

Expand Down Expand Up @@ -171,10 +172,7 @@ public bool MouseOver
/// <summary>
/// Reset the app themed setting so it is retested when next required.
/// </summary>
public void ClearAppThemed()
{
_appThemed = null;
}
public void ClearAppThemed() => _appThemed = null;

/// <summary>
/// Gets the content short text.
Expand Down Expand Up @@ -388,56 +386,53 @@ protected override void WndProc(ref Message m)
_kryptonComboBox.CueHint.PerformPaint(_kryptonComboBox, g, rect, backBrush);
}
else
//////////////////////////////////////////////////////
// Following commented out, to allow the Draw to always happen even tho the edit box will draw over afterwards
// Draw Over is tracked here
// https://github.com/Krypton-Suite/Standard-Toolkit/issues/179
// If not enabled or not the dropDown Style then we can draw over the text area
//if (!_kryptonComboBox.Enabled || _kryptonComboBox.DropDownStyle != ComboBoxStyle.DropDown)
////////////////////////////////////////////////////////
//// Following commented out, to allow the Draw to always happen even tho the edit box will draw over afterwards
//// Draw Over is tracked here
//// https://github.com/Krypton-Suite/Standard-Toolkit/issues/179
//// If not enabled or not the dropDown Style then we can draw over the text area
////if (!_kryptonComboBox.Enabled || _kryptonComboBox.DropDownStyle != ComboBoxStyle.DropDown)
{
// Set the correct text rendering hint for the text drawing. We only draw if the edit text is disabled so we
// just always grab the disable state value. Without this line the wrong hint can occur because it inherits
// it from the device context. Resulting in blurred text.
g.TextRenderingHint = CommonHelper.PaletteTextHintToRenderingHint(states.Content.GetContentShortTextHint(state));

// Define the string formatting requirements
StringFormat stringFormat = new()
{
LineAlignment = StringAlignment.Near,
FormatFlags = StringFormatFlags.NoWrap,
Trimming = StringTrimming.None,
// Use the correct prefix setting
HotkeyPrefix = HotkeyPrefix.None
};

stringFormat.Alignment = states.Content.GetContentShortTextH(state) switch
{
PaletteRelativeAlign.Near => RightToLeft == RightToLeft.Yes
? StringAlignment.Far
: StringAlignment.Near,
PaletteRelativeAlign.Far => RightToLeft == RightToLeft.Yes
? StringAlignment.Near
: StringAlignment.Far,
PaletteRelativeAlign.Center => StringAlignment.Center,
_ => stringFormat.Alignment
};

// Draw using a solid brush
Rectangle rectangle = new(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
rectangle = CommonHelper.ApplyPadding(VisualOrientation.Top, rectangle,
states.Content.GetContentPadding(state));
TextFormatFlags flags = TextFormatFlags.TextBoxControl | TextFormatFlags.NoPadding | TextFormatFlags.VerticalCenter;

// Use the correct prefix setting
flags |= TextFormatFlags.NoPrefix;

try
// Do we need to switch drawing direction?
if (RightToLeft == RightToLeft.Yes)
{
//string label = this.Items[e.Index].ToString();
using SolidBrush foreBrush = new(states.Content.GetContentShortTextColor1(state));
g.DrawString(displayText, states.Content.GetContentShortTextFont(state), foreBrush, rectangle, stringFormat);
flags |= TextFormatFlags.RightToLeft;
}
catch (ArgumentException)

switch (states.Content.GetContentShortTextH(state))
{
using SolidBrush foreBrush = new(ForeColor);
g.DrawString(displayText, Font, foreBrush, rectangle, stringFormat);
case PaletteRelativeAlign.Near:
flags |= TextFormatFlags.Left;
break;
case PaletteRelativeAlign.Center:
flags |= TextFormatFlags.HorizontalCenter;
break;
case PaletteRelativeAlign.Far:
flags |= TextFormatFlags.Right;
break;
}

// Draw text using font defined by the control
Rectangle rectangle = new(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
rectangle = CommonHelper.ApplyPadding(VisualOrientation.Top, rectangle, states.Content.GetContentPadding(state));
// Find correct text color
Color textColor = states.Content.GetContentShortTextColor1(state);
Font contentShortTextFont = states.Content.GetContentShortTextFont(state);
// Find correct background color
Color backColor = states.PaletteBack.GetBackColor1(state);

TextRenderer.DrawText(g,
Text, contentShortTextFont,
rectangle,
textColor, backColor,
flags);
}

// Remove clipping settings
Expand Down Expand Up @@ -672,8 +667,8 @@ public bool Visible
IntPtr.Zero,
0, 0, 0, 0,
PI.SWP_.NOMOVE | PI.SWP_.NOSIZE |
(value ? PI.SWP_.SHOWWINDOW : PI.SWP_.HIDEWINDOW)
);
(value ? PI.SWP_.SHOWWINDOW : PI.SWP_.HIDEWINDOW)
);
}

#endregion
Expand Down Expand Up @@ -1277,6 +1272,8 @@ public bool IsInitializing
/// <summary>Gets or sets the draw mode of the combobox.</summary>
/// <value>The draw mode of the combobox.</value>
[Description(@"Gets or sets the draw mode of the combobox.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[EditorBrowsable(EditorBrowsableState.Never)]
public DrawMode DrawMode
{
get => _comboBox.DrawMode;
Expand Down Expand Up @@ -2666,7 +2663,15 @@ private void AttachEditControl()
// If we found a child then it is the edit class
if (childPtr != IntPtr.Zero)
{
if (this.DropDownStyle == ComboBoxStyle.Simple)
{
//this.childListBox = new ComboBox.ComboBoxChildNativeWindow(this, ComboBox.ChildWindowType.ListBox);
//this.childListBox.AssignHandle(window);
childPtr = PI.GetWindow(childPtr, PI.GetWindowType.GW_HWNDNEXT);
}
_subclassEdit = new SubclassEdit(childPtr, this);
// Following will have been done by Framework
//PI.SendMessage(childPtr, PI.WM_.EM_SETMARGINS, new IntPtr(3), IntPtr.Zero);
_subclassEdit.TrackMouseEnter += OnComboBoxMouseChange;
_subclassEdit.TrackMouseLeave += OnComboBoxMouseChange;
}
Expand Down Expand Up @@ -2723,6 +2728,7 @@ private void OnComboBoxDrawItem(object sender, DrawItemEventArgs e)
// Do we need to draw the edit area
if ((e.State & DrawItemState.ComboBoxEdit) == DrawItemState.ComboBoxEdit)
{
// TODO: Check if this is covered by the WM_PAINT in the internal Combo
// Always get base implementation to draw the background
e.DrawBackground();

Expand Down Expand Up @@ -2926,7 +2932,13 @@ private void OnComboBoxGotFocus(object sender, EventArgs e)
{
if (DropDownStyle == ComboBoxStyle.DropDown)
{
//_subclassEdit.Visible = true;
_subclassEdit.Visible = true;
PaletteState state = Enabled
? IsActive
? PaletteState.Tracking
: PaletteState.Normal
: PaletteState.Disabled;
_comboBox.Font = GetComboBoxTripleState().Content.GetContentShortTextFont(state);
}

base.OnGotFocus(e);
Expand All @@ -2938,7 +2950,8 @@ private void OnComboBoxLostFocus(object sender, EventArgs e)
{
if (DropDownStyle == ComboBoxStyle.DropDown)
{
//_subclassEdit.Visible = false;
_subclassEdit.Visible = false;
_comboBox.Font = GetComboBoxTripleState().Content.GetContentShortTextFont(PaletteState.Normal);
}

// ReSharper disable RedundantBaseQualifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ public void UnattachGlobalEvents()
/// <summary>
/// Gets and sets the ViewManager instance.
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[EditorBrowsable(EditorBrowsableState.Never)]
public ViewManager ViewManager
{
[DebuggerStepThrough]
Expand Down
94 changes: 91 additions & 3 deletions Source/Krypton Components/TestForm/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit af50181

Please sign in to comment.