Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.43 KB | None | 0 0
  1. <Window x:Class="WpfApp1.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6. xmlns:local="clr-namespace:WpfApp1"
  7. mc:Ignorable="d"
  8. Title="Rechner" Height="415.254" Width="525">
  9. <Grid>
  10. <Button x:Name="btSeven" Content="7" HorizontalAlignment="Left" Margin="42,92,0,0" VerticalAlignment="Top" Width="84" Height="45" FontSize="18" Click="btSeven_Click"/>
  11. <Button x:Name="btEight" Content="8" HorizontalAlignment="Left" Height="45" Margin="131,92,0,0" VerticalAlignment="Top" Width="84" FontSize="18" Click="btEight_Click"/>
  12. <Button x:Name="btFour" Content="4" HorizontalAlignment="Left" Height="45" Margin="42,142,0,0" VerticalAlignment="Top" Width="84" FontSize="18" Click="btFour_Click"/>
  13. <Button x:Name="btTwo" Content="2" HorizontalAlignment="Left" Height="45" Margin="131,192,0,0" VerticalAlignment="Top" Width="84" FontSize="18" Click="btTwo_Click"/>
  14. <Button x:Name="btOne" Content="1" HorizontalAlignment="Left" Height="45" Margin="42,192,0,0" VerticalAlignment="Top" Width="84" FontSize="18" Click="btOne_Click"/>
  15. <Button x:Name="btFive" Content="5" HorizontalAlignment="Left" Height="45" Margin="131,142,0,0" VerticalAlignment="Top" Width="84" FontSize="18" Click="btFive_Click"/>
  16. <Button x:Name="btNine" Content="9" HorizontalAlignment="Left" Height="45" Margin="220,92,0,0" VerticalAlignment="Top" Width="84" FontSize="18" Click="btNine_Click"/>
  17. <Button x:Name="btClear" Content="C" HorizontalAlignment="Left" Height="45" Margin="220,242,0,0" VerticalAlignment="Top" Width="84" FontSize="18" Click="btClear_Click"/>
  18. <Button x:Name="btSix" Content="6" HorizontalAlignment="Left" Height="45" Margin="220,142,0,0" VerticalAlignment="Top" Width="84" FontSize="18" Click="btSix_Click"/>
  19. <Button x:Name="btEquals" Content="=" HorizontalAlignment="Left" Height="45" Margin="42,310,0,0" VerticalAlignment="Top" Width="412" FontSize="22" Click="btEquals_Click"/>
  20. <Button x:Name="btDivision" Content="/" HorizontalAlignment="Left" Height="45" Margin="370,92,0,0" VerticalAlignment="Top" Width="84" FontSize="18" Click="btDivision_Click"/>
  21. <Button x:Name="btMultiplikation" Content="*" HorizontalAlignment="Left" Height="45" Margin="370,142,0,0" VerticalAlignment="Top" Width="84" FontSize="18" Click="btMultiplikation_Click"/>
  22. <Button x:Name="btPlus" Content="+" HorizontalAlignment="Left" Height="45" Margin="370,192,0,0" VerticalAlignment="Top" Width="84" FontSize="18" Click="btPlus_Click"/>
  23. <Button x:Name="btZero" Content="0" HorizontalAlignment="Left" Height="45" Margin="42,242,0,0" VerticalAlignment="Top" Width="84" FontSize="18" Click="btZero_Click"/>
  24. <Button x:Name="btComma" Content="." HorizontalAlignment="Left" Height="45" Margin="131,242,0,0" VerticalAlignment="Top" Width="84" FontSize="18" Click="btComma_Click"/>
  25. <Button x:Name="btThree" Content="3" HorizontalAlignment="Left" Height="45" Margin="220,192,0,0" VerticalAlignment="Top" Width="84" FontSize="18" Click="btThree_Click"/>
  26. <Button x:Name="btMinus" Content="-" HorizontalAlignment="Left" Height="45" Margin="370,242,0,0" VerticalAlignment="Top" Width="84" FontSize="18" Click="btMinus_Click"/>
  27. <Label x:Name="lbOut" Content="" HorizontalAlignment="Left" Height="60" Margin="42,16,0,0" VerticalAlignment="Top" Width="412" FontSize="36" RenderTransformOrigin="0.502,0.441"/>
  28.  
  29. </Grid>
  30. </Window>
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. using System;
  82. using System.Collections.Generic;
  83. using System.Linq;
  84. using System.Text;
  85. using System.Threading.Tasks;
  86. using System.Windows;
  87. using System.Windows.Controls;
  88. using System.Windows.Data;
  89. using System.Windows.Documents;
  90. using System.Windows.Input;
  91. using System.Windows.Media;
  92. using System.Windows.Media.Imaging;
  93. using System.Windows.Navigation;
  94. using System.Windows.Shapes;
  95.  
  96. namespace WpfApp1
  97. {
  98. /// <summary>
  99. /// Interaktionslogik für MainWindow.xaml
  100. /// </summary>
  101. public partial class MainWindow : Window
  102. {
  103. string input = string.Empty;
  104. string operand1 = string.Empty;
  105. string operand2 = string.Empty;
  106. char Operation;
  107. double result = 0.0;
  108.  
  109. public MainWindow()
  110. {
  111. InitializeComponent();
  112. }
  113.  
  114. private void Calculate()
  115. {
  116. lbOut.Content = "";
  117. operand2 = input;
  118. double num1, num2;
  119. double.TryParse(operand1, out num1);
  120. double.TryParse(operand2, out num2);
  121.  
  122. if (Operation == '+')
  123. {
  124. result = num1 + num2;
  125. lbOut.Content = result.ToString();
  126. }
  127. else if (Operation == '-')
  128. {
  129. result = num1 - num2;
  130. lbOut.Content = result.ToString();
  131. }
  132. else if (Operation == '*')
  133. {
  134. result = num1 * num2;
  135. lbOut.Content = result.ToString();
  136. }
  137. else if (Operation == '/')
  138. {
  139. if (num2 != 0)
  140. {
  141. result = num1 / num2;
  142. lbOut.Content = result.ToString();
  143. }
  144. else
  145. {
  146. lbOut.Content = "DIV/Zero!";
  147. }
  148. }
  149.  
  150. input = string.Empty;
  151. operand1 = string.Empty;
  152.  
  153. }
  154.  
  155. private void btSeven_Click(object sender, RoutedEventArgs e)
  156. {
  157. input += "7";
  158. if (operand1 == string.Empty)
  159. {
  160. lbOut.Content = input;
  161. }
  162. else
  163. {
  164. lbOut.Content += "7";
  165. }
  166. }
  167.  
  168. private void btEight_Click(object sender, RoutedEventArgs e)
  169. {
  170. input += "8";
  171. if (operand1 == string.Empty)
  172. {
  173. lbOut.Content = input;
  174. }
  175. else
  176. {
  177. lbOut.Content += "8";
  178. }
  179. }
  180.  
  181. private void btNine_Click(object sender, RoutedEventArgs e)
  182. {
  183. input += "9";
  184. if (operand1 == string.Empty)
  185. {
  186. lbOut.Content = input;
  187. }
  188. else
  189. {
  190. lbOut.Content += "9";
  191. }
  192. }
  193.  
  194. private void btDivision_Click(object sender, RoutedEventArgs e)
  195. {
  196. if (operand1 == string.Empty)
  197. {
  198. if (lbOut.Content.ToString() != "DIV/Zero!")
  199. {
  200. if (input == string.Empty)
  201. {
  202. operand1 = result.ToString();
  203. }
  204. else
  205. {
  206. operand1 = input;
  207. }
  208. }
  209. else
  210. {
  211. lbOut.Content = "";
  212. operand1 = string.Empty;
  213. }
  214. Operation = '/';
  215. result = 0.0;
  216. input = string.Empty;
  217. }
  218. else
  219. {
  220. Calculate();
  221. Operation = '/';
  222. operand1 = result.ToString();
  223. result = 0.0;
  224. }
  225. lbOut.Content += "/";
  226. }
  227.  
  228. private void btFour_Click(object sender, RoutedEventArgs e)
  229. {
  230. input += "4";
  231. if (operand1 == string.Empty)
  232. {
  233. lbOut.Content = input;
  234. }
  235. else
  236. {
  237. lbOut.Content += "4";
  238. }
  239. }
  240.  
  241. private void btFive_Click(object sender, RoutedEventArgs e)
  242. {
  243. input += "5";
  244. if (operand1 == string.Empty)
  245. {
  246. lbOut.Content = input;
  247. }
  248. else
  249. {
  250. lbOut.Content += "5";
  251. }
  252. }
  253.  
  254. private void btSix_Click(object sender, RoutedEventArgs e)
  255. {
  256. input += "6";
  257. if (operand1 == string.Empty)
  258. {
  259. lbOut.Content = input;
  260. }
  261. else
  262. {
  263. lbOut.Content += "6";
  264. }
  265. }
  266.  
  267. private void btMultiplikation_Click(object sender, RoutedEventArgs e)
  268. {
  269. if (operand1 == string.Empty)
  270. {
  271. if (lbOut.Content.ToString() != "DIV/Zero!")
  272. {
  273. if (input == string.Empty)
  274. {
  275. operand1 = result.ToString();
  276. }
  277. else
  278. {
  279. operand1 = input;
  280. }
  281. }
  282. else
  283. {
  284. lbOut.Content = "";
  285. operand1 = string.Empty;
  286. }
  287. Operation = '*';
  288. result = 0.0;
  289. input = string.Empty;
  290. }
  291. else
  292. {
  293. Calculate();
  294. Operation = '*';
  295. operand1 = result.ToString();
  296. result = 0.0;
  297. }
  298. lbOut.Content += "*";
  299. }
  300.  
  301. private void btOne_Click(object sender, RoutedEventArgs e)
  302. {
  303. input += "1";
  304. if (operand1 == string.Empty)
  305. {
  306. lbOut.Content = input;
  307. }
  308. else
  309. {
  310. lbOut.Content += "1";
  311. }
  312. }
  313.  
  314. private void btTwo_Click(object sender, RoutedEventArgs e)
  315. {
  316. input += "2";
  317. if (operand1 == string.Empty)
  318. {
  319. lbOut.Content = input;
  320. }
  321. else
  322. {
  323. lbOut.Content += "2";
  324. }
  325. }
  326.  
  327. private void btThree_Click(object sender, RoutedEventArgs e)
  328. {
  329. input += "3";
  330. if (operand1 == string.Empty)
  331. {
  332. lbOut.Content = input;
  333. }
  334. else
  335. {
  336. lbOut.Content += "3";
  337. }
  338. }
  339.  
  340. private void btPlus_Click(object sender, RoutedEventArgs e)
  341. {
  342. if (operand1 == string.Empty)
  343. {
  344. if (lbOut.Content.ToString() != "DIV/Zero!")
  345. {
  346. if (input == string.Empty)
  347. {
  348. operand1 = result.ToString();
  349. }
  350. else
  351. {
  352. operand1 = input;
  353. }
  354. }
  355. else
  356. {
  357. lbOut.Content = "";
  358. operand1 = string.Empty;
  359. }
  360. Operation = '+';
  361. result = 0.0;
  362. input = string.Empty;
  363. }
  364. else
  365. {
  366. Calculate();
  367. Operation = '+';
  368. operand1 = result.ToString();
  369. result = 0.0;
  370. }
  371. lbOut.Content += "+";
  372. }
  373.  
  374. private void btZero_Click(object sender, RoutedEventArgs e)
  375. {
  376. input += "0";
  377. if (operand1 == string.Empty)
  378. {
  379. lbOut.Content = input;
  380. }
  381. else
  382. {
  383. lbOut.Content += "0";
  384. }
  385. }
  386.  
  387. private void btComma_Click(object sender, RoutedEventArgs e)
  388. {
  389. lbOut.Content = "";
  390. if (input == string.Empty)
  391. {
  392. input += "0.";
  393. }
  394. else
  395. {
  396. input += ".";
  397. }
  398. lbOut.Content = input;
  399. }
  400.  
  401. private void btClear_Click(object sender, RoutedEventArgs e)
  402. {
  403. lbOut.Content = "";
  404. input = string.Empty;
  405. operand1 = string.Empty;
  406. operand2 = string.Empty;
  407. }
  408.  
  409. private void btMinus_Click(object sender, RoutedEventArgs e)
  410. {
  411. if (operand1 == string.Empty)
  412. {
  413. if (lbOut.Content.ToString() != "DIV/Zero!")
  414. {
  415. if (input == string.Empty)
  416. {
  417. operand1 = result.ToString();
  418. }
  419. else
  420. {
  421. operand1 = input;
  422. }
  423. }
  424. else
  425. {
  426. lbOut.Content = "";
  427. operand1 = string.Empty;
  428. }
  429. Operation = '-';
  430. result = 0.0;
  431. input = string.Empty;
  432. }
  433. else
  434. {
  435. Calculate();
  436. Operation = '-';
  437. operand1 = result.ToString();
  438. result = 0.0;
  439. }
  440. lbOut.Content += "-";
  441. }
  442.  
  443. private void btEquals_Click(object sender, RoutedEventArgs e)
  444. {
  445. Calculate();
  446. }
  447. }
  448. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement