Skip to content

Commit

Permalink
Merge #2729 Auto size yes no dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Apr 21, 2019
2 parents e163caa + 713b70d commit 7b9da8c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file.
- [GUI] Fix size of relationships list (#2728 by: HebaruSan; reviewed: DasSkelett)
- [GUI] Don't apply previous change set to checkboxes after successful install (#2730 by: HebaruSan; reviewed: DasSkelett)
- [Core] Compare RelationshipDescriptors with Equals instead of Same (#2735 by: HebaruSan; reviewed: DasSkelett)
- [GUI] Auto size yes no dialog (#2729 by: HebaruSan; reviewed: DasSkelett)

## v1.26.0

Expand Down
9 changes: 8 additions & 1 deletion GUI/YesNoDialog.Designer.cs

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

26 changes: 23 additions & 3 deletions GUI/YesNoDialog.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Drawing;
using System.Windows.Forms;

namespace CKAN
{
public partial class YesNoDialog : FormCompatibility
public partial class YesNoDialog : Form
{
public YesNoDialog()
{
Expand All @@ -11,13 +13,31 @@ public YesNoDialog()

public DialogResult ShowYesNoDialog(string text)
{
Util.Invoke(DescriptionLabel, () => DescriptionLabel.Text = text);
Util.Invoke(DescriptionLabel, () =>
{
DescriptionLabel.Text = text;
ClientSize = new Size(ClientSize.Width, StringHeight(text, ClientSize.Width - 25) + 2 * 54);
});

return ShowDialog();
}

/// <summary>
/// Simple syntactic sugar around Graphics.MeasureString
/// </summary>
/// <param name="text">String to measure size of</param>
/// <param name="maxWidth">Number of pixels allowed horizontally</param>
/// <returns>
/// Number of pixels needed vertically to fit the string
/// </returns>
private int StringHeight(string text, int maxWidth)
{
return (int)CreateGraphics().MeasureString(text, DescriptionLabel.Font, maxWidth).Height;
}

public void HideYesNoDialog()
{
Util.Invoke(this, Close);
}
}
}
}

0 comments on commit 7b9da8c

Please sign in to comment.