มาอีกแล้วครับ วันนี้ ผมได้ขึ้น คณิต ม. 1 เรื่อง การบวก การลบ ทศนิยม แล้วนะครับ
คราวนี้ อยาก ให้ DrawString แบบ ใน จุด อยู่ตรงกัน ครับ
โค้ด
https://github.com/mongkonP/KidsLearning/blob/master/KidsLearning.Print/ptnMth/m02OP/op005PlusMinus_Num_03factoring.cs
https://github.com/mongkonP/KidsLearning/blob/master/KidsLearning.Classed/Exten/ExtGraphics_Maths_Operation.cs
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);
}
C# winApp ต้องการให้จุดมันตรงกัน ใน เลขทศนิยม ครับ
คราวนี้ อยาก ให้ DrawString แบบ ใน จุด อยู่ตรงกัน ครับ
โค้ด
https://github.com/mongkonP/KidsLearning/blob/master/KidsLearning.Print/ptnMth/m02OP/op005PlusMinus_Num_03factoring.cs
https://github.com/mongkonP/KidsLearning/blob/master/KidsLearning.Classed/Exten/ExtGraphics_Maths_Operation.cs
{
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);
}