当前位置: 首页>>代码示例>>C#>>正文


C# TextBox.SelectAll方法代码示例

本文整理汇总了C#中System.Windows.Controls.TextBox.SelectAll方法的典型用法代码示例。如果您正苦于以下问题:C# TextBox.SelectAll方法的具体用法?C# TextBox.SelectAll怎么用?C# TextBox.SelectAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.TextBox的用法示例。


在下文中一共展示了TextBox.SelectAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TrimSelectedTextTest

        public void TrimSelectedTextTest()
        {
            AvalonTestRunner.RunInSTA(delegate
            {
                TextBox textBox = new TextBox();
                //try to trim when there are no text
                TimePicker.ExposeTrimSelectedText(textBox);
                Assert.AreEqual("", textBox.Text, "Trim failed");

                textBox = new TextBox();
                textBox.Text = "10";
                textBox.SelectAll();
                TimePicker.ExposeTrimSelectedText(textBox);
                Assert.AreEqual("", textBox.Text, "Trim failed when selection was All");

                textBox = new TextBox();
                textBox.Text = "10";
                textBox.SelectionStart = 0;
                textBox.SelectionLength = 1;
                TimePicker.ExposeTrimSelectedText(textBox);
                Assert.AreEqual("0", textBox.Text, "Trim failed when selection was at the first char");

                textBox = new TextBox();
                textBox.Text = "10";
                textBox.SelectionStart = 1;
                textBox.SelectionLength = 1;
                TimePicker.ExposeTrimSelectedText(textBox);
                Assert.AreEqual("1", textBox.Text, "Trim failed when selection was at the second char");
            });
        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:30,代码来源:TimePickerTest.cs

示例2: Ask

        public object Ask(Parameter par)
        {
            var vlc = main.Children.FindByName(ValueControl);
            if (vlc != null)
                main.Children.Remove(vlc);
            Question.Text = "";
            foreach (string s in par.Question.Split(new[] { "\\n" }, StringSplitOptions.None))
            {
                Question.Inlines.Add(new Run { Text = s });
                Question.Inlines.Add(new LineBreak());
            }
            if (par.ParamType == ParamType.PBool)
            {
                var value = new ComboBox { Width = 100, Height = 20, Name = ValueControl, Margin = new Thickness(5, 0, 0, 0) };
                Grid.SetRow(value, 1);
                main.Children.Add(value);
                value.Items.Add(Boolean.TrueString);
                value.Items.Add(Boolean.FalseString);
                value.SelectedIndex = 0;
                value.Focus();
            }
            else
            {
                var value = new TextBox { Width = 400, Name = ValueControl, Margin = new Thickness(5, 0, 0, 0) };
                Grid.SetRow(value, 1);
                main.Children.Add(value);
                if (par.ParamType == ParamType.PDouble || par.ParamType == ParamType.PFuzzy)
                {
                    value.Text = "0";
                    value.TextChanged += ValueTextChanged;
                    value.Tag = par.ParamType;
                }
                else
                    value.Tag = ParamType.PString;
                value.SelectAll();
                value.Focus();
            }

            if (ShowDialog() == true)
            {

                UIElement uie = main.Children.FindByName(ValueControl);
                if (uie is TextBox)
                {
                    ParamType pt = (ParamType) (uie as TextBox).Tag;
                    if (pt == ParamType.PDouble || pt == ParamType.PFuzzy)
                        return double.Parse((uie as TextBox).Text);
                    return (uie as TextBox).Text;
                }
                if (uie is ComboBox)
                    return bool.Parse((uie as ComboBox).Text);
            }
            return null;
        }
开发者ID:asdanilenk,项目名称:Exp1,代码行数:54,代码来源:AskWindow.xaml.cs

示例3: IsOkay

 private bool IsOkay(String input, TextBox sender)
 {
     if (input.Length > 0)
     {
         return true;
     }
     else
     {
         MessageBox.Show("Check the input.");
         sender.Focus();
         sender.SelectAll();
         return false;
     }
 }
开发者ID:AkiPylvalainen,项目名称:IIO13200_NET_15S,代码行数:14,代码来源:MainWindow.xaml.cs

示例4: checkSetting

        bool checkSetting(bool result, TextBox textBox, string message, TabItem tab = null)
        {
            if (!result) {
                MessageBox.Show(message, resources["Connect"] as string, MessageBoxButton.OK, MessageBoxImage.Warning);
                if (tab != null) tab.Focus();
                new Action(() => {
                    Dispatcher.BeginInvoke(new Action(() => {
                        textBox.SelectAll();
                        textBox.Focus();
                    }));
                }).BeginInvoke(null, null);
            }

            return result;
        }
开发者ID:kevenme,项目名称:x-wall,代码行数:15,代码来源:MainWindow.xaml.cs

示例5: ShowInputDialog

        /// <summary>Simple input dialog box</summary>
        /// <returns>null if the dialog box was closed with "cancel",
        /// otherwise the user input<returns>
        public static string ShowInputDialog(string initialTitle = "", string initialText = "", string initialInput = null)
        {
            // create the dialog content
            TextBox content = new TextBox()
            {
                VerticalAlignment = VerticalAlignment.Bottom,
                TabIndex = 0
            };
            content.Text = initialInput;
            Label lbl = new Label()
            {
                Content = initialText,
                VerticalAlignment = VerticalAlignment.Top,
                Focusable = false
            };
            Grid g = new Grid()
            {
                Height = 50,
                Focusable = false
            };
            g.Children.Add(content);
            g.Children.Add(lbl);
            // create the ModernUI dialog component with the buttons
            var dlg = new ModernDialog
            {
                Title = initialTitle,
                ShowInTaskbar = false,
                Content = g,
                MinHeight = 0,
                MinWidth = 0,
                MaxHeight = 480,
                MaxWidth = 640,
            };
            FocusManager.SetFocusedElement(g, content);
            content.SelectAll();
            dlg.Buttons = new Button[] { dlg.OkButton, dlg.CancelButton };

            // register the event to retrieve the result of the dialog box
            string result = null;
            dlg.OkButton.Click += (object sender, RoutedEventArgs e) =>
            {
                result = content.Text;
            };

            dlg.ShowDialog();
            return result;
        }
开发者ID:StormyCode,项目名称:TimeLogger,代码行数:50,代码来源:CustomDialog.cs

示例6: checkInputIsDouble

        private bool checkInputIsDouble(TextBox input)
        {
            double number;
            bool isNumeric = double.TryParse(input.Text, out number);
            // out pitää kirjoittaa jos funktio voi sijoittaa takaisin muuttujaan

            if (!isNumeric)
            {
                MessageBox.Show("Kentän "+input.Name+" arvon pitää olla numero!");
                input.Focus();
                input.SelectAll();

                return false;
            }

            return true;
        }
开发者ID:njokipal,项目名称:IIO13200_NET_15S,代码行数:17,代码来源:MainWindow.xaml.cs

示例7: SearchControl

        public SearchControl(Reflected refled)
        {
			Reflected = refled;
            nameText = new TextBox();
            nameText.SetBinding(TextBox.TextProperty, new Binding("ItemName") { Mode = BindingMode.TwoWay, Source = Reflected});
            nameText.SelectAll();
            nameText.KeyUp += (sende1, e1) =>
            {
                if (e1.Key != Key.Enter) return;
                if (search && nameText.Text.Length >= 4)
                    SearchService(nameText.Text, Reflected.Type);
                else search = true;
            };
            IsContainsMethod = new CheckBox { Content = "Подстрока" , IsChecked=false };
            ResultsList = new StackPanel();
            Children.Add(nameText, IsContainsMethod, ResultsList);

        }
开发者ID:Sergey303,项目名称:MVC-DZI,代码行数:18,代码来源:SearchModel.cs

示例8: CreateControl

        public override FrameworkElement CreateControl(FormItemContext context)
        {
            TextBox tb = new TextBox();

            // apply [MaxLength(x)] attribute
            var attr2 = context.PropertyInfo.GetCustomAttribute(typeof(MaxLengthAttribute)) as MaxLengthAttribute;
            var attr3 = context.PropertyInfo.GetCustomAttribute(typeof(StringLengthAttribute)) as StringLengthAttribute;
            int maxlength = 0;
            if (attr2 != null)
            {
                maxlength = attr2.Length;
            }
            else if (attr3 != null)
            {
                maxlength = attr3.MaximumLength;
            }

            if(maxlength>0)
            {
                tb.MaxLength = maxlength;
            }
            if (maxlength > 100) //TODO multiline mode
            {
                tb.TextWrapping = System.Windows.TextWrapping.Wrap;
                tb.AcceptsReturn = true;
                tb.Height = 50;
            }

            var binding = new Binding(context.PropertyInfo.Name)
            {
                Mode = BindingMode.TwoWay,
            };
            binding.ValidationRules.Add(new AnnotationValidationRule(context.PropertyInfo));
            tb.SetBinding(TextBox.TextProperty, binding);
            CustomValidation.SetValidationProperty(tb, TextBox.TextProperty);
            tb.GotFocus += (s, e) =>
            {
                tb.SelectAll();
            };
            StyleHelper.ApplyStyle(tb, FormControlConstrants.EDIT_TEXTBOX_STYLE);
            return tb;
        }
开发者ID:mogliang,项目名称:Generic-WPF-Form-Controls,代码行数:42,代码来源:TextBoxSink.cs

示例9: checkJumpRight

 //checks for backspace, arrow and decimal key presses and jumps boxes if needed.
 //returns true when key was matched, false if not.
 private bool checkJumpRight(TextBox currentBox, TextBox rightNeighborBox, KeyEventArgs e)
 {
     switch (e.Key)
     {
         case Key.Right:
             if (currentBox.CaretIndex == currentBox.Text.Length || currentBox.Text == "")
             {
                 jumpRight(rightNeighborBox, e);
             }
             return true;
         case Key.OemPeriod:
         case Key.Decimal:
         case Key.Space:
             jumpRight(rightNeighborBox, e);
             rightNeighborBox.SelectAll();
             return true;
         default:
             return false;
     }
 }
开发者ID:RuvenSalamon,项目名称:IP-MaskedTextBox,代码行数:22,代码来源:UserControl1.xaml.cs

示例10: handleTextInput

        //discards non digits, prepares IPMaskedBox for textchange.
        private void handleTextInput(TextBox currentBox, TextBox rightNeighborBox, TextCompositionEventArgs e)
        {
            if (!char.IsDigit(Convert.ToChar(e.Text)))
            {
                e.Handled = true;
                SystemSounds.Beep.Play();
                return;
            }

            if (currentBox.Text.Length == 3 && currentBox.SelectionLength == 0)
            {
                e.Handled = true;
                SystemSounds.Beep.Play();
                if (currentBox != fourthBox)
                {
                    rightNeighborBox.Focus();
                    rightNeighborBox.SelectAll();
                }
            }
        }
开发者ID:RuvenSalamon,项目名称:IP-MaskedTextBox,代码行数:21,代码来源:UserControl1.xaml.cs

示例11: handleTextChange

        //checks whether textbox content > 255 when 3 characters have been entered.
        //clears if > 255, switches to next textbox otherwise
        private void handleTextChange(TextBox currentBox, TextBox rightNeighborBox)
        {
            if (currentBox.Text.Length == 3)
            {
                try
                {
                    Convert.ToByte(currentBox.Text);

                }
                catch (Exception exception) when (exception is FormatException || exception is OverflowException)
                {
                    currentBox.Clear();
                    currentBox.Focus();
                    SystemSounds.Beep.Play();
                    MessageBox.Show(errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
                if (currentBox.CaretIndex != 2 && currentBox != fourthBox)
                {
                    rightNeighborBox.CaretIndex = rightNeighborBox.Text.Length;
                    rightNeighborBox.SelectAll();
                    rightNeighborBox.Focus();
                }
            }
        }
开发者ID:RuvenSalamon,项目名称:IP-MaskedTextBox,代码行数:27,代码来源:UserControl1.xaml.cs

示例12: OnExecutedCopy

        /// <summary>
        /// This virtual method is called when ApplicationCommands.Copy command is executed.
        /// </summary>
        /// <param name="args"></param>
        protected virtual void OnExecutedCopy(ExecutedRoutedEventArgs args)
        {
            if (ClipboardCopyMode == DataGridClipboardCopyMode.None)
            {
                throw new NotSupportedException(SR.Get(SRID.ClipboardCopyMode_Disabled));
            }

            args.Handled = true;

            // Supported default formats: Html, Text, UnicodeText and CSV
            Collection<string> formats = new Collection<string>(new string[] { DataFormats.Html, DataFormats.Text, DataFormats.UnicodeText, DataFormats.CommaSeparatedValue });
            Dictionary<string, StringBuilder> dataGridStringBuilders = new Dictionary<string, StringBuilder>(formats.Count);
            foreach (string format in formats)
            {
                dataGridStringBuilders[format] = new StringBuilder();
            }

            int minRowIndex;
            int maxRowIndex;
            int minColumnDisplayIndex;
            int maxColumnDisplayIndex;

            // Get the bounding box of the selected cells
            if (_selectedCells.GetSelectionRange(out minColumnDisplayIndex, out maxColumnDisplayIndex, out minRowIndex, out maxRowIndex))
            {
                // Add column headers if enabled
                if (ClipboardCopyMode == DataGridClipboardCopyMode.IncludeHeader)
                {
                    DataGridRowClipboardEventArgs preparingRowClipboardContentEventArgs = new DataGridRowClipboardEventArgs(null, minColumnDisplayIndex, maxColumnDisplayIndex, true /*IsColumnHeadersRow*/);
                    OnCopyingRowClipboardContent(preparingRowClipboardContentEventArgs);

                    foreach (string format in formats)
                    {
                        dataGridStringBuilders[format].Append(preparingRowClipboardContentEventArgs.FormatClipboardCellValues(format));
                    }
                }

                // Add each selected row
                for (int i = minRowIndex; i <= maxRowIndex; i++)
                {
                    object row = Items[i];

                    // Row has a selecion
                    if (_selectedCells.Intersects(i)) 
                    {
                        DataGridRowClipboardEventArgs preparingRowClipboardContentEventArgs = new DataGridRowClipboardEventArgs(row, minColumnDisplayIndex, maxColumnDisplayIndex, false /*IsColumnHeadersRow*/, i);
                        OnCopyingRowClipboardContent(preparingRowClipboardContentEventArgs);

                        foreach (string format in formats)
                        {
                            dataGridStringBuilders[format].Append(preparingRowClipboardContentEventArgs.FormatClipboardCellValues(format));
                        }
                    }
                }
            }

            ClipboardHelper.GetClipboardContentForHtml(dataGridStringBuilders[DataFormats.Html]);

            try
            {
                DataObject dataObject = new DataObject();
                foreach (string format in formats)
                {
                    dataObject.SetData(format, dataGridStringBuilders[format].ToString(), false /*autoConvert*/);
                }

                Clipboard.SetDataObject(dataObject);
            }
            catch (SecurityException)
            {
                // In partial trust we will have a security exception because clipboard operations require elevated permissions
                // Bug: Once the security team fix Clipboard.SetText - we can remove this catch
                // Temp: Use TextBox.Copy to have at least Text format in the clipboard
                TextBox textBox = new TextBox();
                textBox.Text = dataGridStringBuilders[DataFormats.Text].ToString();
                textBox.SelectAll();
                textBox.Copy();
            }
        }
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:83,代码来源:DataGrid.cs

示例13: SetTextValue

 private void SetTextValue(TextBox tb, int value)
 {
     tb.Focus();
       tb.Text = value.ToString();
       tb.SelectAll();
 }
开发者ID:thirkcircus,项目名称:ServiceBusMQManager,代码行数:6,代码来源:TimeControl.xaml.cs

示例14: selectAllText

 private void selectAllText(TextBox aTextBox)
 {
     aTextBox.SelectAll();
 }
开发者ID:PaulSchrum,项目名称:RM21SourceCore,代码行数:4,代码来源:MainWindow.xaml.cs

示例15: EditableTextBlockAdorner

 /// <summary>
 /// Constructor</summary>
 /// <param name="adornedElement">Adorned element</param>
 public EditableTextBlockAdorner(TextBlock adornedElement)
     : base(adornedElement)
 {
     m_collection = new VisualCollection(this);
     m_textBox = new TextBox();
     m_textBox.FontSize = adornedElement.FontSize;
     m_textBox.FontFamily = adornedElement.FontFamily;
     m_textBox.FontStretch = adornedElement.FontStretch;
     m_textBox.FontStyle = adornedElement.FontStyle;
     m_textBox.FontWeight = adornedElement.FontWeight;
     m_textBox.Width = adornedElement.Width;
     m_textBox.Height = adornedElement.Height;
     m_textBox.HorizontalAlignment = HorizontalAlignment.Left;
     m_textBox.VerticalAlignment = VerticalAlignment.Top;
     m_textBox.Padding = new Thickness(0);
     m_textBlock = adornedElement;
     Binding binding = new Binding("Text") { Source = adornedElement };
     m_textBox.SetBinding(TextBox.TextProperty, binding);
     m_textBox.AcceptsReturn = false;
     m_textBox.AcceptsTab = false;
     //_textBox.MaxLength = adornedElement.MaxLength;
     m_textBox.KeyUp += TextBox_KeyUp;
     m_textBox.LostFocus += TextBox_LostFocus;
     m_textBox.SelectAll();
     m_collection.Add(m_textBox);
 }
开发者ID:sbambach,项目名称:ATF,代码行数:29,代码来源:EditableTextBlockBehavior.cs


注:本文中的System.Windows.Controls.TextBox.SelectAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。