void PwdPaste() { // <Snippet_PwdBox_Paste> // A TextBox will serve as a contrived means of putting our test // password on the Clipboard. TextBox txtBox = new TextBox(); PasswordBox pwdBox = new PasswordBox(); // Put some content in the TextBox, and copy it to the Clipboard. txtBox.Text = "Open Sesame!"; txtBox.SelectAll(); txtBox.Copy(); // Paste the contents of the Clipboard into the PasswordBox. After this // call, the value of pwdBox.Password == "Open Sesame!". pwdBox.Paste(); // </Snippet_PwdBox_Paste> }
public WindowMain() { foreach (var entry in ConfigFile.ReadAddressInfo(GetCurrency() + "_nonce")) { m_dAddressNonce[entry.Item1] = entry.Item2; } m_lBlockExplorer = ConfigFile.ReadTrimmedLines(GetCurrency() + "_block_explorer"); m_lNode = ConfigFile.ReadTrimmedLines(GetCurrency() + "_node"); // window Title = GetCurrency() + " Transaction Generator - MiniCryptoWallet"; Background = SystemColors.ControlBrush; foreach (string file in Directory.EnumerateFiles(Directory.GetCurrentDirectory(), GetCurrency() + "_background.*")) { BitmapImage image = new BitmapImage(new Uri(file)); DpiScale scale = VisualTreeHelper.GetDpi(this); Background = new ImageBrush(image) { TileMode = TileMode.Tile, ViewportUnits = BrushMappingMode.Absolute, Viewport = new Rect(0, 0, image.Width * image.DpiX / 96 / scale.DpiScaleX, image.Height * image.DpiY / 96 / scale.DpiScaleY) }; } // control Grid gridInitOrData = new Grid(); gridInitOrData.RowDefinitions.Add(new RowDefinition()); gridInitOrData.ColumnDefinitions.Add(new ColumnDefinition()); WPF.Add(gridInitOrData, m_textBoxInitOrData); gridInitOrData.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); WPF.Add(gridInitOrData, m_buttonClear); gridInitOrData.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); WPF.Add(gridInitOrData, m_buttonBin); gridInitOrData.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); WPF.Add(gridInitOrData, m_buttonHex); Grid grid = new Grid(); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); grid.ColumnDefinitions.Add(new ColumnDefinition()); for (int i = 0; i < 7; i++) { grid.RowDefinitions.Add(new RowDefinition()); } WPF.Add(grid, new Label() { HorizontalContentAlignment = HorizontalAlignment.Right, Content = "Password / Private key" }); WPF.Add(grid, m_passwordBoxPP); WPF.Add(grid, new Label() { HorizontalContentAlignment = HorizontalAlignment.Right, Content = "Nonce" }); WPF.Add(grid, m_comboBoxNonce); WPF.Add(grid, new Label() { HorizontalContentAlignment = HorizontalAlignment.Right, Content = "To" }); WPF.Add(grid, m_comboBoxTo); WPF.Add(grid, new Label() { HorizontalContentAlignment = HorizontalAlignment.Right, Content = "Value" }); WPF.Add(grid, m_comboBoxValue); WPF.Add(grid, new Label() { HorizontalContentAlignment = HorizontalAlignment.Right, Content = "Init / Data" }); WPF.Add(grid, gridInitOrData); WPF.Add(grid, new Label() { HorizontalContentAlignment = HorizontalAlignment.Right, Content = "Gas price" }); WPF.Add(grid, m_comboBoxGasPrice); WPF.Add(grid, new Label() { HorizontalContentAlignment = HorizontalAlignment.Right, Content = "Gas limit" }); WPF.Add(grid, m_comboBoxGasLimit); foreach (FrameworkElement element in grid.Children) { element.Margin = new Thickness(0, 4, 0, 0); } DockPanel panel = new DockPanel() { Opacity = 0.8 }; WPF.Add(panel, Dock.Top, m_menu); WPF.Add(panel, Dock.Top, grid); WPF.Add(panel, Dock.Top, new Label() { Content = GetCurrency() + " transaction" }); WPF.Add(panel, Dock.Top, new RichTextBox() { Document = new FlowDocument(m_paragraphTransaction), IsReadOnly = true, IsDocumentEnabled = true, VerticalScrollBarVisibility = ScrollBarVisibility.Auto }); Content = panel; // data and handler Action <bool> actionSimpleAdvanced = toggle => { bool advanced = toggle ^ ((string)ConfigFile.RegistryGet("Advanced", "True") == "True"); ConfigFile.RegistrySet("Advanced", advanced); for (int i = 4; i < grid.RowDefinitions.Count; i++) { grid.RowDefinitions[i].MaxHeight = advanced ? Double.PositiveInfinity : 0; } foreach (UIElement element in grid.Children) { if (Grid.GetRow(element) >= 4) { element.IsEnabled = advanced; } } }; WPF.Add(m_menu.Items, "Simple / Advanced").Click += (sender, e) => actionSimpleAdvanced(true); actionSimpleAdvanced(false); ContextMenu menu = new ContextMenu(); if (File.Exists(GetCurrency() + "_password_private_key")) { foreach (string line in File.ReadLines(GetCurrency() + "_password_private_key")) { WPF.Add(menu.Items, new string('*', line.Length)).Click += (sender, e) => m_passwordBoxPP.Password = line; } } if (menu.Items.Count != 0) { menu.Items.Add(new Separator()); } WPF.Add(menu.Items, "Paste").Click += (sender, e) => m_passwordBoxPP.Paste(); WPF.Add(menu.Items, "Clear").Click += (sender, e) => m_passwordBoxPP.Clear(); m_passwordBoxPP.ContextMenu = menu; m_passwordBoxPP.PasswordChanged += (sender, e) => UpdateTransaction(true); m_passwordBoxPP.Focus(); for (int i = 0; i < 1000; i++) { m_comboBoxNonce.Items.Add(i); } foreach (var entry in ConfigFile.ReadAddressInfo(GetCurrency() + "_to")) { m_comboBoxTo.Items.Add(("0x" + entry.Item1 + " " + entry.Item2).Trim()); } foreach (string line in ConfigFile.ReadTrimmedLines(GetCurrency() + "_value")) { m_comboBoxValue.Items.Add(line); } m_buttonClear.Click += (sender, e) => InitOrDataClear(); m_buttonBin.Click += (sender, e) => InitOrDataLoad(true); m_buttonHex.Click += (sender, e) => InitOrDataLoad(false); foreach (string line in ConfigFile.ReadTrimmedLines(GetCurrency() + "_gas_price")) { m_comboBoxGasPrice.Items.Add(line); } m_comboBoxGasPrice.SelectedIndex = 0; foreach (string line in ConfigFile.ReadTrimmedLines(GetCurrency() + "_gas_limit")) { m_comboBoxGasLimit.Items.Add(line); } m_comboBoxGasLimit.SelectedIndex = 0; Loaded += (_0, _1) => { foreach (ComboBox comboBox in new ComboBox[] { m_comboBoxNonce, m_comboBoxTo, m_comboBoxValue, m_comboBoxGasPrice, m_comboBoxGasLimit }) { ((TextBox)comboBox.Template.FindName("PART_EditableTextBox", comboBox)).TextChanged += (sender, e) => UpdateTransaction(false); } }; }