Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 2376 → Rev 2377

/MKLiveView/v1.0/Source/KeyPad/KeyPad.csproj
17,7 → 17,7
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
25,13 → 25,14
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Optimize>false</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
/MKLiveView/v1.0/Source/KeyPad/Keypad.xaml
1,6 → 1,7
<Window x:Class="KeyPad.Keypad"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:KeyPad"
Title="MainWindow" Height="313" Width="299" ShowInTaskbar="False" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" >
<Window.Resources>
<DropShadowEffect x:Key="DropShadowEffect"
117,21 → 118,21
<Grid Grid.Row="1">
<Border Style="{StaticResource buttonBorder}" Background="Black" CornerRadius="4" />
<Button Name="button5" Background="WhiteSmoke" BorderThickness="1"
Command="{Binding Path=PressAndRelease}" CommandParameter="NUMPAD7" Click="button_Click">7</Button>
CommandParameter="NUMPAD7" Click="button_Click">7</Button>
</Grid>
<Grid Grid.Column="1" Grid.Row="1">
<Border Style="{StaticResource buttonBorder}" Background="Black" CornerRadius="4" />
<Button x:Name="button6" Background="WhiteSmoke"
Command="{Binding PressAndRelease}" CommandParameter="NUMPAD8" Click="button_Click" BorderThickness="1" Content="8" />
CommandParameter="NUMPAD8" Click="button_Click" BorderThickness="1" Content="8" />
</Grid>
<Grid Grid.Column="2" Grid.Row="1">
<Border Style="{StaticResource buttonBorder}" Background="Black" CornerRadius="4" />
<Button x:Name="button7" Background="WhiteSmoke"
Command="{Binding PressAndRelease}" CommandParameter="NUMPAD9" Click="button_Click" Content="9" />
CommandParameter="NUMPAD9" Click="button_Click" Content="9" />
</Grid>
<Grid Grid.Column="3" Grid.Row="1">
<Border Style="{StaticResource buttonBorder}" Background="Black" CornerRadius="4" />
<Button x:Name="button8" Command="{Binding PressAndRelease}" CommandParameter="BACK" Click="button_Click">
<Button x:Name="button8" CommandParameter="BACK" Click="button_Click">
<Path Stretch="Fill" Width="36" Height="24" Data="F1M555.0371,274.4893L552.7871,276.7383L549.9861,273.9373L547.1991,276.7243L545.1131,274.6393L547.9001,271.8523L545.0101,268.9603L547.2601,266.7113L550.1501,269.6023L552.8921,266.8613L554.9761,268.9463L552.2361,271.6883z M555.3751,264.0003L544.8751,264.0003C543.1251,264.1253,535.0001,270.7503,535.0001,272.2503C535.0001,273.7503,543.1251,279.3753,544.8751,279.5003L555.3751,279.5003C558.8751,279.5003,559.3751,277.7093,559.3751,275.5003L559.3751,268.0003C559.3751,265.7913,558.7501,264.0003,555.3751,264.0003" Fill="#FF333333"/>
</Button>
</Grid>
138,59 → 139,60
<Grid Grid.Row="2">
<Border Style="{StaticResource buttonBorder}" Background="Black" CornerRadius="4" />
<Button x:Name="button9" Background="WhiteSmoke"
Command="{Binding PressAndRelease}" CommandParameter="NUMPAD4" Click="button_Click" Content="4"/>
CommandParameter="NUMPAD4" Click="button_Click" Content="4"/>
</Grid>
<Grid Grid.Column="1" Grid.Row="2">
<Border Style="{StaticResource buttonBorder}" Background="Black" CornerRadius="4" />
<Button x:Name="button10" Background="WhiteSmoke"
Command="{Binding PressAndRelease}" CommandParameter="NUMPAD5" Click="button_Click" Content="5" />
CommandParameter="NUMPAD5" Click="button_Click" Content="5" />
</Grid>
<Grid Grid.Column="2" Grid.Row="2">
<Border Style="{StaticResource buttonBorder}" Background="Black" CornerRadius="4" />
<Button x:Name="button11" Background="WhiteSmoke"
Command="{Binding PressAndRelease}" CommandParameter="NUMPAD6" Click="button_Click" Content="6" />
CommandParameter="NUMPAD6" Click="button_Click" Content="6" />
</Grid>
<Grid Grid.Row="3">
<Border Style="{StaticResource buttonBorder}" Background="Black" CornerRadius="4" />
<Button x:Name="button13" Background="WhiteSmoke"
Command="{Binding PressAndRelease}" CommandParameter="NUMPAD1" Click="button_Click" Content="1"/>
CommandParameter="NUMPAD1" Click="button_Click" Content="1"/>
</Grid>
<Grid Grid.Column="1" Grid.Row="3">
<Border Style="{StaticResource buttonBorder}" Background="Black" CornerRadius="4" />
<Button x:Name="button14" Background="WhiteSmoke"
Command="{Binding PressAndRelease}" CommandParameter="NUMPAD2" Click="button_Click" Content="2"/>
CommandParameter="NUMPAD2" Click="button_Click" Content="2"/>
</Grid>
<Grid Grid.Column="2" Grid.Row="3">
<Border Style="{StaticResource buttonBorder}" Background="Black" CornerRadius="4" />
<Button x:Name="button15" Background="WhiteSmoke"
Command="{Binding PressAndRelease}" CommandParameter="NUMPAD3" Click="button_Click" Content="3" />
CommandParameter="NUMPAD3" Click="button_Click" Content="3" />
</Grid>
<Grid Grid.Column="3" Grid.Row="2" Grid.RowSpan="3">
<Border Style="{StaticResource buttonBorder}" Background="Black" CornerRadius="4" />
<Button x:Name="button16"
Command="{Binding PressAndRelease}" CommandParameter="RETURN" Click="button_Click" Content="Enter"/>
CommandParameter="RETURN" Click="button_Click" Content="Enter"/>
</Grid>
<Grid Grid.ColumnSpan="2" Grid.Row="4">
<Border Style="{StaticResource buttonBorder}" Background="Black" CornerRadius="4" />
<Button x:Name="button17" Background="WhiteSmoke"
Command="{Binding PressAndRelease}" CommandParameter="NUMPAD0" Click="button_Click" Content="0" />
CommandParameter="NUMPAD0" Click="button_Click" Content="0" />
</Grid>
<Grid x:Name="gDecimal" Grid.Column="2" Grid.Row="4">
<Border Style="{StaticResource buttonBorder}" Background="Black" CornerRadius="4" />
<Button x:Name="button19" Background="WhiteSmoke"
Command="{Binding PressAndRelease}" CommandParameter="DECIMAL" Click="button_Click" Content="," />
CommandParameter="DECIMAL" Click="button_Click" Content="," />
</Grid>
<Grid Grid.ColumnSpan="3">
<Border Style="{StaticResource buttonBorder}" Background="Black" CornerRadius="0" >
<!--<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="49" Text="{Binding Result}" VerticalAlignment="Top" Width="212" AllowDrop="False" IsUndoEnabled="False" IsReadOnly="True"/>-->
</Border>
<Label Content="{Binding Result}" HorizontalContentAlignment="Right" Background="WhiteSmoke" Margin="4"/>
<Label Content="{Binding Result}" HorizontalContentAlignment="Right" Background="WhiteSmoke" Margin="4" Visibility="Hidden"/>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="49" Margin="4,4,0,0" Text="{Binding Result}" VerticalAlignment="Top" Width="212" FontSize="24" MaxLines="1" KeyDown="OnKeyDown" TextChanged="OnTextChanged"/>
 
