89 lines
2.4 KiB
C#
89 lines
2.4 KiB
C#
using System;
|
|
using System.Text.RegularExpressions;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
|
|
namespace MetroGauges
|
|
{
|
|
/// <summary>
|
|
/// Others.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class WpfOthers
|
|
{
|
|
public WpfOthers()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void previewTextInput(object sender, TextCompositionEventArgs e)//禁止文本输入
|
|
{
|
|
e.Handled = !IsTextAllowed(e.Text);
|
|
}
|
|
|
|
private void TextBoxPasting(object sender, DataObjectPastingEventArgs e)//禁用黏贴
|
|
{
|
|
if (e.DataObject.GetDataPresent(typeof(String)))
|
|
{
|
|
String text = (String)e.DataObject.GetData(typeof(String));
|
|
if (!IsTextAllowed(text))
|
|
{
|
|
e.CancelCommand();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
e.CancelCommand();
|
|
}
|
|
}
|
|
|
|
public static bool IsTextAllowed(string text)//只能输入数字
|
|
{
|
|
Regex regex = new Regex("[^0-9.-]+"); //regex that matches disallowed text
|
|
return !regex.IsMatch(text);
|
|
}
|
|
|
|
private void RBC_Checked(object sender, RoutedEventArgs e)
|
|
{
|
|
RadioButton rb = sender as RadioButton;
|
|
if (rb == rba)
|
|
{
|
|
//Others.rbOC = true;
|
|
}
|
|
if (rb == rbi)
|
|
{
|
|
//Others.rbOC = false;
|
|
}
|
|
}
|
|
|
|
private void btnScal_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (h.Text == "" & r.Text == "")
|
|
{
|
|
//this.ShowMessageAsync("提示", "请输入计算所需参数");
|
|
}
|
|
else
|
|
{
|
|
//Others.hac = Convert.ToDouble(h.Text); Others.r = Convert.ToDouble(r.Text);
|
|
//if (Others.rbOC == true)
|
|
//{
|
|
// //Bsa.Text = Convert.ToString(Others.Bs());
|
|
// Bsi.Clear();
|
|
//}
|
|
//else
|
|
//{
|
|
// //Bsi.Text = Convert.ToString(Others.Bs());
|
|
// Bsa.Clear();
|
|
//}
|
|
|
|
}
|
|
}
|
|
|
|
private void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
e.Cancel = true;
|
|
Hide();
|
|
}
|
|
}
|
|
}
|