Files
DevToolsAvalonia/常用工具集/Views/05其他/角度弧度转换.axaml.cs
2025-08-26 08:37:44 +08:00

70 lines
1.7 KiB
C#

using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using System;
using Ursa.Controls;
namespace ;
public partial class : UserControl
{
public ()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string strAngle = txtAngle.Text;
double angle;
bool flag = double.TryParse(strAngle, out angle);
if (!flag)
{
MessageBox.ShowAsync("请输入0~360之间的数字");
return;
}
if (angle < 0 || angle > 360)
{
MessageBox.ShowAsync("请输入0~360之间的数字");
return;
}
double rad = angle * (Math.PI / 180);
txtRad.Text = string.Format("{0:N6}", rad);
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
string strRad = txtRad.Text;
double rad;
bool flag = double.TryParse(strRad, out rad);
if (!flag)
{
MessageBox.ShowAsync("请输入0~2Π之间的数字");
return;
}
if (rad < 0 || rad > (2 * Math.PI))
{
MessageBox.ShowAsync("请输入0~2Π之间的数字");
return;
}
double angle = rad * 180 / Math.PI;
txtAngle.Text = string.Format("{0:N6}", angle);
}
private void txtAngle_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
Button_Click(sender, null);
}
}
private void txtRad_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
Button_Click_1(sender, null);
}
}
}