qdrow

Untitled

Oct 29th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.28 KB | None | 0 0
  1. /// <summary>
  2. /// Логика взаимодействия для MainWindow.xaml
  3. /// </summary>
  4. public partial class MainWindow : Window
  5. {
  6. public int[] BinaryValue = new int[64];
  7. public MainWindow()
  8. {
  9. InitializeComponent();
  10. int indexLb = 0;
  11. int colIndexStkPnl = 0;
  12. for (int stpnl = 0; stpnl < 16; stpnl++)
  13. {
  14. BinPanel.Children.Add(new StackPanel {Orientation = Orientation.Horizontal, Margin = new Thickness(10,0,10,0)});
  15. }
  16. foreach (object anyContener in BinPanel.Children)
  17. {
  18. if(anyContener is StackPanel)
  19. {
  20. StackPanel stkPanel = (StackPanel)anyContener;
  21. if (indexLb < 32)
  22. {
  23. Grid.SetRow(stkPanel, 0);
  24. Grid.SetColumn(stkPanel, colIndexStkPnl);
  25. colIndexStkPnl++;
  26. }
  27. else if(indexLb > 31)
  28. {
  29. Grid.SetRow(stkPanel, 2);
  30. Grid.SetColumn(stkPanel, colIndexStkPnl % 8);
  31. colIndexStkPnl++;
  32. }
  33.  
  34. for(int i = 0; i<4; i++)
  35. {
  36. stkPanel.Children.Add(new Label { Name = "Bin" + indexLb.ToString(), Content = 0, Padding = new Thickness(1) });
  37. indexLb++;
  38. }
  39. }
  40. }
  41. }
  42.  
  43. private void BinaryPanel_MouseDown(object sender, MouseButtonEventArgs e)
  44. {
  45. Label ChildElem = (Label)e.Source;
  46. bool PinVal = Convert.ToBoolean(Convert.ToInt16(ChildElem.Content));
  47. ChildElem.Content = Convert.ToInt16(!PinVal);
  48. int indexChild = Convert.ToInt32(ChildElem.Name.Substring(3));
  49. BinaryValue[indexChild] = Convert.ToInt16(ChildElem.Content);
  50. string FullBinVal = string.Concat<int>(BinaryValue);
  51. Tablo.Text = Convert.ToString(Convert.ToInt64(FullBinVal, 2));
  52. }
  53.  
  54. private void Numbers(object sender, RoutedEventArgs e)
  55. {
  56. Button Any_but = (Button)sender;
  57. switch (Any_but.Content)
  58. {
  59. case "0":
  60. if (Tablo.Text != "0")
  61. {
  62. Tablo.Text += "0";
  63. }
  64. break;
  65. default:
  66. if (Tablo.Text == "0")
  67. {
  68. Tablo.Text = Convert.ToString(Any_but.Content);
  69. }
  70. else
  71. {
  72. Tablo.Text += Any_but.Content;
  73. }
  74. break;
  75. }
  76. }
  77. private void Comma_Click(object sender, RoutedEventArgs e)
  78. {
  79. if (!Tablo.Text.Contains(","))
  80. {
  81. Tablo.Text += ",";
  82. }
  83. }
  84. private void Cancel_mode(object sender, RoutedEventArgs e)
  85. {
  86. Button cancel = (Button)sender;
  87. switch (cancel.Content)
  88. {
  89. case "CE":
  90. Tablo.Text = "0";
  91. break;
  92. case "C":
  93. Tablo.Text = "0";
  94. Func_calc.Text = "";
  95. break;
  96. default:
  97. if (Tablo.Text.Length != 1)
  98. {
  99. Tablo.Text = Tablo.Text.Substring(0, Tablo.Text.Length - 1);
  100. }
  101. else
  102. {
  103. Tablo.Text = "0";
  104. }
  105. break;
  106. }
  107. }
  108.  
  109. private void MenuItem_Click(object sender, RoutedEventArgs e)
  110. {
  111. usles.IsChecked = false;
  112. stat.IsChecked = false;
  113. progr.IsChecked = false;
  114. ingen.IsChecked = false;
  115. MenuItem test = (MenuItem)sender;
  116. test.IsChecked = true;
  117. }
  118.  
  119. private void Unchecked(object sender, RoutedEventArgs e)
  120. {
  121. MenuItem test = (MenuItem)sender;
  122. switch (test.Name)
  123. {
  124. case "usles":
  125. break;
  126. case "ingen":
  127. Application.Current.MainWindow.Width = Application.Current.MainWindow.Width / 2;
  128. EnginPanel.Visibility = Visibility.Collapsed;
  129. leftCol.Width = GridLength.Auto;
  130. break;
  131. case "progr":
  132. Application.Current.MainWindow.Width = Application.Current.MainWindow.Width / 2;
  133. Application.Current.MainWindow.Height = Application.Current.MainWindow.Height - BinPanel.Height;
  134. BinPanel.Visibility = Visibility.Collapsed;
  135. ProgrPanel.Visibility = Visibility.Collapsed;
  136. leftCol.Width = GridLength.Auto;
  137. break;
  138. case "stat":
  139. break;
  140. }
  141. }
  142. private void Cheched(object sender, RoutedEventArgs e)
  143. {
  144. MenuItem test = (MenuItem)sender;
  145. switch (test.Name)
  146. {
  147. case "usles":
  148. break;
  149. case "ingen":
  150. Application.Current.MainWindow.Width = Application.Current.MainWindow.Width * 2;
  151. EnginPanel.Visibility = Visibility.Visible;
  152. leftCol.Width = new GridLength(1, GridUnitType.Star);
  153. break;
  154. case "progr":
  155. Application.Current.MainWindow.Width = Application.Current.MainWindow.Width * 2;
  156. Application.Current.MainWindow.Height = Application.Current.MainWindow.Height + BinPanel.Height;
  157. BinPanel.Visibility = Visibility.Visible;
  158. ProgrPanel.Visibility = Visibility.Visible;
  159. leftCol.Width = new GridLength(1, GridUnitType.Star);
  160. break;
  161. case "stat":
  162. break;
  163. }
  164. }
  165.  
  166. private void Window_TextInput(object sender, TextCompositionEventArgs e)
  167. {
  168. char KeyPress;
  169. Char.TryParse(e.Text, out KeyPress);
  170. switch (Convert.ToInt32(KeyPress))
  171. {
  172. case 8:
  173. Cancel_mode(BackSP, new RoutedEventArgs());
  174. break;
  175. default:
  176. if (Convert.ToInt32(KeyPress) <= 57 && Convert.ToInt32(KeyPress) >= 48)
  177. {
  178. if (Tablo.Text != "0")
  179. {
  180. Tablo.Text += KeyPress;
  181. }
  182. else
  183. {
  184. Tablo.Text = Convert.ToString(KeyPress);
  185. }
  186. }
  187. break;
  188. }
  189. }
  190.  
  191. private void Tablo_TextChanged(object sender, TextChangedEventArgs e)
  192. {
  193. string binValue = Convert.ToString(Convert.ToInt64(Tablo.Text), 2);
  194. }
  195. }
Advertisement
Add Comment
Please, Sign In to add comment