Je viens de "construire" un bouton Numérique Haut Bas. Maintenant j'ai une question, je voudrais que si j'appuie sur le bouton plus longtemps les presses sont comptées plus vite. Mais seulement après 1-2 secondes. Ainsi que le bouton Numeric Up Down normal. Si vous avez cliqué sur le bouton, plus vite il a été compté.C# WPF - Plus j'appuie sur un bouton, plus vite sera compté
Comment faire cela?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using System.Text.RegularExpressions;
namespace loeschen
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
{
//Regex regex = new Regex("[^0-9-)]");
// Regex regex = new Regex("[^0-9-)]");
//e.Handled = regex.IsMatch(e.Text);
//int zahl;
//e.Handled = int.TryParse(e.Text, out zahl);
Regex regex = new Regex(@"-?\d+(?:\.\d+)?");
e.Handled = !regex.IsMatch(e.Text);
}
private void textBox_GotFocus(object sender, RoutedEventArgs e)
{
textBox.SelectAll();
}
private void textBox1_GotFocus(object sender, RoutedEventArgs e)
{
}
private void button_Copy1_Click(object sender, RoutedEventArgs e)
{
if (!String.IsNullOrEmpty(tb.Text))
tb.Text = ((Int32.Parse(tb.Text)) + 1).ToString();
}
private void button_Copy2_Click(object sender, RoutedEventArgs e)
{
if (!String.IsNullOrEmpty(tb.Text))
tb.Text = ((Int32.Parse(tb.Text)) - 1).ToString();
}
private void tb_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
if (!String.IsNullOrEmpty(tb.Text))
{
if (Int32.Parse(tb.Text) > 100)
{
label.Content = "Limit erreicht";
tb.Text = (Int32.Parse(tb.Text) - 1).ToString();
}
else if (Int32.Parse(tb.Text) < -100)
{
label.Content = "Limit erreicht";
tb.Text = (Int32.Parse(tb.Text) + 1).ToString();
}
else if(Int32.Parse(tb.Text) < 100 && Int32.Parse(tb.Text) > -100)
{
label.Content = "";
}
}
}
catch (Exception)
{
}
}
}
}
<Window x:Class="loeschen.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
xmlns:local="clr-namespace:loeschen"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid Background="#FFA8EE9D">
<Canvas HorizontalAlignment="Left" Height="46" Margin="75,25,0,0" VerticalAlignment="Top" Width="132" Background="White">
<Button x:Name="button" Content="▲" HorizontalAlignment="Left" VerticalAlignment="Top" Canvas.Left="116" Canvas.Top="2"/>
<Button x:Name="button_Copy" Content="▼" HorizontalAlignment="Left" VerticalAlignment="Top" Canvas.Left="116" Canvas.Top="24" RenderTransformOrigin="2.069,0.293"/>
<TextBox x:Name="textBox" HorizontalAlignment="Left" BorderThickness="0" Height="22" BorderBrush="Transparent" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="79" Canvas.Left="37" Canvas.Top="12" SelectionBrush="Transparent" TextAlignment="Center" Background="{x:Null}" GotFocus="textBox_GotFocus"/>
</Canvas>
<Canvas HorizontalAlignment="Left" Height="45" Margin="290,201,0,0" VerticalAlignment="Top" Width="99" Background="White">
<TextBox x:Name="tb" PreviewTextInput="NumberValidationTextBox" HorizontalAlignment="Left" BorderThickness="0" Height="22" BorderBrush="Transparent" TextWrapping="Wrap" Text="99" VerticalAlignment="Top" Width="79" Canvas.Top="13" SelectionBrush="Transparent" TextAlignment="Center" Background="{x:Null}" GotFocus="textBox_GotFocus" TextChanged="tb_TextChanged"/>
</Canvas>
<Canvas HorizontalAlignment="Left" Height="45" Margin="370,201,0,0" VerticalAlignment="Top" Width="19" Background="Gainsboro">
<Button x:Name="button_Copy1" Content="▲" HorizontalAlignment="Left" VerticalAlignment="Top" Height="19" Width="19" FontSize="9" Click="button_Copy1_Click"/>
<Button x:Name="button_Copy2" Content="▼" HorizontalAlignment="Left" VerticalAlignment="Top" Height="19" Width="19" FontSize="9" Canvas.Top="26" Click="button_Copy2_Click"/>
</Canvas>
<Label x:Name="label" Content="Label" HorizontalAlignment="Left" Margin="329,154,0,0" VerticalAlignment="Top"/>
</Grid>
</Window>
Je voudrais aussi sa solution. Je pense que l'événement mousebutton down devrait être déclenché avant l'événement control_click, n'est-ce pas? –
http://pastebin.combosa.com/23 Voici la première version, mais ce n'est pas aussi bien qu'avec le Windows Form, comment puis-je le rendre plus beau? Les chiffres ne descendent pas d'affilée. – GabelUndMesser
Que voulez-vous dire "Les chiffres ne tombent pas dans une rangée"? – BugFinder