qdrow

Untitled

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