Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Логика взаимодействия для MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public int[] BinValueArray = new int[64];
- public MainWindow()
- {
- InitializeComponent();
- StackPanel stkPCash;
- int indexLb = 0;
- int colIndexStkPnl = 0;
- for (int stpnl = 0; stpnl < 16; stpnl++)
- {
- BinPanel.Children.Add(new StackPanel { Orientation =Orientation.Horizontal,
- Margin = new Thickness(10, 0, 10,0)});
- }
- foreach (object anyContener in BinPanel.Children)
- {
- if (anyContener is StackPanel)
- {
- stkPCash = (StackPanel)anyContener;
- if (indexLb < 32)
- {
- Grid.SetRow(stkPCash, 0);
- Grid.SetColumn(stkPCash, colIndexStkPnl);
- colIndexStkPnl++;
- }
- else if (indexLb > 31)
- {
- Grid.SetRow(stkPCash, 2);
- Grid.SetColumn(stkPCash, colIndexStkPnl % 8);
- colIndexStkPnl++;
- }
- for (int i = 0; i < 4; i++)
- {
- stkPCash.Children.Add(new Label {Name = "Bin"+indexLb.ToString(),
- Content = 0, Padding = new Thickness(1)});
- indexLb++;
- }
- }
- }
- }
- private void BinaryPanel_MouseDown(object sender, MouseButtonEventArgs e)
- {
- if (e.Source is Label)
- {
- Label ChildElem = (Label)e.Source;
- bool PinVal = Convert.ToBoolean(Convert.ToInt16(ChildElem.Content));
- ChildElem.Content = Convert.ToInt16(!PinVal);
- int index = Convert.ToInt32(ChildElem.Name.Substring(3));
- BinValueArray[index] = Convert.ToInt32(ChildElem.Content);
- string textes = string.Concat<int>(BinValueArray);
- Tablo.Text = Convert.ToString(Convert.ToInt64(textes, 2));
- }
- }
- private void Numbers(object sender, RoutedEventArgs e)
- {
- Button Any_but = (Button)sender;
- switch (Any_but.Content)
- {
- case "0":
- if (Tablo.Text != "0")
- {
- Tablo.Text += "0";
- }
- break;
- default:
- if (Tablo.Text == "0")
- {
- Tablo.Text = Convert.ToString(Any_but.Content);
- }
- else
- {
- Tablo.Text += Any_but.Content;
- }
- break;
- }
- }
- private void Comma_Click(object sender, RoutedEventArgs e)
- {
- if (!Tablo.Text.Contains(","))
- {
- Tablo.Text += ",";
- }
- }
- private void Cancel_mode(object sender, RoutedEventArgs e)
- {
- Button cancel = (Button)sender;
- switch (cancel.Content)
- {
- case "CE":
- Tablo.Text = "0";
- break;
- case "C":
- Tablo.Text = "0";
- Func_calc.Text = "";
- break;
- default:
- if (Tablo.Text.Length != 1)
- {
- Tablo.Text = Tablo.Text.Substring(0, Tablo.Text.Length - 1);
- }
- else
- {
- Tablo.Text = "0";
- }
- break;
- }
- }
- private void MenuItem_Click(object sender, RoutedEventArgs e)
- {
- usles.IsChecked = false;
- stat.IsChecked = false;
- progr.IsChecked = false;
- ingen.IsChecked = false;
- MenuItem test = (MenuItem)sender;
- test.IsChecked = true;
- }
- private void Unchecked(object sender, RoutedEventArgs e)
- {
- MenuItem test = (MenuItem)sender;
- switch (test.Name)
- {
- case "usles":
- break;
- case "ingen":
- Application.Current.MainWindow.Width = Application.Current.MainWindow.Width / 2;
- EnginPanel.Visibility = Visibility.Collapsed;
- leftCol.Width = GridLength.Auto;
- break;
- case "progr":
- Application.Current.MainWindow.Width = Application.Current.MainWindow.Width / 2;
- Application.Current.MainWindow.Height = Application.Current.MainWindow.Height - BinPanel.Height;
- BinPanel.Visibility = Visibility.Collapsed;
- ProgrPanel.Visibility = Visibility.Collapsed;
- leftCol.Width = GridLength.Auto;
- break;
- case "stat":
- break;
- }
- }
- private void Cheched(object sender, RoutedEventArgs e)
- {
- MenuItem test = (MenuItem)sender;
- switch (test.Name)
- {
- case "usles":
- break;
- case "ingen":
- Application.Current.MainWindow.Width = Application.Current.MainWindow.Width * 2;
- EnginPanel.Visibility = Visibility.Visible;
- leftCol.Width = new GridLength(1, GridUnitType.Star);
- break;
- case "progr":
- Application.Current.MainWindow.Width = Application.Current.MainWindow.Width * 2;
- Application.Current.MainWindow.Height = Application.Current.MainWindow.Height + BinPanel.Height;
- BinPanel.Visibility = Visibility.Visible;
- ProgrPanel.Visibility = Visibility.Visible;
- leftCol.Width = new GridLength(1, GridUnitType.Star);
- break;
- case "stat":
- break;
- }
- }
- private void Window_TextInput(object sender, TextCompositionEventArgs e)
- {
- char KeyPress;
- Char.TryParse(e.Text, out KeyPress);
- switch (Convert.ToInt32(KeyPress))
- {
- case 8:
- Cancel_mode(BackSP, new RoutedEventArgs());
- break;
- default:
- if (Convert.ToInt32(KeyPress) <= 57 && Convert.ToInt32(KeyPress) >= 48)
- {
- if (Tablo.Text != "0")
- {
- Tablo.Text += KeyPress;
- }
- else
- {
- Tablo.Text = Convert.ToString(KeyPress);
- }
- }
- break;
- }
- }
- private void Tablo_TextChanged(object sender, TextChangedEventArgs e)
- {
- string TabValue = Convert.ToString(Convert.ToInt64(Tablo.Text), 2);
- int i = TabValue.Length;
- for (int index = 0; index < BinValueArray.Length; index++)
- {
- BinValueArray[index] = 0;
- }
- if (TabValue.Length >= 1)
- {
- do
- {
- BinValueArray[(BinValueArray.Length) - i] =
- Convert.ToInt16(Convert.ToString(TabValue[TabValue.Length - i]));
- i--;
- }
- while (i != 0);
- }
- int j = 0;
- if (BinPanel != null)
- {
- foreach (object anyStkPnl in BinPanel.Children)
- {
- if (anyStkPnl is StackPanel)
- {
- foreach (object anyLb in (anyStkPnl as StackPanel).Children)
- {
- if (anyLb is Label)
- {
- Label obj = (Label)anyLb;
- obj.Content = BinValueArray[j];
- j++;
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment