1. 劃線乘法
namespace Q1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int? a, b;
private void button1_Click(object sender, EventArgs e)
{
a = int.Parse(textBox1.Text);
b = int.Parse(textBox2.Text);
panel1.Refresh();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
if (a == null) return;
{
var r = a.Value / 10;
var pen = new Pen(Brushes.Red, 2);
if (r == 0) pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
for (int i = 0; i < Math.Max(r, 1); i++)
{
e.Graphics.DrawLine(
pen,
50 + 200 + i * 10 + 50,50 + 0 + i * 10 - 50,50 + 0 + i * 10 + 50,50 + 200 + i * 10 - 50
);
}
var k = a.Value % 10;
pen.DashStyle = k == 0 ? System.Drawing.Drawing2D.DashStyle.Dash : System.Drawing.Drawing2D.DashStyle.Solid;
for (int i = 0; i < Math.Max(1, k); i++)
{
e.Graphics.DrawLine(
pen,
50 + 400 + i * 10,50 +50 + i * 10,50 + 150 + i * 10,50 + 300 + i * 10
);
}
}
{
var r = b.Value / 10;
var pen = new Pen(Brushes.Blue, 2);
if (r == 0) pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
var z = +50;
for (int i = 0; i < Math.Max(r, 1); i++)
{
e.Graphics.DrawLine(
pen,
50 + i * -10 - 75 + z,50 + i * 10,50 + 300 + z + i * -10 - 75 + z,50 + 300 + i * 10 + z
);
}
var k = b.Value % 10;
pen.DashStyle = k == 0 ? System.Drawing.Drawing2D.DashStyle.Dash : System.Drawing.Drawing2D.DashStyle.Solid;
for (int i = 0; i < Math.Max(1, k); i++)
{
e.Graphics.DrawLine(
pen,
50 + 200 + i * -10 - 75 + z,50 + i * 10 - 75 + z,50 + 500 + i * -10 - 75 + z,50 + 300 + i * 10 - 75 + z
);
}
}
}
}
}
Last updated