基地正在被攻击吧 关注:12贴子:540
  • 3回复贴,共1

一篇研究,主要是防断电,于是放在这里。

只看楼主收藏回复

namespace 进制转换
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public void Error()//发生异常时调用
{
TB1.Text = "";
TB2.Text = "";
TB3.Text = "";
TB4.Text = "";
}
private void TB3_TextChanged(object sender, TextChangedEventArgs e)
{
if (TB3.IsFocused)
{
if (TB3.Text == "")
{
TB1.Text = "";
TB2.Text = "";
TB4.Text = "";
}
else
{
try
{
TB1.Text = Convert.ToString(Convert.ToInt32(TB3.Text), 2);
TB2.Text = Convert.ToString(Convert.ToInt32(TB3.Text), 8);
TB4.Text = Convert.ToString(Convert.ToInt32(TB3.Text), 16).ToUpper();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n请重新输入!", "输入有误!");
Error();
}
}
}
}
private void TB1_TextChanged(object sender, TextChangedEventArgs e)
{
if (TB1.IsFocused)
{
if (TB1.Text == "")
{
TB3.Text = "";
TB2.Text = "";
TB4.Text = "";
}
else
{
try
{
TB3.Text = Convert.ToString(Convert.ToInt32(TB1.Text, 2));//先转换为十进制
TB2.Text = Convert.ToString(Convert.ToInt32(TB3.Text), 8);
TB4.Text = Convert.ToString(Convert.ToInt32(TB3.Text), 16).ToUpper();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n请重新输入!","输入有误!");
Error();
}
}
}
}
private void TB2_TextChanged(object sender, TextChangedEventArgs e)
{
if (TB2.IsFocused)
{
if (TB2.Text == "")
{
TB3.Text = "";
TB1.Text = "";
TB4.Text = "";
}
else
{
try
{
TB3.Text = Convert.ToString(Convert.ToInt32(TB2.Text, 8));//先转换为十进制
TB1.Text = Convert.ToString(Convert.ToInt32(TB3.Text), 2);
TB4.Text = Convert.ToString(Convert.ToInt32(TB3.Text), 16).ToUpper();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n请重新输入!", "输入有误!");
Error();
}
}
}
}
private void TB4_TextChanged(object sender, TextChangedEventArgs e)
{
if (TB4.IsFocused)
{
if (TB4.Text == "")
{
TB3.Text = "";
TB2.Text = "";
TB1.Text = "";
}
else
{
try
{
TB3.Text = Convert.ToString(Convert.ToInt32(TB4.Text, 16));//先转换为十进制
TB2.Text = Convert.ToString(Convert.ToInt32(TB3.Text), 8);
TB1.Text = Convert.ToString(Convert.ToInt32(TB3.Text), 2);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n请重新输入!", "输入有误!");
Error();
}
}
}
}
}
}


IP属地:广东1楼2023-10-01 22:18回复
    老哥,可以看看八字吗私信不了您


    IP属地:陕西来自Android客户端2楼2024-09-18 17:45
    收起回复