qdrow

Untitled

Nov 7th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.51 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 TextBox focusedElement;
  8. public MainWindow()
  9. {
  10. InitializeComponent();
  11.  
  12. StackPanel stkPCash;
  13. int indexLb = 0;
  14. int colIndexStkPnl = 0;
  15. for (int stpnl = 0; stpnl < 16; stpnl++)
  16. {
  17. BinPanel.Children.Add(new StackPanel
  18. {
  19. Orientation = Orientation.Horizontal,
  20. Margin = new Thickness(10, 0, 10, 0)
  21. });
  22. }
  23. foreach (object anyContener in BinPanel.Children)
  24. {
  25. if (anyContener is StackPanel)
  26. {
  27. stkPCash = (StackPanel)anyContener;
  28. if (indexLb < 32)
  29. {
  30. Grid.SetRow(stkPCash, 0);
  31. Grid.SetColumn(stkPCash, colIndexStkPnl);
  32. colIndexStkPnl++;
  33. }
  34. else if (indexLb > 31)
  35. {
  36. Grid.SetRow(stkPCash, 2);
  37. Grid.SetColumn(stkPCash, colIndexStkPnl % 8);
  38. colIndexStkPnl++;
  39. }
  40.  
  41. for (int i = 0; i < 4; i++)
  42. {
  43. stkPCash.Children.Add(new Label
  44. {
  45. Name = "Bin" + indexLb.ToString(),
  46. Content = 0,
  47. Padding = new Thickness(1)
  48. });
  49. indexLb++;
  50. }
  51. }
  52. }
  53. }
  54.  
  55. private void BinaryPanel_MouseDown(object sender, MouseButtonEventArgs e)
  56. {
  57. if (e.Source is Label)
  58. {
  59. Label ChildElem = (Label)e.Source;
  60. bool PinVal = Convert.ToBoolean(Convert.ToInt16(ChildElem.Content));
  61. ChildElem.Content = Convert.ToInt16(!PinVal);
  62. int index = Convert.ToInt32(ChildElem.Name.Substring(3));
  63. BinValueArray[index] = Convert.ToInt32(ChildElem.Content);
  64. string textes = string.Concat<int>(BinValueArray);
  65. Tablo.Text = Convert.ToString(Convert.ToInt64(textes, 2));
  66. }
  67. }
  68.  
  69. private void Numbers(object sender, RoutedEventArgs e)
  70. {
  71. Button Any_but = (Button)sender;
  72. switch (Any_but.Content)
  73. {
  74. case "0":
  75. if (Tablo.Text != "0")
  76. {
  77. Tablo.Text += "0";
  78. }
  79. break;
  80. default:
  81. if (Tablo.Text == "0")
  82. {
  83. Tablo.Text = Convert.ToString(Any_but.Content);
  84. }
  85. else
  86. {
  87. Tablo.Text += Any_but.Content;
  88. }
  89. break;
  90. }
  91. }
  92. private void Comma_Click(object sender, RoutedEventArgs e)
  93. {
  94. if (!Tablo.Text.Contains(","))
  95. {
  96. Tablo.Text += ",";
  97. }
  98. }
  99. private void Cancel_mode(object sender, RoutedEventArgs e)
  100. {
  101. Button cancel = (Button)sender;
  102. switch (cancel.Content)
  103. {
  104. case "CE":
  105. Tablo.Text = "0";
  106. break;
  107. case "C":
  108. Tablo.Text = "0";
  109. Func_calc.Text = "";
  110. break;
  111. default:
  112. if (Tablo.Text.Length != 1)
  113. {
  114. Tablo.Text = Tablo.Text.Substring(0, Tablo.Text.Length - 1);
  115. }
  116. else
  117. {
  118. Tablo.Text = "0";
  119. }
  120. break;
  121. }
  122. }
  123.  
  124. private void MenuItem_Click(object sender, RoutedEventArgs e)
  125. {
  126. usles.IsChecked = false;
  127. stat.IsChecked = false;
  128. progr.IsChecked = false;
  129. ingen.IsChecked = false;
  130. MenuItem test = (MenuItem)sender;
  131. test.IsChecked = true;
  132. }
  133.  
  134. private void Unchecked(object sender, RoutedEventArgs e)
  135. {
  136. MenuItem test = (MenuItem)sender;
  137. switch (test.Name)
  138. {
  139. case "usles":
  140. break;
  141. case "ingen":
  142. Application.Current.MainWindow.Width = Application.Current.MainWindow.Width / 2;
  143. EnginPanel.Visibility = Visibility.Collapsed;
  144. leftCol.Width = GridLength.Auto;
  145. break;
  146. case "progr":
  147. Application.Current.MainWindow.Width = Application.Current.MainWindow.Width / 2;
  148. Application.Current.MainWindow.Height = Application.Current.MainWindow.Height - BinPanel.Height;
  149. BinPanel.Visibility = Visibility.Collapsed;
  150. ProgrPanel.Visibility = Visibility.Collapsed;
  151. leftCol.Width = GridLength.Auto;
  152. break;
  153. case "stat":
  154. break;
  155. }
  156. }
  157. private void Cheched(object sender, RoutedEventArgs e)
  158. {
  159. MenuItem test = (MenuItem)sender;
  160. switch (test.Name)
  161. {
  162. case "usles":
  163. break;
  164. case "ingen":
  165. Application.Current.MainWindow.Width = Application.Current.MainWindow.Width * 2;
  166. EnginPanel.Visibility = Visibility.Visible;
  167. leftCol.Width = new GridLength(1, GridUnitType.Star);
  168. break;
  169. case "progr":
  170. Application.Current.MainWindow.Width = Application.Current.MainWindow.Width * 2;
  171. Application.Current.MainWindow.Height = Application.Current.MainWindow.Height + BinPanel.Height;
  172. BinPanel.Visibility = Visibility.Visible;
  173. ProgrPanel.Visibility = Visibility.Visible;
  174. leftCol.Width = new GridLength(1, GridUnitType.Star);
  175. break;
  176. case "stat":
  177. break;
  178. }
  179. }
  180.  
  181. private void Window_TextInput(object sender, TextCompositionEventArgs e)
  182. {
  183. char KeyPress;
  184. Char.TryParse(e.Text, out KeyPress);
  185. switch (Convert.ToInt32(KeyPress))
  186. {
  187. case 8:
  188. Cancel_mode(BackSP, new RoutedEventArgs());
  189. break;
  190. default:
  191. if (Convert.ToInt32(KeyPress) <= 57 && Convert.ToInt32(KeyPress) >= 48)
  192. {
  193. if (Tablo.Text != "0")
  194. {
  195. Tablo.Text += KeyPress;
  196. }
  197. else
  198. {
  199. Tablo.Text = Convert.ToString(KeyPress);
  200. }
  201. }
  202. break;
  203. }
  204. }
  205.  
  206.  
  207.  
  208. private void Tablo_TextChanged(object sender, TextChangedEventArgs e)
  209. {
  210. string TabValue = Convert.ToString(Convert.ToInt64(Tablo.Text), 2);
  211. int i = TabValue.Length;
  212. for (int index = 0; index < BinValueArray.Length; index++)
  213. {
  214. BinValueArray[index] = 0;
  215. }
  216. if (TabValue.Length >= 1)
  217. {
  218. do
  219. {
  220. BinValueArray[(BinValueArray.Length) - i] =
  221. Convert.ToInt16(Convert.ToString(TabValue[TabValue.Length - i]));
  222. i--;
  223. }
  224. while (i != 0);
  225. }
  226. int j = 0;
  227. if (BinPanel != null)
  228. {
  229. foreach (object anyStkPnl in BinPanel.Children)
  230. {
  231. if (anyStkPnl is StackPanel)
  232. {
  233. foreach (object anyLb in (anyStkPnl as StackPanel).Children)
  234. {
  235. if (anyLb is Label)
  236. {
  237. Label obj = (Label)anyLb;
  238. obj.Content = BinValueArray[j];
  239. j++;
  240. }
  241. }
  242. }
  243. }
  244. }
  245. }
  246.  
  247.  
  248. private void Button_Click_2(object sender, RoutedEventArgs e)
  249. {
  250. if (Journal.Visibility == Visibility.Visible)
  251. {
  252. Journal.Children.Add(new TextBox {IsReadOnly = false, Text = "some func",
  253. BorderBrush = new SolidColorBrush(Colors.White),
  254. HorizontalContentAlignment=HorizontalAlignment.Right});
  255. if (Journal.Children.Count == 1)
  256. {
  257. focusedElement = (TextBox)Journal.Children[0];
  258. }
  259. }
  260. }
  261.  
  262. private void Button_Click(object sender, RoutedEventArgs e)
  263. {
  264. if (Journal.Children.Count > 1)
  265. {
  266. focusedElement.MoveFocus(new TraversalRequest(FocusNavigationDirection.Up));
  267. foreach (object i in Journal.Children)
  268. {
  269. if ((i as TextBox).IsFocused == true)
  270. {
  271. focusedElement = i as TextBox;
  272. }
  273. }
  274. }
  275.  
  276. }
  277.  
  278. private void Button_Click_1(object sender, RoutedEventArgs e)
  279. {
  280. if (Journal.Children.Count > 1)
  281. {
  282. focusedElement.MoveFocus(new TraversalRequest(FocusNavigationDirection.Down));
  283. foreach (object i in Journal.Children)
  284. {
  285. if ((i as TextBox).IsFocused == true)
  286. {
  287. focusedElement = i as TextBox;
  288. }
  289. }
  290. }
  291. }
  292. }
Advertisement
Add Comment
Please, Sign In to add comment