本文整理汇总了C#中System.Windows.Controls.TextBox类的典型用法代码示例。如果您正苦于以下问题:C# TextBox类的具体用法?C# TextBox怎么用?C# TextBox使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextBox类属于System.Windows.Controls命名空间,在下文中一共展示了TextBox类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: for_MouseDown
private void for_MouseDown(object sender, MouseButtonEventArgs e)
{
SolidColorBrush[] brushes = new SolidColorBrush[]
{ Brushes.Green, Brushes.BurlyWood,Brushes.CadetBlue,
Brushes.Gray,Brushes.Chartreuse,Brushes.Chocolate,
Brushes.AliceBlue,Brushes.Coral,Brushes.CornflowerBlue,
Brushes.AntiqueWhite,Brushes.Cornsilk,Brushes.Crimson,
Brushes.Aqua,Brushes.Cyan,Brushes.DarkBlue,Brushes.DarkCyan,
Brushes.Aquamarine,Brushes.DarkGoldenrod,Brushes.DarkGray,
Brushes.Azure,Brushes.DarkGreen,Brushes.DarkKhaki,
Brushes.Beige,Brushes.DarkMagenta,Brushes.DarkOliveGreen,
Brushes.Bisque,Brushes.DarkOrange,Brushes.DarkOrchid,
Brushes.Black,Brushes.DarkRed,Brushes.DarkSalmon,
Brushes.BlanchedAlmond,Brushes.DarkSeaGreen,Brushes.DarkSlateBlue,
Brushes.Blue,Brushes.DarkSlateGray,Brushes.DarkTurquoise,
Brushes.BlueViolet,Brushes.Brown,Brushes.DarkViolet
};
TextBox b = new TextBox() { Text = "Label " + contC };
b.Name = "s" + contador;
b.Background = brushes[new Random().Next(brushes.Length)];
b.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
b.VerticalAlignment = System.Windows.VerticalAlignment.Top;
b.PreviewMouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.TextBox_PreviewMouseLeftButtonDown);
b.PreviewMouseDown += new System.Windows.Input.MouseButtonEventHandler(this.TextBox_PreviewDown);
this.workSpace.Children.Add(b);
b.Margin = new Thickness(0, 0, 0, 0);
contC++;
}
示例2: IsNonEmpty
internal static bool IsNonEmpty(TextBox input)
{
bool result = false;
try
{
if (false == string.IsNullOrEmpty(input.Text))
{
SetToDefaultStyle(input);
result = true;
}
else
{
Style textBoxErrorStyle;
FrameworkElement frameworkElement;
frameworkElement = new FrameworkElement();
textBoxErrorStyle = (Style)frameworkElement.TryFindResource("textBoxEmptyErrorStyle");
input.Style = textBoxErrorStyle;
}
}
catch (Exception ex)
{
Logger.LogException(ex);
}
return result;
}
示例3: OnlyNumbersAndCommas
public static void OnlyNumbersAndCommas(KeyEventArgs e, TextBox tb)
{
if (e.Key != Key.Decimal && e.Key != Key.OemComma && (e.Key < Key.D0 || e.Key > Key.D9) && (e.Key < Key.NumPad0 || e.Key > Key.NumPad9))
{
e.Handled = true;
}
}
示例4: KinectDance
public KinectDance(double layoutHeight, double layoutWidth, List<TextBlock> menus, Style mouseOverStyle, Border menuBorder,TextBox debugBox = null)
{
_layoutHeight = layoutHeight;
_layoutWidth = layoutWidth;
_debugBox = debugBox;
_menus = menus;
_menuBorder = menuBorder;
_mouseOverStyle = mouseOverStyle;
_kinect = KinectSensor.KinectSensors.FirstOrDefault();
if (_kinect == null) return;
//_kinect.SkeletonStream.TrackingMode = SkeletonTrackingMode.Seated;
_kinect.Start();
_kinect.ColorStream.Enable();
_kinect.SkeletonStream.Enable(new TransformSmoothParameters
{
Smoothing = 0.7f,
Correction = 0.3f,
Prediction = 0.4f,
JitterRadius = 0.5f,
MaxDeviationRadius = 0.5f
});
_kinect.SkeletonFrameReady += kinect_SkeletonFrameReady;
}
示例5: GenereateFields
public static void GenereateFields()
{
// Get the Grid from the MainWindow
Grid AuthenticationGrid = ((MainWindow)System.Windows.Application.Current.MainWindow).AuthenticationGrid;
// Build a list of Digest Auth Fields
List<string> fields = new List<string>();
fields.Add("Username");
fields.Add("Password");
for (int i = 0; i < fields.Count; i++)
{
// Add a row to the AuthGrid
RowDefinition rowDefinition = new RowDefinition();
rowDefinition.Height = GridLength.Auto;
AuthenticationGrid.RowDefinitions.Add(rowDefinition);
// Add a Label
Label label = new Label();
label.SetValue(Grid.RowProperty, i + 1);
label.SetValue(Grid.ColumnProperty, 0);
label.Name = "AuthenticationKey" + i;
label.Content = fields[i] + ":";
AuthenticationGrid.Children.Add(label);
// Add a textbox
TextBox textBox = new TextBox();
textBox.SetValue(Grid.RowProperty, i + 1);
textBox.SetValue(Grid.ColumnProperty, 1);
textBox.Name = "AuthenticationValue" + i;
AuthenticationGrid.Children.Add(textBox);
}
}
示例6: KinectControl
public KinectControl(HoverButton kinectButton, double layoutHeight, double layoutWidth, List<Button> buttons, TextBox debugBox = null)
{
_kinectButton = kinectButton;
_layoutHeight = layoutHeight;
_layoutWidth = layoutWidth;
_buttons = buttons;
_debugBox = debugBox;
_kinect = KinectSensor.KinectSensors.FirstOrDefault();
if (_kinect != null)
{
_kinect.Start();
_kinect.ColorStream.Enable();
_kinect.SkeletonStream.Enable(new TransformSmoothParameters
{
Smoothing = 0.7f,
Correction = 0.1f,
Prediction = 0.1f,
JitterRadius = 0.05f,
MaxDeviationRadius = 0.05f
});
_kinect.SkeletonFrameReady += kinect_SkeletonFrameReady;
}
_activeRecognizer = CreateRecognizer();
_kinectButton.Click += KinectButton_Click;
}
示例7: toInt
private static int toInt(TextBox tb)
{
if (string.IsNullOrEmpty(tb.Text))
return 0;
else
return Convert.ToInt32(tb.Text);
}
示例8: StateChangeAdorner
public StateChangeAdorner(TextBox adornedElement, StateChange change)
: base(adornedElement)
{
this.text.FontSize = adornedElement.FontSize * 0.80;
this.text.Text = change.Variable + " = " + change.Value;
this.border.Child = this.text;
}
示例9: BasicsWindow
public BasicsWindow()
{
Window basics = new Window
{
Title = "Code Basics",
Height = 400,
Width = 400,
FontSize = 20,
};
StackPanel sp = new StackPanel();
basics.Content = sp;
TextBlock title = new TextBlock
{
Text = "Code Basics",
FontSize = 24,
TextAlignment = TextAlignment.Center,
};
sp.Children.Add(title);
txtName = new TextBox();
sp.Children.Add(txtName);
txtName.Margin = new Thickness(10);
Button btnSend = new Button
{
Content = "Send",
};
sp.Children.Add(btnSend);
btnSend.Margin = new Thickness(10);
btnSend.Click += BtnSend_Click;
basics.Show();
}
示例10: utiliseAlphabet
/// <summary>
/// Premet de savoir si l'utilisateur utilise a-z ou A-Z
/// </summary>
/// <param name="champ">champ à valider</param>
/// <returns>Retourne vrai si le champ contient des lettres uniquement</returns>
private bool utiliseAlphabet(TextBox champ)
{
int nbTirets = 0;
for (int car = 0; car < champ.Text.Length; car++)
{
if (champ.Text[car] != '-')
{
if (!((champ.Text[car] >= 97 && champ.Text[car] <= 122) || (champ.Text[car] >= 65 && champ.Text[car] <= 90)))
{
return false;
}
}
else
{
nbTirets++;
// Si l'utilisateur utilise plus de 2 tirets, le champ n'est pas valide
if (nbTirets > 1)
{
return false;
}
}
}
return true;
}
示例11: RecalculateVisibility
private void RecalculateVisibility(object oldValue, object newValue)
{
if(AutoChild)
{
// when datacontext change is fired but its not loaded, it's quite possible that some Common.Routes are not working yet
if (newValue == null/* || !IsLoaded*/)
Child = null;
else
{
EntitySettings es = Navigator.Manager.EntitySettings.TryGetC(newValue.GetType());
if (es == null)
Child = new TextBox
{
Text = "No EntitySettings for {0}".FormatWith(newValue.GetType()),
Foreground = Brushes.Red,
FontWeight = FontWeights.Bold
};
else
Child = es.CreateView((ModifiableEntity)newValue, Common.GetPropertyRoute(this));
}
}
if (Child != null)
{
if (newValue == null)
Child.Visibility = Visibility.Hidden;
else
Child.Visibility = Visibility.Visible;
if (oldValue != null && newValue != null)
Child.BeginAnimation(UIElement.OpacityProperty, animation);
}
}
示例12: AutoCompleteTextBox
public AutoCompleteTextBox()
{
controls = new VisualCollection(this);
InitializeComponent();
searchThreshold = 2; // default threshold to 2 char
// set up the key press timer
keypressTimer = new System.Timers.Timer();
keypressTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
// set up the text box and the combo box
comboBox = new ComboBox();
comboBox.IsSynchronizedWithCurrentItem = true;
comboBox.IsTabStop = false;
comboBox.SelectionChanged += new SelectionChangedEventHandler(comboBox_SelectionChanged);
textBox = new TextBox();
textBox.TextChanged += new TextChangedEventHandler(textBox_TextChanged);
textBox.VerticalContentAlignment = VerticalAlignment.Center;
controls.Add(comboBox);
controls.Add(textBox);
}
示例13: Use_Zip_Code
private void Use_Zip_Code(object sender, System.Windows.RoutedEventArgs e)
{
TextBox textBox = new TextBox();
// restrict input to digits:
InputScope inputScope = new InputScope();
InputScopeName inputScopeName = new InputScopeName();
inputScopeName.NameValue = InputScopeNameValue.Digits;
inputScope.Names.Add(inputScopeName);
textBox.InputScope = inputScope;
CustomMessageBox messageBox = new CustomMessageBox()
{
Message = "Enter your US zip code:",
LeftButtonContent = "okay",
RightButtonContent = "cancel",
Content = textBox
};
messageBox.Loaded += (a, b) =>
{
textBox.Focus();
};
messageBox.Show();
messageBox.Dismissed += (s, args) =>
{
if (args.Result == CustomMessageBoxResult.LeftButton)
{
if (textBox.Text.Length >= 5)
{
geocodeUsingString(textBox.Text);
}
}
};
}
示例14: IsValidCurrency
internal static bool IsValidCurrency(TextBox input)
{
bool result = false;
try
{
if (input.Text == "0.00")
{
SetToDefaultStyle(input);
return true;
}
if (false == string.IsNullOrEmpty(input.Text) && Regex.IsMatch(input.Text, @"^[0-9]*(?:\.[0-9]*)?$"))
{
SetToDefaultStyle(input);
result = true;
}
else
{
Style textBoxErrorStyle;
FrameworkElement frameworkElement;
frameworkElement = new FrameworkElement();
textBoxErrorStyle = (Style)frameworkElement.TryFindResource("textBoxCurrencyErrorStyle");
input.Style = textBoxErrorStyle;
}
}
catch (Exception ex)
{
Logger.LogException(ex);
}
return result;
}
示例15: IsNumberOnly
internal static bool IsNumberOnly(TextBox input)
{
bool result = false;
try
{
if (Regex.IsMatch(input.Text, @"^\d+$"))
{
SetToDefaultStyle(input);
result = true;
}
else
{
Style textBoxErrorStyle;
FrameworkElement frameworkElement;
frameworkElement = new FrameworkElement();
//textBoxNormalStyle = (Style)frameworkElement.TryFindResource("textBoxNormalStyle");
textBoxErrorStyle = (Style)frameworkElement.TryFindResource("textBoxNumericErrorStyle");
input.Style = textBoxErrorStyle;
}
}
catch (Exception ex)
{
Logger.LogException(ex);
}
return result;
}