私は問題があります。テキストボックスが存在しない数字を受け入れないようにしたい。テキストボックスが小数を受け入れないように、すでに作成しました。しかし、たとえば 0865 を入力すると、すぐに 865 に変換されます。方法がわかりません。これが私のコードです:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Globalization;
namespace KeepThemTogether
{
public partial class MainPage : PhoneApplicationPage
{
int from_a, to_b, generatedNumber;
public MainPage()
{
InitializeComponent();
}
private void from_text(object sender, TextChangedEventArgs e)
{
}
private void to_change(object sender, TextChangedEventArgs e)
{
}
private void ShowGen()
{
ShGenTxt.Text = Convert.ToString(generatedNumber);
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
from_a = Int32.Parse(FromTxt.Text);
to_b = Int32.Parse(ToTxt.Text);
Random generate = new Random();
generatedNumber = generate.Next(from_a, to_b);
ShowGen();
}
private void from_up(object sender, KeyEventArgs e)
{
TextBox txt = (TextBox)sender;
if (txt.Text.Contains('.'))
{
txt.Text = txt.Text.Replace(".", "");
txt.SelectionStart = txt.Text.Length;
}
}
private void to_up(object sender, KeyEventArgs e)
{
TextBox txt = (TextBox)sender;
if (txt.Text.Contains('.'))
{
txt.Text = txt.Text.Replace(".", "");
txt.SelectionStart = txt.Text.Length;
}
}
}
}