using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Project
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar < 48) || (e.KeyChar > 57))
{
e.KeyChar = Convert.ToChar(Keys.Back);
}
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
private void button2_stop_Click(object sender, EventArgs e)
{
this.Close();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox2.Clear();
string a = textBox1.Text;
try
{
int b = Convert.ToInt32(listBox1.Text);
string c = Convert.ToString(bin(b, int.Parse(a)));
if (c == "0")
{
switch (a)
{
case "10": a = "A"; break;
case "11": a = "B"; break;
case "12": a = "C"; break;
case "13": a = "D"; break;
case "14": a = "E"; break;
case "15": a = "F"; break;
}
textBox2.Text = a + "";
}
string m = Convert.ToString(int.Parse(a) % (int.Parse(c) * b));
while (int.Parse(c) >= b)
{
m = Convert.ToString(int.Parse(a) % (int.Parse(c) * b));
switch (m)
{
case "10": m = "A"; break;
case "11": m = "B"; break;
case "12": m = "C"; break;
case "13": m = "D"; break;
case "14": m = "E"; break;
case "15": m = "F"; break;
}
textBox2.Text = m + " " + textBox2.Text + " ";
a = c;
c = Convert.ToString(bin(b, int.Parse(c)));
}
m = Convert.ToString(int.Parse(a) % (int.Parse(c) * b));
switch (m)
{
case "10": m = "A"; break;
case "11": m = "B"; break;
case "12": m = "C"; break;
case "13": m = "D"; break;
case "14": m = "E"; break;
case "15": m = "F"; break;
}
switch (c)
{
case "10": c = "A"; break;
case "11": c = "B"; break;
case "12": c = "C"; break;
case "13": c = "D"; break;
case "14": c = "E"; break;
case "15": c = "F"; break;
}
textBox2.Text = c + " " + m + " " + textBox2.Text + " ";
textBox2.Text = textBox2.Text;
}
catch { }
}
private int bin(int b, int a)
{
int x = 0;
int i = 1;
while (true)
{
x = b * i;
if (x > a)
break;
i++;
}
if (i * b > a)
{
i--;
}
x = i;
return x;
}
}
}
//โค๊ดผมประมาณนี้ครับ อยากทราบตัวแปรที่จะนำมาแสดงให้มันเป็นวิธีการคำนวณออกมาเราเห็นบน Textboxของวิธีการคำนวณอะครับ