qdrow

Untitled

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