Major upgrade
This commit is contained in:
58
Source/Program/GUI/Common/Util.cs
Normal file
58
Source/Program/GUI/Common/Util.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace ProgramLib.GUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides utility functions related to GUI
|
||||
/// </summary>
|
||||
internal class Util
|
||||
{
|
||||
public enum StandardButtons
|
||||
{
|
||||
OK_YES,
|
||||
CANCEL_NO,
|
||||
|
||||
NOT_SET
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the width and height of a string in pixels.
|
||||
/// This is useful if we want to resize window to fit dynamic text
|
||||
/// </summary>
|
||||
public static Size MeasureString(string text)
|
||||
{
|
||||
TextBlock tb = new TextBlock();
|
||||
var formattedText = new FormattedText(
|
||||
text,
|
||||
CultureInfo.CurrentCulture,
|
||||
FlowDirection.LeftToRight,
|
||||
new Typeface(tb.FontFamily, tb.FontStyle, tb.FontWeight, tb.FontStretch),
|
||||
tb.FontSize,
|
||||
Brushes.Black,
|
||||
new NumberSubstitution(),
|
||||
VisualTreeHelper.GetDpi(tb).PixelsPerDip);
|
||||
|
||||
return new Size(formattedText.Width, formattedText.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user