c#


C# WPF - The longer I press on a button the faster will be counted


I just "build" a Numeric Up Down button. Now I have a question, I would like that if I press the button longer the longer the presses are counted faster.
But only after 1-2 seconds. As well as the normal Numeric Up Down Button. If you clicked on the button, the faster it was counted up.
How do I do that ?
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>
You could add a timer and in on mousebutton down, start the timer, in the mousebutton up, stop it.
The timer, if time since mouse down is >2s could +1 to an increment, so that the count goes up by the increment.. so each iteration it goes up faster and faster, or just uses the timer to +1 if <2s and +5 or something after 2s .. choices are yours

Related Links

Read text file from resource
What does exactly <Expander Header=“{Binding}”> do?
List<T> Constructor (IEnumerable<T>) doesn't accept an array created from Array.CreateInstance(Type, Int32)
Event binding not working in telerik windows controls for universal apps
How to define length of properties [closed]
Tracking files of a particular extension
Trap timeouts in Parse
How to add point precision to decimal in C#?
How to store meta data in a SQL Server database to differentiate it from other databases?
How to draw ellipses in movement?
Integrate Audio and Filter Method
Dynamically Generated TextBoxes
No output from my C# calculator [closed]
Add items to custom ListBox
List<> Iteration performance
Azure build fails using ReservedIP

Categories

HOME
indexing
microcontroller
dronekit
apache-storm
ibm
gaussian
mailchimp
ebay
localhost
powerquery
uml-designer
richtextbox
opacity
openam
formulas
lotusscript
hololens
beaker-notebook
google-drive-android-api
ng-tags-input
bootstrap-accordion
ps
scalatest
smart-device
libxml2
windows-10-mobile
git-submodules
dynamics-ax-2012-r3
spring-data-gemfire
machine-code
wunderground
headphones
android-databinding
maven-2
pyexcel
apiman
libzip
risc
gridgain
spring-data-commons
react.rb
emacs24
history
richtext
typewriter
pyautogui
portaudio
cosign-api
angularfire
stdlist
askbot
sdkman
litedb
log-analysis
teamwork
pymol
xmla
xcode5
novell
livescript
xts
ccmenuitem
serializer
mvcgrid
data-layers
grape-api
objectdatasource
playing-cards
typography
source-depot
backbone-views
asp.net-4.0
antixsslibrary
feincms
idoc
invalidoperationexception
report-viewer2010
beep
project-files
code-organization
service-layer
projectgen
j++
asp.net-1.1

Resources

Encrypt Message