namespace 抵抗計算123
{
public partial class Form1 : Form
{
int e_sel = 12, B;
double r_value=0;
double rp1 = 1, rp2 = 1,rx1,rpp;
double rs1 = 1, rs2 = 1,rx2,rss;
double[,] R;
int i_step = 2;
int gousei = 1;
public Form1()
{
double B;
InitializeComponent();
R = newdouble[11, 25];
B = 1;
for (int i = 1; i < 10; i++)
{
R[i, 1 ]= 1.0 * B;
R[i, 2 ]= 1.1 * B;
R[i, 3 ]= 1.2 * B;
R[i, 4 ]= 1.3 * B;
R[i, 5 ]= 1.5 * B;
R[i, 6 ]= 1.6 * B;
R[i, 7 ]= 1.8 * B;
R[i, 8 ]= 2.0 * B;
R[i, 9 ]= 2.2 * B;
R[i, 10 ]= 2.4 * B;
R[i, 11 ]= 2.7 * B;
R[i, 12 ]= 3.0 * B;
R[i, 13 ]= 3.3 * B;
R[i, 14 ]= 3.6 * B;
R[i, 15 ]= 3.9 * B;
R[i, 16 ]= 4.3 * B;
R[i, 17 ]= 4.7 * B;
R[i, 18 ]= 5.1 * B;
R[i, 19 ]= 5.6 * B;
R[i, 20 ]= 6.2 * B;
R[i, 21 ]= 6.8 * B;
R[i, 22 ]= 7.5 * B;
R[i, 23 ]= 8.2 * B;
R[i, 24 ]= 9.1 * B;
B = B * 10;
}
}
privatevoid Form1_Load(object sender, EventArgs e)
{
this.ActiveControl = this.textBox5;
}
privatevoid Form1_Shown(object sender, EventArgs e)
{
textBox5.Focus();
}
privatevoid r_value_calc()
{
double a, b;
double rs = r_value;
double rp_temp = 9999999;
double rs_temp = 9999999;
if (gousei == 1)
{
for (int i1 = 1; i1 < 9; i1++)
{
for (int j1 = 1; j1 < 24; j1 += i_step)
{
for (int i2 = 1; i2 < 9; i2++)
{
for (int j2 = 1; j2 < 24; j2 += i_step)
{
a = R[i1, j1];
b = R[i2, j2];
rx1 = a * b /(a + b);
if (Math.Sqrt((rx1 - rs )*(rx1 - rs ))< rp_temp)
{
rp_temp = Math.Sqrt((rx1 - rs )*(rx1 - rs));
rp1 = a;
rp2 = b;
rpp = rx1;
}
rx2 = a + b;
if (Math.Sqrt((rx2 - rs )*(rx2 - rs ))< rs_temp)
{
rs_temp = Math.Sqrt((rx2 - rs )*(rx2 - rs));
rs1 = a;
rs2 = b;
rss = rx2;
}
}
}
}
}
textBox1.Text = rp1.ToString("n0");
if (this.textBox1.TextLength == 1)
{
textBox1.Text = rp1.ToString("n1");
}
if (Math.Sqrt((rp1 - rs )*(rp1 - rs ))> 0.1)
{
textBox2.Text = rp2.ToString("n0");
}
else
{
textBox2.Text = " ";
}
textBox3.Text = rpp.ToString("f2");
textBox4.Text =((rpp - rs )/ rs).ToString("p");
textBox7.Text = rs1.ToString("n1");
textBox8.Text = rs2.ToString("n1");
textBox9.Text = rss.ToString("f2");
textBox10.Text =((rss - rs )/ rs).ToString("p");
Refresh();
}
else
{
rx1 = Convert.ToInt32(textBox1.Text);
rx2 = Convert.ToInt32(textBox2.Text);
if ((rx1 * rx2 )< 1)
{
Console.Beep();
}
else
{
rpp
=(rx1 * rx2 )/(rx1 + rx2);
textBox5.Text = rpp.ToString("f2");
textBox4.Text = " ";
textBox3.Text = rpp.ToString("f2");
textBox7.Text = " " ;
textBox8.Text = " " ;
textBox9.Text = " " ;
textBox10.Text = " " ;
Refresh();
}
}
}
privatevoid TextBox5_KeyPress(object sender,System.Windows.Forms.KeyPressEventArgs e)
{
if ((e.KeyChar < '0' || '9' < e.KeyChar))
{
if (e.KeyChar ==(char)0x0d)
{
textBox1.Text = "";
textBox2.Text = "";
Refresh();
if (textBox5.Text != "") r_value = double.Parse(textBox5.Text);
if (r_value >= 1) r_value_calc();
}
}
}
privatevoid TextBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar < '0' || '9' < e.KeyChar)
{
e.Handled = true;
}
}
privatevoid TextBox2_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar < '0' || '9' < e.KeyChar)
{
e.Handled = true;
}
}
privatevoid radioButton3_CheckedChanged(object sender, EventArgs e)
{
e_sel = 12;
radioButton3.Font = new Font(radioButton3.Font, FontStyle.Bold);
radioButton4.Font = new Font(radioButton4.Font, FontStyle.Regular);
i_step = 2;
if (gousei == 1)
{
textBox5.SelectionStart = 0;
textBox5.SelectionLength = 0;
textBox5.Focus();
}
else
{
textBox1.SelectionStart = 0;
textBox1.SelectionLength = 0;
textBox1.Focus();
}
}
privatevoid radioButton4_CheckedChanged(object sender, EventArgs e)
{
e_sel = 24;
radioButton3.Font = new Font(radioButton3.Font, FontStyle.Regular);
radioButton4.Font = new Font(radioButton4.Font, FontStyle.Bold);
i_step = 1;
if (gousei == 1)
{
textBox5.SelectionStart = 0;
textBox5.SelectionLength = 0;
textBox5.Focus();
}
else
{
textBox1.SelectionStart = 0;
textBox1.SelectionLength = 0;
textBox1.Focus();
}
}
privatevoid button1_Click(object sender, EventArgs e)
{
if (gousei == 1)
{
textBox1.Text = "";
textBox2.Text = "";
Refresh();
if (textBox5.Text != "") r_value = double.Parse(textBox5.Text);
if (r_value >= 1) r_value_calc();
}
else
{
textBox5.Text = "";
r_value_calc();
Refresh();
}
}
privatevoid textBox5_KeyDown(object sender, KeyEventArgs e)
{
try
{
if (e.KeyCode == Keys.Enter)
{
if (textBox5.Text != "") r_value = double.Parse(textBox5.Text);
if (r_value >= 1) r_value_calc();
}
}
catch (System.Exception ex)
{
}
}
privatevoid radioButton1_CheckedChanged(object sender, EventArgs e)
{
gousei = 1;
radioButton1.Font = new Font(radioButton1.Font, FontStyle.Bold);
radioButton2.Font = new Font(radioButton2.Font, FontStyle.Regular);
textBox5.Text = "";
textBox1.Text = "";
textBox2.Text = "";
textBox4.Text = " ";
textBox3.Text = " ";
textBox7.Text = " ";
textBox8.Text = " ";
textBox9.Text = " ";
textBox10.Text = " ";
this.textBox5.BackColor = Color.Pink;
this.textBox1.BackColor = Color.LightCyan;
this.textBox2.BackColor = Color.LightCyan;
this.textBox3.BackColor = Color.WhiteSmoke;
this.textBox4.BackColor = Color.WhiteSmoke;
this.textBox7.BackColor = Color.LightCyan;
this.textBox8.BackColor = Color.LightCyan;
this.textBox9.BackColor = Color.WhiteSmoke;
this.textBox10.BackColor = Color.WhiteSmoke;
textBox5.SelectionStart = 0;
textBox5.SelectionLength = 0;
textBox5.Focus();
Refresh();
}
privatevoid radioButton2_CheckedChanged(object sender, EventArgs e)
{
gousei = 0;
radioButton2.Font = new Font(radioButton2.Font, FontStyle.Bold);
radioButton1.Font = new Font(radioButton1.Font, FontStyle.Regular);
textBox5.Text = "";
textBox1.Text = "";
textBox2.Text = "";
textBox4.Text = " ";
textBox3.Text = " ";
textBox7.Text = " ";
textBox8.Text = " ";
textBox9.Text = " ";
textBox10.Text = " ";
this.textBox5.BackColor = Color.LightCyan;
this.textBox1.BackColor = Color.Pink;
this.textBox2.BackColor = Color.Pink;
this.textBox4.BackColor = Color.DimGray;
this.textBox7.BackColor = Color.DimGray;
this.textBox8.BackColor = Color.DimGray;
this.textBox9.BackColor = Color.DimGray;
this.textBox10.BackColor = Color.DimGray;
this.textBox3.BackColor = Color.LightCyan;
textBox1.SelectionStart = 0;
textBox1.SelectionLength = 0;
textBox1.Focus();
Refresh();
}
privatevoid HELPToolStripMenuItem_Click(object sender, EventArgs e)
{
Help.ShowHelp(this, "抵抗計算V2.chm");
}
privatevoid バージョン情報ToolStripMenuItem_Click(object sender, EventArgs e)
{
VersionForm ver = new VersionForm();
ver.ShowDialog();
}
}
}
|