public static void DrawNumPositive(this Graphics e, Font fontDetail, double min, double max, int x, int y, string opr, int CountNum = 6)
{
var num = new Classed.Exten.RandomNumber(min, max);
string _a = TextStringExtension.SpacedString(num.MinValue.ToString());
string _b = TextStringExtension.SpacedString(num.MaxValue.ToString());
//System.Windows.Forms.MessageBox.Show(num.MinValue + "\n" + num.MaxValue + "\n" + _a + "\n" + _b);
int w = Convert.ToInt32(e.MeasureString("0 ", fontDetail).Width);
int h = Convert.ToInt32(e.MeasureString("0 ", fontDetail).Height);
//https://docs.microsoft.com/en-us/dotnet/desktop/winforms/advanced/how-to-align-drawn-text?view=netframeworkdesktop-4.8
StringFormat format = new StringFormat(StringFormatFlags.DirectionRightToLeft);
// https://stackoverflow.com/questions/11451001/why-isnt-my-text-right-aligned-when-i-custom-draw-my-strings
//https://docs.microsoft.com/en-us/dotnet/desktop/winforms/advanced/how-to-align-drawn-text?view=netframeworkdesktop-4.8&redirectedfrom=MSDN
StringFormat stringFormat = new StringFormat() { Alignment = StringAlignment.Far };
e.DrawString(_b, fontDetail, new SolidBrush(Color.Black), new Rectangle(x, y, w * CountNum, h), stringFormat);
e.DrawString(_a, fontDetail, new SolidBrush(Color.Black), new Rectangle(x, y + h + 10, w * CountNum, h), stringFormat);
e.DrawLine(new Pen(Color.Black, 3), x, y + 2 * h + 10, x + (CountNum) * w, y + 2 * h + 10);
e.DrawString(opr, fontDetail, new SolidBrush(Color.Black), x + (CountNum) * w, y + 10 + h / 2);
e.DrawLine(new Pen(Color.Black, 3), x, y + h * 3 + 15, x + (CountNum) * w, y + h * 3 + 15);
e.DrawLine(new Pen(Color.Black, 3), x, y + h * 3 + 20, x + (CountNum) * w, y + h * 3 + 20);
}
public static string SpacedString(string myOldString)
{
//ref
//https://stackoverflow.com/questions/2969143/c-sharp-drawstring-letter-spacing
System.Text.StringBuilder newStringBuilder = new System.Text.StringBuilder("");
foreach (char c in myOldString.ToCharArray())
{
newStringBuilder.Append(c.ToString() + " ");
}
string MyNewString = "";
if (newStringBuilder.Length > 0)
{
// remember to trim off the last inserted space
MyNewString = newStringBuilder.ToString().Substring(0, newStringBuilder.Length - 1).Trim();
//MyNewString = newStringBuilder.ToString();
}
// no else needed if the StringBuilder's length is <= 0... The resultant string would just be "", which is what it was intitialized to when declared.
return MyNewString;
}
public static void DrawNumPositive(this Graphics e, Font fontDetail, double min, double max, int x, int y, string opr, int CountNum = 6)
{
double a = GetRandomNumber(min, max, random.Next(1, 5));
double b = GetRandomNumber(min, max, random.Next(1, 5));
int c = Math.Max((a.ToString().Contains(".")) ? a.ToString().Split('.')[1].Length : 0, (b.ToString().Contains(".")) ? b.ToString().Split('.')[1].Length : 0);
string _a = SpacedString(a.ToString("N" + c));
string _b = SpacedString(b.ToString("N" + c));
int w = Convert.ToInt32(e.MeasureString("0 ", fontDetail).Width);
int h = Convert.ToInt32(e.MeasureString("0 ", fontDetail).Height);
//https://docs.microsoft.com/en-us/dotnet/desktop/winforms/advanced/how-to-align-drawn-text?view=netframeworkdesktop-4.8
StringFormat format = new StringFormat(StringFormatFlags.DirectionRightToLeft);
// https://stackoverflow.com/questions/11451001/why-isnt-my-text-right-aligned-when-i-custom-draw-my-strings
//https://docs.microsoft.com/en-us/dotnet/desktop/winforms/advanced/how-to-align-drawn-text?view=netframeworkdesktop-4.8&redirectedfrom=MSDN
StringFormat stringFormat = new StringFormat() { Alignment = StringAlignment.Far };
e.DrawString(_b, fontDetail, new SolidBrush(Color.Black), new Rectangle(x, y, w * CountNum, h), stringFormat);
e.DrawString(_a, fontDetail, new SolidBrush(Color.Black), new Rectangle(x, y + h + 10, w * CountNum, h), stringFormat);
e.DrawLine(new Pen(Color.Black, 3), x, y + 2 * h + 10, x + (CountNum) * w, y + 2 * h + 10);
e.DrawString(opr, fontDetail, new SolidBrush(Color.Black), x + (CountNum) * w, y + 10 + h / 2);
e.DrawLine(new Pen(Color.Black, 3), x, y + h * 3 + 15, x + (CountNum) * w, y + h * 3 + 15);
e.DrawLine(new Pen(Color.Black, 3), x, y + h * 3 + 20, x + (CountNum) * w, y + h * 3 + 20);
}