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);
        }
    }
}