</Grid>
</Grid>
<Grid Grid.Column="3" >
<Border Style="{StaticResource buttonBorder}" Background="Black" CornerRadius="4" />
<Button x:Name="buttonClear" Grid.Row="0"
Command="{Binding PressAndRelease}" CommandParameter="Clear" Click="button_Click" Content="C"/>
CommandParameter="Clear" Click="button_Click" Content="C"/>
<!--<Button x:Name="buttonEsc" Grid.Row="0"
Command="{Binding PressAndRelease}" CommandParameter="ESC" Click="button_Click" Content="Esc"/>-->
</Grid>
/MKLiveView/v1.0/Source/KeyPad/Keypad.xaml.cs
23,6 → 23,7
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;
using System.Windows.Input;
 
namespace KeyPad
{
35,6 → 36,7
private string _result;
int length = 0;
double min = 0, max = 0;
bool bDec = true;
#region Public Properties
public double MIN
{
59,6 → 61,7
public void disableDecimal()
{
gDecimal.Visibility = Visibility.Hidden;
bDec = false;
}
#endregion
84,6 → 87,7
 
case "RETURN":
double result1;
Result = LeaveOnlyNumbers(Result);
if (Double.TryParse(Result, out result1))
if (result1 <= max && result1 >= min && Result.Length <= length)
this.DialogResult = true;
96,20 → 100,30
 
default:
string tmp = Result + button.Content.ToString();
double result;
// if (Double.TryParse(tmp,System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.CreateSpecificCulture("en-GB"),out result))
if (Double.TryParse(tmp,out result))
{
if (result <= max && tmp.Length <= length)
if(checkValid(tmp))
Result += button.Content.ToString();
}
break;
}
}
}
 
