private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//Loop till all the grid rows not get printed
if (bFirstPage) printDocumentNewPage(sender, e);
#region _Draw Detail
int yC = 120, xC = 100;
int a = 0, b = 0, _a = 0, _b = 0,
den_1 = 1,den_2 = 1, _den_1 = 1, _den_2 = 1,
ext_1 = 0,ext_2 = 0,_ext_1 = 0, _ext_2 = 0;
string _sop;
for (int i = 0; i < 6; i++)
{
_den_1 = 1;
_den_2 = 1;
_ext_1 = 0;
_ext_2 = 0;
if (Den == "E")//ส่วนเหมือนกัน
{
_den_1 = RandomNumberGenerator.GetInt32(3, 10);
_den_2 = _den_1;
}
else if (Den == "NE")//ส่วนต่างกัน
{
_den_1 = RandomNumberGenerator.GetInt32(3, 10);
do {
_den_2 = RandomNumberGenerator.GetInt32(2, 10);
} while (_den_1== _den_2);
}
else if (Den == "E_Int")//แบบมีตัวเลข
{
int aa = RandomNumberGenerator.GetInt32(1, 3000);
if (aa > 1500)
{
_den_2 = 1;
_den_1 = RandomNumberGenerator.GetInt32(3, 10);
}
else
{
_den_1 = 1;
_den_2 = RandomNumberGenerator.GetInt32(2, 10);
}
}
else if (Den == "E_Flc")//แบบมีจำนวนคละ
{
_den_1 = RandomNumberGenerator.GetInt32(3, 10);
_den_2 = RandomNumberGenerator.GetInt32(2, 10);
int aa = RandomNumberGenerator.GetInt32(1, 3000) ;
if (aa > 2000)
{
_ext_1 = RandomNumberGenerator.GetInt32(1, 10);
}
else if (aa < 1000)
{
_ext_2 = RandomNumberGenerator.GetInt32(1, 10);
}
else
{
_ext_1 = RandomNumberGenerator.GetInt32(1, 10);
_ext_2 = RandomNumberGenerator.GetInt32(1, 10);
}
}
else if (Den == "N/NE")//แบบสุ่ม
{
int dd = RandomNumberGenerator.GetInt32(1, 4000);
if (dd >3000)
{
_den_1 = RandomNumberGenerator.GetInt32(3, 10);
_den_2 = _den_1;
}
else if (dd<=3000 && dd >2000)
{
_den_1 = RandomNumberGenerator.GetInt32(3, 10);
do
{
_den_2 = RandomNumberGenerator.GetInt32(2, 10);
} while (_den_1 == _den_2);
}
else if (dd <=2000 && dd >1000)
{
int aa = RandomNumberGenerator.GetInt32(1, 3000);
if (aa > 1500)
{
_den_2 = 1;
_den_1 = RandomNumberGenerator.GetInt32(3, 10);
}
else
{
_den_1 = 1;
_den_2 = RandomNumberGenerator.GetInt32(2, 10);
}
}
else
{
_den_1 = RandomNumberGenerator.GetInt32(3, 10);
_den_2 = RandomNumberGenerator.GetInt32(2, 10);
int aa = RandomNumberGenerator.GetInt32(1, 3000);
if (aa > 2000)
{
_ext_1 = RandomNumberGenerator.GetInt32(1, 10);
}
else if (aa < 1000)
{
_ext_2 = RandomNumberGenerator.GetInt32(1, 10);
}
else
{
_ext_1 = RandomNumberGenerator.GetInt32(1, 10);
_ext_2 = RandomNumberGenerator.GetInt32(1, 10);
}
}
}
_a = (_den_1 >2)? RandomNumberGenerator.GetInt32(1, _den_1-1): RandomNumberGenerator.GetInt32(1, 10);
_b = (_den_2 >2) ? RandomNumberGenerator.GetInt32(1, _den_2 - 1) : RandomNumberGenerator.GetInt32(1, 10);
if (Sop == "+")
{
_sop = "+";
}
else if (Sop == "-")
{
_sop = "-";
}
else
{
if (RandomNumberGenerator.GetInt32(1, 5000) > 2500)
{
_sop = "+";
}
else
{
_sop = "-";
}
}
if (_sop == "+" )
{
a = _a;
b = _b;
den_1 = _den_1;
den_2 = _den_2;
ext_1 = _ext_1;
ext_2 = _ext_2;
}
else
{
_den_1 = RandomNumberGenerator.GetInt32(3, 12);
_den_2 = RandomNumberGenerator.GetInt32(2, 12);
_a = (_den_1 > 2) ? RandomNumberGenerator.GetInt32(1, _den_1 - 1) : RandomNumberGenerator.GetInt32(1, 10);
_b = (_den_2 > 2) ? RandomNumberGenerator.GetInt32(1, _den_2 - 1) : RandomNumberGenerator.GetInt32(1, 10);
if ((_a + den_1 * ext_1) < (_b + den_2 * ext_2))
{
a = _a;
b = _b;
den_1 = _den_1;
den_2 = _den_1;
ext_1 = _ext_1;
ext_2 = _ext_2;
}
else
{
/* a = _a;
den_1 = _den_1;
ext_1 = _ext_1;
do
{
// _den_1 = RandomNumberGenerator.GetInt32(3, 10);
_den_2 = RandomNumberGenerator.GetInt32(3, 10);
b = (_den_2 > 1) ? RandomNumberGenerator.GetInt32(1, _den_2 - 1) : RandomNumberGenerator.GetInt32(1, 10);
a = (_den_1 > 1) ? RandomNumberGenerator.GetInt32(1, _den_1 - 1) : RandomNumberGenerator.GetInt32(1, 10);
} while (ext_1 * _a / den_1 >= ext_2 * _b / den_2);
*/
}
}
// MessageBox.Show(_a + " " + _den_1 + " " + _ext_1 + "\n" + _b + " " + _den_2 + " " + _ext_2);
if (den_1 != 0 && den_1 != 1)
{
e.Graphics.DrawFraction(ext_1, b, den_1, xC + 10, yC);
}
else
{
e.Graphics.DrawString(b.ToString(), new Font("Angsana New", 22), new SolidBrush(Color.Black), xC + 60, yC + 15);
}
e.Graphics.DrawString(_sop, new Font("Angsana New", 22), new SolidBrush(Color.Black), xC + 80, yC + 15);
if (den_2 != 0 && den_2 != 1)
{
e.Graphics.DrawFraction(ext_2, a, den_2, xC + 100, yC);
}
else
{
e.Graphics.DrawString(b.ToString(), new Font("Angsana New", 22), new SolidBrush(Color.Black), xC + 110, yC + 15);
}
e.Graphics.DrawString(" วิธีทำ# ", new Font("Angsana New", 20), new SolidBrush(Color.Black), xC + 200, yC + 5);
yC += 150;
}
#endregion
if (iPage > iPageAll - 1)
{
bNewPage = false;
bMorePagesToPrint = false;
}
if (bNewPage)
{
printDocumentNewPage(sender, e);
}
iPage++;
//If more lines exist, print another page.
e.HasMorePages = (bMorePagesToPrint) ? true : false;
}
ไม่แน่ใจว่าพลาดในส่วนไหน ครับ
ในส่วนของ การดำเนิน การจะมี
1. การบวก
2. การลบ
3.สุ่ม การ บวก ลบ
และ มีเงื่อนไข คือ
1.สัดส่วนที่เท่ากัน
2.สัดส่วนที่ไม่เท่ากัน
3.มีจำนวนเต็ม
4.มีจำนวนคละ
5. แบบสุ่มเลือก
C# WinApp รบกวนขอคำแนะนำเกี่ยวกับการสุ่มตัวเลข เพื่อคำนวณเศษส่วนหน่อย ครับ
{
//Loop till all the grid rows not get printed
if (bFirstPage) printDocumentNewPage(sender, e);
#region _Draw Detail
int yC = 120, xC = 100;
int a = 0, b = 0, _a = 0, _b = 0,
den_1 = 1,den_2 = 1, _den_1 = 1, _den_2 = 1,
ext_1 = 0,ext_2 = 0,_ext_1 = 0, _ext_2 = 0;
string _sop;
for (int i = 0; i < 6; i++)
{
_den_1 = 1;
_den_2 = 1;
_ext_1 = 0;
_ext_2 = 0;
if (Den == "E")//ส่วนเหมือนกัน
{
_den_1 = RandomNumberGenerator.GetInt32(3, 10);
_den_2 = _den_1;
}
else if (Den == "NE")//ส่วนต่างกัน
{
_den_1 = RandomNumberGenerator.GetInt32(3, 10);
do {
_den_2 = RandomNumberGenerator.GetInt32(2, 10);
} while (_den_1== _den_2);
}
else if (Den == "E_Int")//แบบมีตัวเลข
{
int aa = RandomNumberGenerator.GetInt32(1, 3000);
if (aa > 1500)
{
_den_2 = 1;
_den_1 = RandomNumberGenerator.GetInt32(3, 10);
}
else
{
_den_1 = 1;
_den_2 = RandomNumberGenerator.GetInt32(2, 10);
}
}
else if (Den == "E_Flc")//แบบมีจำนวนคละ
{
_den_1 = RandomNumberGenerator.GetInt32(3, 10);
_den_2 = RandomNumberGenerator.GetInt32(2, 10);
int aa = RandomNumberGenerator.GetInt32(1, 3000) ;
if (aa > 2000)
{
_ext_1 = RandomNumberGenerator.GetInt32(1, 10);
}
else if (aa < 1000)
{
_ext_2 = RandomNumberGenerator.GetInt32(1, 10);
}
else
{
_ext_1 = RandomNumberGenerator.GetInt32(1, 10);
_ext_2 = RandomNumberGenerator.GetInt32(1, 10);
}
}
else if (Den == "N/NE")//แบบสุ่ม
{
int dd = RandomNumberGenerator.GetInt32(1, 4000);
if (dd >3000)
{
_den_1 = RandomNumberGenerator.GetInt32(3, 10);
_den_2 = _den_1;
}
else if (dd<=3000 && dd >2000)
{
_den_1 = RandomNumberGenerator.GetInt32(3, 10);
do
{
_den_2 = RandomNumberGenerator.GetInt32(2, 10);
} while (_den_1 == _den_2);
}
else if (dd <=2000 && dd >1000)
{
int aa = RandomNumberGenerator.GetInt32(1, 3000);
if (aa > 1500)
{
_den_2 = 1;
_den_1 = RandomNumberGenerator.GetInt32(3, 10);
}
else
{
_den_1 = 1;
_den_2 = RandomNumberGenerator.GetInt32(2, 10);
}
}
else
{
_den_1 = RandomNumberGenerator.GetInt32(3, 10);
_den_2 = RandomNumberGenerator.GetInt32(2, 10);
int aa = RandomNumberGenerator.GetInt32(1, 3000);
if (aa > 2000)
{
_ext_1 = RandomNumberGenerator.GetInt32(1, 10);
}
else if (aa < 1000)
{
_ext_2 = RandomNumberGenerator.GetInt32(1, 10);
}
else
{
_ext_1 = RandomNumberGenerator.GetInt32(1, 10);
_ext_2 = RandomNumberGenerator.GetInt32(1, 10);
}
}
}
_a = (_den_1 >2)? RandomNumberGenerator.GetInt32(1, _den_1-1): RandomNumberGenerator.GetInt32(1, 10);
_b = (_den_2 >2) ? RandomNumberGenerator.GetInt32(1, _den_2 - 1) : RandomNumberGenerator.GetInt32(1, 10);
if (Sop == "+")
{
_sop = "+";
}
else if (Sop == "-")
{
_sop = "-";
}
else
{
if (RandomNumberGenerator.GetInt32(1, 5000) > 2500)
{
_sop = "+";
}
else
{
_sop = "-";
}
}
if (_sop == "+" )
{
a = _a;
b = _b;
den_1 = _den_1;
den_2 = _den_2;
ext_1 = _ext_1;
ext_2 = _ext_2;
}
else
{
_den_1 = RandomNumberGenerator.GetInt32(3, 12);
_den_2 = RandomNumberGenerator.GetInt32(2, 12);
_a = (_den_1 > 2) ? RandomNumberGenerator.GetInt32(1, _den_1 - 1) : RandomNumberGenerator.GetInt32(1, 10);
_b = (_den_2 > 2) ? RandomNumberGenerator.GetInt32(1, _den_2 - 1) : RandomNumberGenerator.GetInt32(1, 10);
if ((_a + den_1 * ext_1) < (_b + den_2 * ext_2))
{
a = _a;
b = _b;
den_1 = _den_1;
den_2 = _den_1;
ext_1 = _ext_1;
ext_2 = _ext_2;
}
else
{
/* a = _a;
den_1 = _den_1;
ext_1 = _ext_1;
do
{
// _den_1 = RandomNumberGenerator.GetInt32(3, 10);
_den_2 = RandomNumberGenerator.GetInt32(3, 10);
b = (_den_2 > 1) ? RandomNumberGenerator.GetInt32(1, _den_2 - 1) : RandomNumberGenerator.GetInt32(1, 10);
a = (_den_1 > 1) ? RandomNumberGenerator.GetInt32(1, _den_1 - 1) : RandomNumberGenerator.GetInt32(1, 10);
} while (ext_1 * _a / den_1 >= ext_2 * _b / den_2);
*/
}
}
// MessageBox.Show(_a + " " + _den_1 + " " + _ext_1 + "\n" + _b + " " + _den_2 + " " + _ext_2);
if (den_1 != 0 && den_1 != 1)
{
e.Graphics.DrawFraction(ext_1, b, den_1, xC + 10, yC);
}
else
{
e.Graphics.DrawString(b.ToString(), new Font("Angsana New", 22), new SolidBrush(Color.Black), xC + 60, yC + 15);
}
e.Graphics.DrawString(_sop, new Font("Angsana New", 22), new SolidBrush(Color.Black), xC + 80, yC + 15);
if (den_2 != 0 && den_2 != 1)
{
e.Graphics.DrawFraction(ext_2, a, den_2, xC + 100, yC);
}
else
{
e.Graphics.DrawString(b.ToString(), new Font("Angsana New", 22), new SolidBrush(Color.Black), xC + 110, yC + 15);
}
e.Graphics.DrawString(" วิธีทำ# ", new Font("Angsana New", 20), new SolidBrush(Color.Black), xC + 200, yC + 5);
yC += 150;
}
#endregion
if (iPage > iPageAll - 1)
{
bNewPage = false;
bMorePagesToPrint = false;
}
if (bNewPage)
{
printDocumentNewPage(sender, e);
}
iPage++;
//If more lines exist, print another page.
e.HasMorePages = (bMorePagesToPrint) ? true : false;
}
ไม่แน่ใจว่าพลาดในส่วนไหน ครับ
ในส่วนของ การดำเนิน การจะมี
1. การบวก
2. การลบ
3.สุ่ม การ บวก ลบ
และ มีเงื่อนไข คือ
1.สัดส่วนที่เท่ากัน
2.สัดส่วนที่ไม่เท่ากัน
3.มีจำนวนเต็ม
4.มีจำนวนคละ
5. แบบสุ่มเลือก