qdrow

Untitled

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