private string LeaveOnlyNumbers(String inString)
{
string pattern;
if (bDec)
pattern = @"(0(?![0-9])|([1-9]\d*))+(\,\d+)?";
else
pattern = @"(0(?![0-9])|([1-9]\d*))+";
string tmp;
tmp = System.Text.RegularExpressions.Regex.Match(inString, pattern).Value;
return tmp;
}
 
 
#region INotifyPropertyChanged members
 
public event PropertyChangedEventHandler PropertyChanged;
 
 
private void OnPropertyChanged(String info)
{
if (PropertyChanged != null)
117,10 → 131,71
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
#endregion
private bool IsNumberKey(Key inKey)
{
if ((inKey < Key.D0 || inKey > Key.D9) & (inKey != Key.Decimal && inKey != Key.OemComma))
{
if ((inKey < Key.NumPad0 || inKey > Key.NumPad9) & (inKey != Key.Decimal && inKey != Key.OemComma))
{
return false;
}
}
if ((inKey == Key.Decimal || inKey == Key.OemComma) & (textBox.Text.Contains(",")||!bDec))
return false;
 
return true;
}
 
private bool IsDelOrBackspaceOrTabKey(Key inKey)
{
return inKey == Key.Delete || inKey == Key.Back;
}
 
bool checkValid(string tmp)
{
double result;
if (Double.TryParse(tmp, out result))
{
if (result <= max && tmp.Length <= length)
return true;
}
 
return false;
}
#region Event Functions
protected void OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == System.Windows.Input.Key.Return)
button_Click(button16, null);
else
{
if (!IsNumberKey(e.Key) && !IsDelOrBackspaceOrTabKey(e.Key))
e.Handled = true;
else
{
if ((e.Key != Key.Decimal && e.Key != Key.OemComma))
{
string tmp = e.Key.ToString().Replace("NumPad", "");
tmp = tmp.Replace("D", "");
tmp = ((TextBox)sender).Text + tmp;
if (checkValid(tmp))
e.Handled = false;
else
e.Handled = true;
}
}
}
}
 
protected void OnTextChanged(object sender, TextChangedEventArgs e)
{
Result = ((TextBox)sender).Text;
}
 
#endregion
 
 
 
}
}