private void AssignShortcut(TextBox textbox, int row, int column) { var hotKey = new KeyBinding(new RelayCommand(() => textbox.Focus()), new MultiKeyGesture(new List<Key> { (Key)(row + 34), (Key)(column + 34) }, ModifierKeys.Control | ModifierKeys.Shift)); this.InputBindings.Add(hotKey); if (row < 10 && column < 10) { hotKey = new KeyBinding(new RelayCommand(() => textbox.Focus()), new MultiKeyGesture(new List<Key> { (Key)(row + 34), (Key)(column + 34) }, ModifierKeys.Control)); this.InputBindings.Add(hotKey); // following is not working //hotKey = new KeyBinding(new RelayCommand(() => textbox.Focus()), new MultiKeyGesture(new List<Key> { (Key)(row + 34), (Key)(column + 34) }, ModifierKeys.Alt)); //this.InputBindings.Add(hotKey); } }
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); } } }; }
public PrintBanner() { Title = "Print Banner"; SizeToContent = SizeToContent.WidthAndHeight; // Make StackPanel content of window. StackPanel stack = new StackPanel(); Content = stack; // Create TextBox. txtbox = new TextBox(); txtbox.Width = 250; txtbox.Margin = new Thickness(12); stack.Children.Add(txtbox); // Create Button. Button btn = new Button(); btn.Content = "_Print..."; btn.Margin = new Thickness(12); btn.Click += PrintOnClick; btn.HorizontalAlignment = HorizontalAlignment.Center; stack.Children.Add(btn); txtbox.Focus(); }
private void BindTree(TreeViewItem item, List<Detail> data) { foreach (var detail in data) { var panel = new WrapPanel(); panel.Children.Add(new TextBlock { Text = detail.DisplayName, FontWeight = FontWeights.Bold, VerticalAlignment = VerticalAlignment.Center }); var t = new TextBox { Text = detail.Value, Margin = new Thickness(5, 0, 0, 0), TextWrapping = TextWrapping.Wrap, //Width = this.Width - 300, BorderBrush = new SolidColorBrush(Colors.White), Padding = new Thickness(0) }; t.MouseEnter += (s, ee) => { t.Focus(); t.SelectAll(); }; panel.Children.Add(t); if (!string.IsNullOrEmpty(detail.Description)) panel.Children.Add(new TextBlock { Text = detail.Description, Margin = new Thickness(5, 0, 0, 0), FontStyle = FontStyles.Italic, TextWrapping = TextWrapping.Wrap, Width = 1050 }); var subItem = new TreeViewItem { Header = panel, }; if (detail.SubDetails != null) { BindTree(subItem, detail.SubDetails); } item.Items.Add(subItem); } }
public static ComboBox WorkWithEmailBox(Grid grid, TextBox emailTextBox, TextCompositionEventArgs e, int columnSpanEmailBox) { ComboBox comboBox = new ComboBox(); const string val = "@"; if (e.Text != val) return comboBox; if (emailTextBox.Text.Length < 1) return null; if (emailTextBox.Text.IndexOf(val, StringComparison.Ordinal) != -1) return comboBox; Grid.SetColumnSpan(emailTextBox, columnSpanEmailBox); comboBox.DropDownClosed += (a, r) => { if (comboBox.SelectedIndex == -1) return; grid.Children.Remove(comboBox); Grid.SetColumnSpan(emailTextBox, columnSpanEmailBox+2); if (comboBox.SelectedIndex == 0) { emailTextBox.Text += val; emailTextBox.Focus(); } else { emailTextBox.Text += comboBox.SelectedItem.ToString(); } emailTextBox.SelectionStart = emailTextBox.Text.Length; emailTextBox.Focus(); }; Grid.SetRow(comboBox, 2); comboBox.Items.Add("написать другой"); comboBox.Items.Add(val + "gmail.com"); comboBox.Items.Add(val + "mail.ru"); comboBox.Items.Add(val + "yandex.ua"); comboBox.Items.Add(val + "rambler.ru"); comboBox.Items.Add(val + "hotmail.com"); comboBox.Items.Add(val + "yahoo.com"); comboBox.Items.Add(val + "inbox.ru"); comboBox.Items.Add(val + "list.ru"); comboBox.Items.Add(val + "bk.ru"); comboBox.Items.Add(val + "mail.ua"); comboBox.Height = emailTextBox.ActualHeight; Grid.SetColumn(comboBox, 4); Grid.SetColumnSpan(comboBox, 2); grid.Children.Add(comboBox); comboBox.IsDropDownOpen = true; comboBox.Focus(); return comboBox; }
public static void Limpiar(TextBox t1, TextBox t2 = null, TextBox t3 = null) { t1.Clear(); if (t2 != null) t2.Clear(); if (t3 != null) t3.Clear(); t1.Focus(); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); _tb = (TextBox) GetTemplateChild("tbName"); if (_tb != null) { _tb.Focus(); } _tbError = (TextBlock) GetTemplateChild("tbError"); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); _tbName = (TextBox) GetTemplateChild("tbName"); if (_tbName != null) { _tbName.Focus(); } _pswb = (PasswordBox) GetTemplateChild("pswb"); }
public bool CheckTextBox(TextBox box) { if(box.Text.Length == 0) { MessageBox.Show("Вы ввели не все данные."); box.Focus(); return false; } return true; }
public override void OnApplyTemplate() { if (textBox != null) textBox.KeyDown -= textBox_KeyDown; base.OnApplyTemplate(); textBox = GetTemplateChild("TextBox") as TextBox; if (textBox != null) textBox.Focus(); textBox.KeyDown += textBox_KeyDown; }
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; }
public UriDialog() { Title = "Enter a URI"; ShowInTaskbar = false; SizeToContent = SizeToContent.WidthAndHeight; WindowStyle = WindowStyle.ToolWindow; WindowStartupLocation = WindowStartupLocation.CenterOwner; txtBox = new TextBox(); txtBox.Margin = new Thickness(48); Content = txtBox; txtBox.Focus(); }
private void aSircleTextbox_LostFocus(object sender, RoutedEventArgs e) { int iTextboxPosition = _getTextboxPosition(((TextBox)sender).Name); if (iTextboxPosition != 11) //Last Textbox { int iNextQuestionID = ((int)iTextboxPosition / 2) + 1; VisualStateManager.GoToState(this, _sCatapillarPrefix + "Question" + iNextQuestionID.ToString() , true); iTextboxPosition += 2; //Next Textbox _txtActiveInput = (TextBox)this.FindName(_sCatapillarPrefix + "Sircle" + iTextboxPosition.ToString() + "Textbox"); _txtActiveInput.Focus(); } }
public void list_KeyDown(ListBox list, KeyEventArgs e, TextBox txtbox, Popup popup) { i = txtbox.CaretIndex; switch (e.Key) { case Key.Enter: txtbox.Text = Regex.Replace(txtbox.Text, @"\b" + know + @"\b", UpdatedCollection[list.SelectedIndex]); txtbox.CaretIndex = i + UpdatedCollection[list.SelectedIndex].Length; know = string.Empty; popup.IsOpen = false; e.Handled = true; txtbox.Focus(); break; case Key.Left: popup.IsOpen = false; txtbox.CaretIndex = i; e.Handled = true; txtbox.Focus(); break; } }
public MeetTheDockers() { Title = "Meet the Dockers"; DockPanel dock = new DockPanel(); Content = dock; // Create menu. Menu menu = new Menu(); MenuItem item = new MenuItem(); item.Header = "Menu"; menu.Items.Add(item); // Dock menu at top of panel. DockPanel.SetDock(menu, Dock.Top); dock.Children.Add(menu); // Create tool bar. ToolBar tool = new ToolBar(); tool.Header = "Toolbar"; // Dock tool bar at top of panel. DockPanel.SetDock(tool, Dock.Top); dock.Children.Add(tool); // Create status bar. StatusBar status = new StatusBar(); StatusBarItem statitem = new StatusBarItem(); statitem.Content = "Status"; status.Items.Add(statitem); // Dock status bar at bottom of panel. DockPanel.SetDock(status, Dock.Bottom); dock.Children.Add(status); // Create list box. ListBox lstbox = new ListBox(); lstbox.Items.Add("List Box Item"); // Dock list box at left of panel. DockPanel.SetDock(lstbox, Dock.Left); dock.Children.Add(lstbox); // Create text box. TextBox txtbox = new TextBox(); txtbox.AcceptsReturn = true; // Add text box to panel & give it input focus. dock.Children.Add(txtbox); txtbox.Focus(); }
public void ShouldClearTextOnFocus() { var textBox = new TextBox(); textBox.Text = "DefaultText"; var command = new MockCommand(); TestableReturnCommandBehavior behavior = new TestableReturnCommandBehavior(textBox); behavior.Command = command; behavior.DefaultTextAfterCommandExecution = "DefaultText"; textBox.Focus(); Assert.AreEqual(string.Empty, textBox.Text); }
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; } }
public static bool IsInt32(TextBox textBox) { try { Convert.ToInt32(textBox.Text); return true; } catch (FormatException) { // MessageBox.Show(textBox.Tag.ToString() + " must be an integer value.", Title); textBox.Focus(); return false; } }
private bool IsOkay(String input, TextBox sender) { double number = 0; if (input.Length > 0 && Double.TryParse(input, out number)) { return true; } else { MessageBox.Show("Tarkista syöte."); sender.Focus(); sender.SelectAll(); return false; } }
private bool isOkay(string syote, TextBox sender) { double luku = 0; if (syote.Length > 0 && double.TryParse(syote, out luku)) { return true; } else { MessageBox.Show("Tarkista syöte!"); sender.Focus(); return false; } }
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; }
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; }
private void textBox_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { answers.Add((sender as TextBox).Text); var textBox = new TextBox(); textBox.Width = 187; textBox.KeyDown += textBox_KeyDown; stackPanel1.Children.Add(textBox); textBox.Focus(); } else if (e.Key == Key.Escape) { answers.Add((sender as TextBox).Text); timer.Stop(); this.Close(); } }
public override void OnApplyTemplate() { base.OnApplyTemplate(); _InputText = GetTemplateChild("InputText") as TextBox; _InputText.KeyDown += OnInputTextKeyDown; Button btnOK = GetTemplateChild("BtnOK") as Button; btnOK.Click += Button_OK; Button btnCancel = GetTemplateChild("BtnCancel") as Button; btnCancel.Click += Button_Cancel; _InputText.Focus(); if (!string.IsNullOrEmpty(_DefaultText)) { _InputText.Text = _DefaultText; } }
public void ShouldResetTextOnLostFocus() { var textBox = new TextBox(); var textBox2 = new TextBox(); var grid = new Grid(); grid.Children.Add(textBox); grid.Children.Add(textBox2); var command = new MockCommand(); TestableReturnCommandBehavior behavior = new TestableReturnCommandBehavior(textBox); behavior.Command = command; behavior.DefaultTextAfterCommandExecution = "DefaultText"; textBox.Focus(); DependencyObject scope = FocusManager.GetFocusScope(textBox); FocusManager.SetFocusedElement(scope, textBox2 as IInputElement); Assert.AreEqual("DefaultText", textBox.Text); }
public MeetTheDockers() { Title = "Meet the Dockers"; DockPanel dock = new DockPanel(); Content = dock; Menu menu = new Menu(); MenuItem item = new MenuItem(); item.Header = "Menu"; menu.Items.Add(item); DockPanel.SetDock(menu, Dock.Top); dock.Children.Add(menu); ToolBar tool = new ToolBar(); tool.Header = "Toolbar"; DockPanel.SetDock(tool, Dock.Top); dock.Children.Add(tool); StatusBar status = new StatusBar(); StatusBarItem statitem = new StatusBarItem(); statitem.Content = "Status"; status.Items.Add(statitem); DockPanel.SetDock(status, Dock.Bottom); dock.Children.Add(status); ListBox lstbox = new ListBox(); lstbox.Items.Add("List Box Item"); DockPanel.SetDock(lstbox, Dock.Left); dock.Children.Add(lstbox); TextBox txtbox = new TextBox(); txtbox.AcceptsReturn = true; dock.Children.Add(txtbox); txtbox.Focus(); }
public LoggedTextBox(TextBox textBox) { string outputDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\BenchmarkApplication\"; var df = new DirectoryInfo(outputDir); if (! df.Exists) { df = Directory.CreateDirectory(df.FullName); } string fileName = string.Format(df.FullName + "BenchmarkApplication{0}.log", DateTime.Now.ToFileTime()); var logFile = new FileStream(fileName, FileMode.Append, FileAccess.Write, FileShare.None); this.streamWriter = new StreamWriter(logFile); this.textBox = textBox; this.appendText = delegate(string text) { textBox.AppendText(text); textBox.ScrollToEnd(); textBox.Focus(); }; }
private void TextEntry_PreviewKeyDown(object sender, KeyEventArgs e) { TextBox currentCell = (TextBox)sender; TextBox targetCell = new TextBox(); int currentIndex = (int)currentCell.Tag; int targetIndex = -10; if (e.Key == Key.Enter) { e.Handled = true; SolvePuzzleButton.Command.Execute(null); ClearGrid.Focus(); } if (e.Key == Key.Up) { e.Handled = true; targetIndex = currentIndex - 9; } if (e.Key == Key.Down) { e.Handled = true; targetIndex = currentIndex + 9; } if (e.Key == Key.Left) { e.Handled = true; targetIndex = currentIndex - 1; } if (e.Key == Key.Right) { e.Handled = true; targetIndex = currentIndex + 1; } if (targetIndex != -10) { if (targetIndex < 1) { targetIndex += 81;} if (targetIndex > 81) { targetIndex -= 81;} targetCell = (from control in MainGrid.Children.OfType<TextBox>() where control.GetType().Name.Equals(typeof(System.Windows.Controls.TextBox).Name) && ((int)control.Tag).Equals(targetIndex) select control).FirstOrDefault(); if (targetCell != null) { targetCell.Focus(); } } }
public EditSomeText() { Title = "Edit Some Text"; txtbox = new TextBox(); txtbox.AcceptsReturn = true; txtbox.TextWrapping = TextWrapping.Wrap; txtbox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; txtbox.KeyDown += TextBoxOnKeyDown; Content = txtbox; try { txtbox.Text = File.ReadAllText(strFileName); } catch { } txtbox.CaretIndex = txtbox.Text.Length; txtbox.Focus(); }
public static string PickFile([NotNull] string message, [CanBeNull] System.Windows.Controls.TextBox textBox, [CanBeNull] System.Windows.Controls.Control otherControl, [NotNull] string pattern) { Assert.ArgumentNotNullOrEmpty(message, "message"); Assert.ArgumentNotNullOrEmpty(pattern, "pattern"); OpenFileDialog fileBrowserDialog = new OpenFileDialog { Title = message, Multiselect = false, CheckFileExists = true, Filter = pattern }; string filePath = textBox != null ? textBox.Text : string.Empty; string fileName = Path.GetFileName(filePath); if (!string.IsNullOrEmpty(fileName) && SIM.FileSystem.FileSystem.Local.File.Exists(filePath)) { fileBrowserDialog.FileName = fileName; fileBrowserDialog.InitialDirectory = Path.GetDirectoryName(filePath); } if (fileBrowserDialog.ShowDialog() == DialogResult.OK) { if (textBox != null) { textBox.Text = fileBrowserDialog.FileName; textBox.Focus(); if (otherControl != null) { otherControl.Focus(); } } return(fileBrowserDialog.FileName); } return(null); }
public WindowUsingItemProperty() { InitializeComponent(); tabControl.TabItemAdded += tabControl_TabItemAdded; tabControl.SelectionChanged += tabControl_SelectionChanged; // these 3 events ensure that all the contents of the textbox are selected on a mouseclick (as per IE) // code borrowed from the Windows Presentation Foundation Forum at http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2199428&SiteID=1 textBox.GotKeyboardFocus += delegate(object sender, KeyboardFocusChangedEventArgs e) { System.Windows.Controls.TextBox tb = (sender as System.Windows.Controls.TextBox); if (tb != null) { tb.SelectAll(); } }; textBox.MouseDoubleClick += delegate(object sender, MouseButtonEventArgs e) { System.Windows.Controls.TextBox tb = (sender as System.Windows.Controls.TextBox); if (tb != null) { tb.SelectAll(); } }; textBox.PreviewMouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e) { System.Windows.Controls.TextBox tb = (sender as System.Windows.Controls.TextBox); if (tb != null) { if (!tb.IsKeyboardFocusWithin) { e.Handled = true; tb.Focus(); } } }; }
/// <summary> /// 执行OpenFileCommand /// </summary> private static void SaveFileButtonClick(object sender, ExecutedRoutedEventArgs e) { try { TextBox tbox = null; var text = e.Parameter as FrameworkElement; if (text == null) { var obj = sender as FrameworkElement; var parent = obj.GetParentObject <ContentPresenter>("rightct"); if (parent != null) { tbox = (TextBox)parent.Tag; } } else { tbox = text as TextBox; } if (tbox == null) { return; } SaveFileDialog fd = new SaveFileDialog(); fd.Title = "文件保存路径"; fd.Filter = "所有文件(*.*)|*.*"; fd.FileName = tbox.Text.Trim(); if (fd.ShowDialog() == true) { tbox.Text = fd.FileName; } tbox.Focus(); } catch (Exception ex) { } }
public void SetSelectionAllOnGotFocus(System.Windows.Controls.TextBox textbox) { MouseButtonEventHandler _OnPreviewMouseDown = (sender, e) => { System.Windows.Controls.TextBox box = e.Source as System.Windows.Controls.TextBox; box.Focus(); e.Handled = true; }; RoutedEventHandler _OnLostFocus = (sender, e) => { System.Windows.Controls.TextBox box = e.Source as System.Windows.Controls.TextBox; box.PreviewMouseDown += _OnPreviewMouseDown; }; RoutedEventHandler _OnGotFocus = (sender, e) => { System.Windows.Controls.TextBox box = e.Source as System.Windows.Controls.TextBox; box.SelectAll(); box.PreviewMouseDown -= _OnPreviewMouseDown; }; textbox.PreviewMouseDown += _OnPreviewMouseDown; textbox.LostFocus += _OnLostFocus; textbox.GotFocus += _OnGotFocus; }
public PrintBetterBanner() { Title = "Print Better Banner"; SizeToContent = SizeToContent.WidthAndHeight; // Make StackPanel content of window. StackPanel stack = new StackPanel(); Content = stack; // Create TextBox. txtbox = new TextBox(); txtbox.Width = 250; txtbox.Margin = new Thickness(12); stack.Children.Add(txtbox); // Create Font Button. Button btn = new Button(); btn.Content = "_Font..."; btn.Margin = new Thickness(12); btn.Click += FontOnClick; btn.HorizontalAlignment = HorizontalAlignment.Center; stack.Children.Add(btn); // Create Print Button. btn = new Button(); btn.Content = "_Print..."; btn.Margin = new Thickness(12); btn.Click += PrintOnClick; btn.HorizontalAlignment = HorizontalAlignment.Center; stack.Children.Add(btn); // Initialize Facename field. face = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch); txtbox.Focus(); }
/// <summary> /// 执行OpenFolderCommand /// </summary> private static void OpenFolderButtonClick(object sender, ExecutedRoutedEventArgs e) { try { TextBox tbox = null; var text = e.Parameter as FrameworkElement; if (text == null) { var obj = sender as FrameworkElement; var parent = obj.GetParentObject <ContentPresenter>("rightct"); if (parent != null) { tbox = (TextBox)parent.Tag; } } else { tbox = text as TextBox; } if (tbox == null) { return; } FolderBrowserDialog fd = new FolderBrowserDialog(); fd.Description = "请选择文件路径"; fd.SelectedPath = tbox.Text.Trim(); if (fd.ShowDialog() == DialogResult.OK) { tbox.Text = fd.SelectedPath; } tbox.Focus(); } catch (Exception ex) { } }
private void octet1_KeyDown(object sender, KeyEventArgs e) { check(sender); if (e.Key == Key.Back) { if (((System.Windows.Controls.TextBox)sender).SelectionStart == 0) { switch (((System.Windows.Controls.TextBox)sender).Name) { case "octet2": { System.Windows.Controls.TextBox el = octet1; if (el.Text.Length > 0) { el.Text = el.Text.Substring(0, el.Text.Length); } el.Focus(); el.Select(el.Text.Length, 0); } break; case "octet3": { System.Windows.Controls.TextBox el = octet2; if (el.Text.Length > 0) { el.Text = el.Text.Substring(0, el.Text.Length); } el.Focus(); el.Select(el.Text.Length, 0); } break; case "octet4": { System.Windows.Controls.TextBox el = octet3; if (el.Text.Length > 0) { el.Text = el.Text.Substring(0, el.Text.Length); } el.Focus(); el.Select(el.Text.Length, 0); } break; default: break; } } } else { if (((System.Windows.Controls.TextBox)sender).SelectionStart == 3) { switch (((System.Windows.Controls.TextBox)sender).Name) { case "octet1": { TextBox el = octet2; el.Focus(); el.SelectAll(); } break; case "octet2": { TextBox el = octet3; el.Focus(); el.SelectAll(); } break; case "octet3": { TextBox el = octet4; el.Focus(); el.SelectAll(); } break; default: break; } } } }
private void SetupNotepad() { // compute boundaries var bounds = _selectionForegroundPath.Data.Bounds; var width = Math.Max(bounds.Width, NOTEPAD_MIN_WIDTH); var left = bounds.Left + bounds.Width / 2 - width / 2; var top = bounds.Bottom + 40; // create grid var grid = new Grid { Width = width, Height = 300 }; grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(20) }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); // create text editor var editor = new TextBox { FontSize = FONT_SIZE_NORMAL, Foreground = Brushes.White, Background = Brushes.Transparent, TextWrapping = TextWrapping.Wrap, AcceptsReturn = true, CaretBrush = Brushes.DodgerBlue }; Grid.SetColumn(editor, 0); // create text viewer var viewer = new FlowDocumentScrollViewer { FontSize = FONT_SIZE_NORMAL, Foreground = Brushes.White, VerticalScrollBarVisibility = ScrollBarVisibility.Hidden, Background = Brushes.Transparent }; var binding = new Binding() { Source = editor, Path = new PropertyPath("Text"), Converter = (TextToFlowDocumentConverter)FindResource("TextToFlowDocumentConverter") }; viewer.SetBinding(FlowDocumentScrollViewer.DocumentProperty, binding); Grid.SetColumn(viewer, 2); // add to grid grid.Children.Add(editor); grid.Children.Add(viewer); // add to canvas Canvas.SetTop(grid, top); Canvas.SetLeft(grid, left); MainCanvas.Children.Add(grid); // set focus to editor editor.Focus(); }
public CustomMessageBox( string caption, CustomMessageBoxIcon icon = CustomMessageBoxIcon.Default, CustomMessageBoxButtons buttons = CustomMessageBoxButtons.None, List <string> messageRows = null, string prompt = null, CustomMessageBoxPromptValidation promptValidationMode = CustomMessageBoxPromptValidation.None, CustomMessageBoxFocus controlFocus = CustomMessageBoxFocus.Default) { DataContext = this; InitializeComponent(); if (DesignerProperties.GetIsInDesignMode(this)) { } else { // ToDo: Evil Hack to have the cake (see actual design in design mode) and eat it too (have different styles at runtime) this.Resources = null; } int currentIndex = 0; this.Title = caption; this.promptValidationMode = promptValidationMode; this.controlFocus = controlFocus; var rowCaption = new RowDefinition(); rowCaption.Height = GridLength.Auto; ContentGrid.RowDefinitions.Add(rowCaption); var captionTextBox = new System.Windows.Controls.TextBlock(); var captionStyle = (Style)FindResource("VersionName_TextBox_Style"); if (captionStyle != null) { captionTextBox.Style = captionStyle; } captionTextBox.Text = caption; ContentGrid.InsertAt(captionTextBox, 0, currentIndex); currentIndex++; switch (icon) { case CustomMessageBoxIcon.Information: { var informationStyle = (Style)FindResource("CustomMessageBoxInformationIconStyle"); if (informationStyle != null) { DialogImage.Style = informationStyle; } break; } case CustomMessageBoxIcon.Question: { var questionStyle = (Style)FindResource("CustomMessageBoxQuestionIconStyle"); if (questionStyle != null) { DialogImage.Style = questionStyle; } break; } case CustomMessageBoxIcon.Error: { var errorStyle = (Style)FindResource("CustomMessageBoxErrorIconStyle"); if (errorStyle != null) { DialogImage.Style = errorStyle; } break; } case CustomMessageBoxIcon.Default: { var defaultStyle = (Style)FindResource("CustomMessageBoxDefaultIconStyle"); if (defaultStyle != null) { DialogImage.Style = defaultStyle; } break; } } var textblockStyle = (Style)FindResource("CustomMessageBox_TextBlock_Style"); if (messageRows != null && messageRows.Any()) { foreach (var messgeRow in messageRows) { var rowDefinition = new RowDefinition(); rowDefinition.Height = GridLength.Auto; ContentGrid.RowDefinitions.Add(rowDefinition); var tempTextBox = new System.Windows.Controls.TextBlock(); if (textblockStyle != null) { tempTextBox.Style = textblockStyle; } tempTextBox.Text = messgeRow; ContentGrid.InsertAt(tempTextBox, 0, currentIndex); currentIndex++; } } if (prompt != null) { var promptRow = new RowDefinition(); promptRow.Height = GridLength.Auto; ContentGrid.RowDefinitions.Add(promptRow); promptTextBox = new System.Windows.Controls.TextBox(); var promptStyle = (Style)FindResource("MainWindowTextBoxStyle"); if (promptStyle != null) { promptTextBox.Style = promptStyle; } promptTextBox.Name = "DialogPromptTextBox"; promptTextBox.IsEnabled = true; promptTextBox.IsReadOnly = false; promptTextBox.TextChanged += PromptTextBox_TextChanged; promptTextBox.Text = prompt; ContentGrid.InsertAt(promptTextBox, 0, currentIndex); if (controlFocus == CustomMessageBoxFocus.Prompt) { promptTextBox.Focus(); promptTextBox.Select(0, prompt.Length); } currentIndex++; } if (buttons != CustomMessageBoxButtons.None) { var tempButton = new SvgImageButton1(); var buttonStyle = (Style)FindResource("SvgAcceptButton"); if (buttonStyle != null) { tempButton.Style = buttonStyle; } tempButton.HorizontalAlignment = HorizontalAlignment.Right; tempButton.Click += OkButton_Click; tempButton.IsDefault = true; DialogGrid.InsertAt(tempButton, 1, 3); if (controlFocus == CustomMessageBoxFocus.Ok) { tempButton.Focus(); } if (buttons == CustomMessageBoxButtons.OkAndCancel) { var cancelButton = new SvgImageButton1(); var cancelButtonStyle = (Style)FindResource("SvgCancelButton"); if (cancelButtonStyle != null) { cancelButton.Style = cancelButtonStyle; } cancelButton.HorizontalAlignment = HorizontalAlignment.Left; cancelButton.Click += CancelButton_Click; DialogGrid.InsertAt(cancelButton, 0, 3); if (controlFocus == CustomMessageBoxFocus.Cancel) { cancelButton.Focus(); } } currentIndex++; } }
private void InitTextbox(Point mousePoint) { if (textBox == null) { textBox = new TextBox { MinWidth = 100, BorderThickness = new Thickness(1), Background = new SolidColorBrush(Colors.Transparent), AcceptsReturn = true, FontFamily = new FontFamily("Microsoft YaHei") }; textBox.LostFocus += (sender, args) => { if (sender is TextBox box) { box.SelectionLength = 0; box.BorderThickness = new Thickness(0); box.IsReadOnly = true; _istextboxEditing = false; if (textBox == box && string.IsNullOrEmpty(box.Text)) { AdornerRectangle.Children.Remove(box); textBox = null; } } }; textBox.GotFocus += (sender, args) => { if (sender is TextBox box) { box.BorderThickness = new Thickness(1); } }; textBox.MouseDoubleClick += (sender, args) => { if (sender is TextBox box) { _istextboxEditing = true; box.IsReadOnly = false; box.Cursor = Cursors.Arrow; box.Focus(); box.SelectionLength = 0; } }; textBox.MouseEnter += (sender, args) => { if (sender is TextBox box) { box.Cursor = box.IsReadOnly ? Cursors.SizeAll : Cursors.Arrow; } }; textBox.PreviewMouseLeftButtonDown += (sender, args) => { _selectedElement = (TextBox)sender; }; AdornerRectangle.Children.Add(textBox); } if (string.IsNullOrEmpty(textBox.Text)) { textBox.MaxWidth = AdornerRectangle.RenderSize.Width - mousePoint.X; textBox.MaxHeight = AdornerRectangle.RenderSize.Height - mousePoint.Y; textBox.BorderBrush = new SolidColorBrush(ColorSelected); textBox.Foreground = new SolidColorBrush(ColorSelected); textBox.CaretBrush = new SolidColorBrush(ColorSelected); textBox.FontSize = SizeSelected * 3; Canvas.SetLeft(textBox, mousePoint.X); Canvas.SetTop(textBox, mousePoint.Y); textBox.Focus(); textBox.IsReadOnly = false; } else { textBox = null; } }
static void Main(string[] args) { var c = new JSCSolutionsNETCarouselCanvas { CloseOnClick = false }; c.HideSattelites(); //c.Container.Effect = new DropShadowEffect(); //c.Container.BitmapEffect = new DropShadowBitmapEffect(); //.MoveTo(0, ImageCarouselCanvas.DefaultHeight - 96).SizeTo(ImageCarouselCanvas.DefaultWidth, 96); var cc = new Canvas(); // http://cloudstore.blogspot.com/2008/05/creating-custom-window-style.html var wcam = new Window(); wcam.Background = Brushes.Transparent; wcam.WindowStyle = WindowStyle.None; wcam.ResizeMode = ResizeMode.NoResize; wcam.SizeTo(200, 200); wcam.AllowsTransparency = true; //wcam.Opacity = 0.5; wcam.ShowInTaskbar = false; wcam.Cursor = Cursors.Hand; wcam.Focusable = false; wcam.Topmost = true; var w = cc.ToWindow(); w.SizeToContent = SizeToContent.Manual; //w.SizeTo(400, 400); //w.ToTransparentWindow(); // http://blog.joachim.at/?p=39 // http://blogs.msdn.com/changov/archive/2009/01/19/webbrowser-control-on-transparent-wpf-window.aspx // http://blogs.interknowlogy.com/johnbowen/archive/2007/06/20/20458.aspx w.AllowsTransparency = true; w.WindowStyle = System.Windows.WindowStyle.None; w.Focusable = false; //w.Background = new SolidColorBrush(Color.FromArgb(0x20, 0, 0, 0)); w.Background = Brushes.Transparent; w.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; w.Topmost = true; //w.ShowInTaskbar = false; var winfoc = new Canvas(); var winfo = winfoc.ToWindow(); winfo.AllowsTransparency = true; winfo.ShowInTaskbar = false; winfo.WindowStyle = WindowStyle.None; //winfo.Background = Brushes.Transparent; winfo.Background = Brushes.Red; winfo.Opacity = 0.3; winfo.ResizeMode = ResizeMode.NoResize; winfo.SizeToContent = SizeToContent.Manual; winfo.Topmost = true; // http://www.squidoo.com/youtubehd var NextInputModeEnabled = false; var NextInputModeKeyDownEnabled = false; Action <Key> NextInputModeKeyDown = delegate { }; var CommandKeysEnabled = false; #region TopicText var TopicText = new System.Windows.Controls.TextBox { //IsReadOnly = true, Background = Brushes.Transparent, BorderThickness = new System.Windows.Thickness(0), Foreground = Brushes.White, Effect = new DropShadowEffect(), Text = "JSC C# Foo Bar", //TextDecorations = TextDecorations.Underline, FontFamily = new FontFamily("Verdana"), FontSize = 24, TextAlignment = System.Windows.TextAlignment.Right }; #endregion #region KeyDown InterceptKeys.KeyDown += key => { if (key == Key.LeftShift) { //w.Background = new SolidColorBrush(Color.FromArgb(2, 0, 0, 0)); //w.MakeInteractive(true); NextInputModeEnabled = true; } else { if (NextInputModeEnabled || NextInputModeKeyDownEnabled) { NextInputModeKeyDownEnabled = false; NextInputModeKeyDown(key); } NextInputModeEnabled = false; } }; #endregion #region KeyUp InterceptKeys.KeyUp += key => { if (key == Key.CapsLock) { CommandKeysEnabled = !CommandKeysEnabled; TopicText.IsReadOnly = CommandKeysEnabled; TopicText.Select(0, 0); } if (key == Key.LeftShift) { NextInputModeKeyDownEnabled = false; } else { } NextInputModeEnabled = false; }; #endregion var s = 7; var ThumbnailSize = 0.4; var CaptionBackgroundHeight = 24; #region UpdateChildren Action UpdateChildren = delegate { if (w.ActualWidth == 0) { return; } var ss = s; var ss2 = 0; Console.WriteLine( new { w.Left, w.Top }); winfo.MoveTo(w.Left, w.Top).SizeTo(w.ActualWidth, w.ActualHeight); if (ThumbnailSize == 1) { wcam.Background = Brushes.Black; ss = 0; var qw = w.ActualWidth - ss * 2; var qh = w.ActualHeight - ss * 2; // no status bars or menues please :) wcam.MoveTo( w.Left + ss + ss2, w.Top + (w.ActualHeight - qh * ThumbnailSize - ss) - ss2 ).SizeTo( qw * ThumbnailSize, qh * ThumbnailSize ); } else { wcam.Background = Brushes.Transparent; //if (w.WindowState == WindowState.Maximized) //{ // ss2 = s; //} var qw = w.ActualWidth - ss * 2; var qh = w.ActualHeight - ss * 2; wcam.MoveTo(w.Left + ss + ss2, w.Top + (w.ActualHeight - qh * ThumbnailSize - ss) - ss2).SizeTo(qw * ThumbnailSize, qh * ThumbnailSize); } }; #endregion w.LocationChanged += delegate { UpdateChildren(); }; var Borders = Enumerable.Range(1, s * 2).Reverse().Select( Width => new { Width = Width * 2, Left = new Rectangle { Fill = Brushes.Black, Opacity = 0.06 }.MoveTo(0, 0).AttachTo(winfoc), Right = new Rectangle { Fill = Brushes.Black, Opacity = 0.06 }.MoveTo(0, 0).AttachTo(winfoc), Bottom = new Rectangle { Fill = Brushes.Black, Opacity = 0.03 }.MoveTo(0, 0).AttachTo(winfoc), Top = new Rectangle { Fill = Brushes.Black, Opacity = 0.11 }.MoveTo(0, 0).AttachTo(winfoc) } ).ToArray(); var CaptionBackgroundOverlay = new Rectangle { Fill = Brushes.Black, Opacity = 0.02, }.AttachTo(cc); var CaptionSysMenuOverlay = new Rectangle { Fill = Brushes.Black, Opacity = 0.02, }.AttachTo(cc).SizeTo(CaptionBackgroundHeight * 4, CaptionBackgroundHeight); var ExtraBorderTop = new Rectangle { Fill = Brushes.Black, Opacity = 0.0, }.AttachTo(winfoc); var ExtraBorderBottom = new Rectangle { Fill = Brushes.Black, Opacity = 0.0, }.AttachTo(winfoc); var CaptionClose = new TextBox { Foreground = Brushes.Red, FontFamily = new FontFamily("Webdings"), Text = "r", Background = Brushes.Transparent, BorderThickness = new Thickness(0), TextAlignment = System.Windows.TextAlignment.Center, Opacity = 0.5 }.AttachTo(winfoc); var CaptionText = new System.Windows.Controls.TextBox { IsReadOnly = true, Background = Brushes.Transparent, BorderThickness = new System.Windows.Thickness(0), Foreground = Brushes.White, Effect = new System.Windows.Media.Effects.DropShadowEffect(), Text = "jsc-solutions.net", //TextDecorations = TextDecorations.Underline, FontFamily = new FontFamily("Verdana"), FontSize = 16, TextAlignment = System.Windows.TextAlignment.Right } .AttachTo(winfoc); TopicText.AttachTo(winfoc); #region SetCaption Action <string> SetCaption = text => { if (string.IsNullOrEmpty(text)) { CaptionText.Text = "jsc-solutions.net"; } else { CaptionText.Text = text + " | jsc-solutions.net"; } }; #endregion c.AttachContainerTo(winfoc); var ExtraBorderSize = 0.10; var Intro = new PromotionBrandIntro.ApplicationCanvas().AttachTo(winfoc); Intro.Opacity = 0; #region SizeChanged Action SizeChanged = delegate { Intro.SizeTo(w.ActualWidth, w.ActualHeight); //ink.SizeTo(w.ActualWidth, w.ActualHeight - CaptionBackgroundHeight); var CaptionWidth = 200; CaptionBackgroundOverlay.MoveTo(w.ActualWidth - CaptionWidth, 0).SizeTo(CaptionWidth, CaptionBackgroundHeight); ExtraBorderTop.MoveTo(0, 0).SizeTo(w.ActualWidth, w.ActualHeight * ExtraBorderSize); ExtraBorderBottom.MoveTo(0, w.ActualHeight * (1 - ExtraBorderSize)).SizeTo(w.ActualWidth, w.ActualHeight * ExtraBorderSize); TopicText.MoveTo( 0, w.ActualHeight - 48 ).SizeTo(w.ActualWidth - 48, 48); if (c != null) { c.MoveContainerTo(-200 + 42, -200 + 38); } Borders.WithEach(k => k.Left.MoveTo(0, 0).SizeTo(k.Width, w.ActualHeight)); Borders.WithEach(k => k.Right.MoveTo(w.ActualWidth - k.Width, 0).SizeTo(k.Width, w.ActualHeight)); Borders.WithEach(k => k.Bottom.MoveTo(0, w.ActualHeight - k.Width).SizeTo(w.ActualWidth, k.Width)); Borders.WithEach(k => k.Top.MoveTo(0, 0).SizeTo(w.ActualWidth, k.Width)); CaptionText.MoveTo(0, 2).SizeTo(w.ActualWidth - CaptionBackgroundHeight, 32); CaptionClose.MoveTo(w.ActualWidth - CaptionBackgroundHeight, s).SizeTo(CaptionBackgroundHeight - s, CaptionBackgroundHeight - s); UpdateChildren(); }; #endregion w.SizeChanged += delegate { SizeChanged(); }; w.StateChanged += delegate { if (w.WindowState == WindowState.Maximized) { w.WindowState = WindowState.Normal; } SizeChanged(); }; #region GetWindows Func <IEnumerable <Internal.Window> > GetWindows = delegate { var windows = new List <Internal.Window>(); Internal.EnumWindows( (IntPtr hwnd, int lParam) => { if (new WindowInteropHelper(wcam).Handle != hwnd && (Internal.GetWindowLongA(hwnd, Internal.GWL_STYLE) & Internal.TARGETWINDOW) == Internal.TARGETWINDOW ) { StringBuilder sb = new StringBuilder(100); Internal.GetWindowText(hwnd, sb, sb.Capacity); windows.Add( new Internal.Window { Handle = hwnd, Title = sb.ToString() } ); } return(true); //continue enumeration } , 0); return(windows.OrderBy(k => k.Title)); }; #endregion var ResetThumbnailSkip = 0; Func <Internal.Window> GetCurrentThumbnail = () => GetWindows().AsCyclicEnumerable().Skip(ResetThumbnailSkip).First(); #region AnimationCompleted Intro.AnimationCompleted += delegate { if (c == null) { c = new JSCSolutionsNETCarouselCanvas { CloseOnClick = false }.AttachContainerTo(winfoc); c.HideSattelites(); CaptionClose.Show(); SizeChanged(); } }; #endregion wcam.SourceInitialized += delegate { { wcam.MakeInteractive(false); UpdateChildren(); } var thumb = IntPtr.Zero; ResetThumbnailSkip = GetWindows().Where( k => k.Title.Contains("Chrome") || k.Title.Contains("Studio") || k.Title.Contains("Minefield") ).TakeWhile(k => k.Handle != Internal.GetForegroundWindow()).Count(); #region ResetThumbnail Action ResetThumbnail = delegate { GetCurrentThumbnail().With( shadow => { //t.Text = shadow.Title; if (thumb != IntPtr.Zero) { Internal.DwmUnregisterThumbnail(thumb); } int i = Internal.DwmRegisterThumbnail( new WindowInteropHelper(wcam).Handle, shadow.Handle, out thumb); #region UpdateThumbnail Action UpdateThumbnail = delegate { if (thumb != IntPtr.Zero) { Internal.PSIZE size; Internal.DwmQueryThumbnailSourceSize(thumb, out size); Internal.DWM_THUMBNAIL_PROPERTIES props = new Internal.DWM_THUMBNAIL_PROPERTIES(); props.fVisible = true; props.dwFlags = Internal.DWM_TNP_VISIBLE | Internal.DWM_TNP_RECTDESTINATION | Internal.DWM_TNP_OPACITY | Internal.DWM_TNP_SOURCECLIENTAREAONLY; props.opacity = (byte)((byte)(0x7F) + (byte)((0x80) * (ThumbnailSize))); props.rcDestination = new Internal.Rect(0, 0, (int)wcam.ActualWidth, (int)wcam.ActualHeight); props.fSourceClientAreaOnly = true; if (size.x < wcam.ActualWidth) { props.rcDestination.Right = props.rcDestination.Left + size.x; props.rcDestination.Left += ((int)wcam.ActualWidth - size.x) / 2; props.rcDestination.Right += ((int)wcam.ActualWidth - size.x) / 2; } if (size.y < wcam.ActualHeight) { props.rcDestination.Bottom = props.rcDestination.Top + size.y; props.rcDestination.Top += ((int)wcam.ActualHeight - size.y) / 2; props.rcDestination.Bottom += ((int)wcam.ActualHeight - size.y) / 2; } Internal.DwmUpdateThumbnailProperties(thumb, ref props); } }; #endregion (1000 / 15).AtInterval(UpdateThumbnail); wcam.SizeChanged += delegate { UpdateThumbnail(); }; } ); }; #endregion ResetThumbnail(); NextInputModeKeyDown += key => { if (key == Key.RightShift) { NextInputModeKeyDownEnabled = true; if (c != null) { CaptionClose.Hide(); c.AtClose += delegate { c.OrphanizeContainer(); }; c.Close(); c = null; } Intro.Background = Brushes.Transparent; Intro.Overlay.Opacity = 1; Intro.FadeIn( delegate { 2000.AtDelay(Intro.PrepareAnimation()); } ); } if (!CommandKeysEnabled) { if (key == Key.F2) { w.Activate(); TopicText.Focusable = true; TopicText.Focus(); TopicText.SelectAll(); } return; } if (key == Key.Right) { if (w.IsActive) { GetCurrentThumbnail().Activate(); } else { NextInputModeKeyDownEnabled = true; ResetThumbnailSkip = GetWindows().TakeWhile(k => k.Handle != Internal.GetForegroundWindow()).Count(); ResetThumbnail(); } } if (key == Key.Up) { NextInputModeKeyDownEnabled = true; if (ThumbnailSize < 0.3) { ThumbnailSize = 0.3; } else if (ThumbnailSize < 0.5) { ThumbnailSize = 0.5; } else if (ThumbnailSize < 1) { ThumbnailSize = 1; } else { if (c != null) { CaptionClose.Hide(); c.AtClose += delegate { c.OrphanizeContainer(); }; c.Close(); c = null; } } UpdateChildren(); } if (key == Key.Down) { NextInputModeKeyDownEnabled = true; if (c == null) { c = new JSCSolutionsNETCarouselCanvas { CloseOnClick = false }.AttachContainerTo(winfoc); CaptionClose.Show(); } else if (ThumbnailSize > 0.5) { ThumbnailSize = 0.5; } else if (ThumbnailSize > 0.3) { ThumbnailSize = 0.3; } else if (ThumbnailSize == 0.3) { ThumbnailSize = 0; } SizeChanged(); } if (key == Key.Left) { if (w.IsActive) { NextInputModeKeyDownEnabled = true; if (ExtraBorderTop.Opacity == 1) { ExtraBorderTop.Opacity = 0; ExtraBorderBottom.Opacity = 0; } else { ExtraBorderTop.Opacity = 1; ExtraBorderBottom.Opacity = 1; } } } }; }; winfo.SourceInitialized += delegate { winfo.MakeInteractive(false); }; w.SourceInitialized += delegate { // http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/61e93dca-e24c-4953-9719-22ce3f705353 Matrix m = PresentationSource.FromVisual(w).CompositionTarget.TransformToDevice; double dx = m.M11; double dy = m.M22; w.SizeTo(1280 / dx, 768 / dy); w.MoveTo(8, 0); SizeChanged(); wcam.Owner = w; winfo.Owner = w; wcam.Show(); winfo.Show(); HwndSource hwndSource = (HwndSource)HwndSource.FromVisual(w); hwndSource.AddHook( (IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handeled) => { if (msg == 0x0084) // WM_NCHITTEST { //http://agsmith.wordpress.com/2008/09/16/hit-testing-in-wpf/ var p = new { cx = w.ActualWidth - (Internal.LOWORD(lParam) - w.Left), cy = w.ActualHeight - (Internal.HIWORD(lParam) - w.Top), x = Internal.LOWORD(lParam) - w.Left, y = Internal.HIWORD(lParam) - w.Top }; CaptionText.Text = p.ToString(); handeled = true; return((IntPtr)HitTestValues.HTCAPTION); // HTCAPTION if (false) { if (p.x < s) { if (p.y < s) { return((IntPtr)HitTestValues.HTTOPLEFT); // HTCAPTION } } if (p.x < CaptionBackgroundHeight) { if (p.y < CaptionBackgroundHeight) { return((IntPtr)HitTestValues.HTSYSMENU); // HTCAPTION } } if (p.cx < CaptionBackgroundHeight) { if (p.y < CaptionBackgroundHeight) { return((IntPtr)HitTestValues.HTCLOSE); // HTCAPTION } } if (p.cx < s) { if (p.cy < s) { return((IntPtr)HitTestValues.HTBOTTOMRIGHT); // HTCAPTION } } if (p.cx < s) { if (p.y < s) { return((IntPtr)HitTestValues.HTTOPRIGHT); // HTCAPTION } } if (p.x < s) { if (p.cy < s) { return((IntPtr)HitTestValues.HTBOTTOMLEFT); // HTCAPTION } } if (p.x < s) { return((IntPtr)HitTestValues.HTLEFT); // HTCAPTION } if (p.y < s) { return((IntPtr)HitTestValues.HTTOP); // HTCAPTION } if (p.cx < s) { return((IntPtr)HitTestValues.HTRIGHT); // HTCAPTION } if (p.cy < s) { return((IntPtr)HitTestValues.HTBOTTOM); // HTCAPTION } if (p.y < CaptionBackgroundHeight) { return((IntPtr)HitTestValues.HTCAPTION); // HTCAPTION } return((IntPtr)HitTestValues.HTTRANSPARENT); // HTCAPTION } } return(IntPtr.Zero); } ); }; InterceptKeys.InternalMain( Rehook => { w.Deactivated += delegate { TopicText.Focusable = false; }; w.Activated += delegate { //TopicText.Focus(); Rehook(); }; w.ShowDialog(); } ); }
/// <summary> /// Calcular el producto /// </summary> /// <param name="sender"></param> private void CalcularProducto(object sender) { AlmacenCierreDiaInventarioInfo seleccion = (AlmacenCierreDiaInventarioInfo)gridProductosInventario.SelectedItem; TextBox text = (TextBox)sender; if (seleccion != null && text.Text != "") { text.Text = text.Text.Replace(" ", ""); if (ValidarDecimal(text.Text)) { var cantidad = decimal.Parse(text.Text.Trim(), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture); if (cantidad > 0) { foreach (var almacenCierreDiaInventarioInfo in datosGrid.Where(almacenCierreDiaInventarioInfo => seleccion.ProductoID == almacenCierreDiaInventarioInfo.ProductoID)) { almacenCierreDiaInventarioInfo.ImporteReal = almacenCierreDiaInventarioInfo.PrecioPromedio * cantidad; almacenCierreDiaInventarioInfo.FolioAlmacen = long.Parse(txtFolio.Text); almacenCierreDiaInventarioInfo.CantidadReal = cantidad; almacenCierreDiaInventarioInfo.Observaciones = txtObservaciones.Text; btnGuardar.IsEnabled = true; break; } } else { foreach (var almacenCierreDiaInventarioInfo in datosGrid) { if (seleccion.ProductoID == almacenCierreDiaInventarioInfo.ProductoID) { almacenCierreDiaInventarioInfo.ImporteReal = 0; almacenCierreDiaInventarioInfo.CantidadReal = 0; break; } } } } else { index = gridProductosInventario.SelectedIndex; SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.CierreDiaInventario_CantidadInsertadaError, MessageBoxButton.OK, MessageImage.Warning); gridProductosInventario.CurrentCell = new DataGridCellInfo( gridProductosInventario.Items[index], gridProductosInventario.Columns[4]); gridProductosInventario.BeginEdit(); gridProductosInventario.SelectedIndex = index; text.SelectAll(); return; } } index = gridProductosInventario.SelectedIndex; gridProductosInventario.ItemsSource = null; gridProductosInventario.ItemsSource = datosGrid; gridProductosInventario.Focus(); if (gridProductosInventario.Items.Count > (index + 1)) { gridProductosInventario.CurrentCell = new DataGridCellInfo( gridProductosInventario.Items[index + 1], gridProductosInventario.Columns[4]); gridProductosInventario.BeginEdit(); gridProductosInventario.SelectedIndex = index + 1; } else { btnGuardar.Focus(); } text.Focus(); text.SelectAll(); }