Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.75 KB | None | 0 0
  1. #pragma once
  2.  
  3.  
  4. namespace Calc {
  5.  
  6. using namespace System;
  7. using namespace System::ComponentModel;
  8. using namespace System::Collections;
  9. using namespace System::Windows::Forms;
  10. using namespace System::Data;
  11. using namespace System::Drawing;
  12.  
  13. /// <summary>
  14. /// Summary for Form1
  15. ///
  16. /// WARNING: If you change the name of this class, you will need to change the
  17. /// 'Resource File Name' property for the managed resource compiler tool
  18. /// associated with all .resx files this class depends on. Otherwise,
  19. /// the designers will not be able to interact properly with localized
  20. /// resources associated with this form.
  21. /// </summary>
  22. public ref class Form1 : public System::Windows::Forms::Form
  23. {
  24. public:
  25. Form1(void)
  26. {
  27. InitializeComponent();
  28. //
  29. //TODO: Add the constructor code here
  30. //
  31. }
  32.  
  33. protected:
  34. /// <summary>
  35. /// Clean up any resources being used.
  36. /// </summary>
  37. ~Form1()
  38. {
  39. if (components)
  40. {
  41. delete components;
  42. }
  43. }
  44. private: System::Windows::Forms::Panel^ panel1;
  45. protected:
  46. private: System::Windows::Forms::Label^ label3;
  47. private: System::Windows::Forms::Label^ label2;
  48. private: System::Windows::Forms::Label^ label1;
  49. private: System::Windows::Forms::Button^ button4;
  50. private: System::Windows::Forms::Button^ button3;
  51. private: System::Windows::Forms::Button^ button2;
  52. private: System::Windows::Forms::Button^ button1;
  53. private: System::Windows::Forms::TextBox^ Result;
  54. private: System::Windows::Forms::TextBox^ SecondOperand;
  55. private: System::Windows::Forms::TextBox^ FirstOperand;
  56. private: System::Windows::Forms::MenuStrip^ menuStrip1;
  57. private: System::Windows::Forms::ToolStripMenuItem^ operationToolStripMenuItem;
  58. private: System::Windows::Forms::ToolStripMenuItem^ addToolStripMenuItem;
  59. private: System::Windows::Forms::ToolStripMenuItem^ subtractToolStripMenuItem;
  60. private: System::Windows::Forms::ToolStripMenuItem^ multiplyToolStripMenuItem;
  61. private: System::Windows::Forms::ToolStripMenuItem^ divideToolStripMenuItem;
  62. private: System::Windows::Forms::ToolStripMenuItem^ exitToolStripMenuItem;
  63. private: System::Windows::Forms::ContextMenuStrip^ contextMenuStrip1;
  64. private: System::Windows::Forms::ToolStripMenuItem^ addToolStripMenuItem1;
  65. private: System::Windows::Forms::ToolStripMenuItem^ subToolStripMenuItem;
  66. private: System::Windows::Forms::ToolStripMenuItem^ mulToolStripMenuItem;
  67. private: System::Windows::Forms::ToolStripMenuItem^ divToolStripMenuItem;
  68. private: System::Windows::Forms::Panel^ panel2;
  69. private: System::Windows::Forms::Button^ button8;
  70. private: System::Windows::Forms::Button^ button7;
  71. private: System::Windows::Forms::Button^ button6;
  72. private: System::Windows::Forms::Button^ button5;
  73. private: System::Windows::Forms::Button^ button9;
  74. private: System::ComponentModel::IContainer^ components;
  75.  
  76.  
  77. private:
  78. /// <summary>
  79. /// Required designer variable.
  80. /// </summary>
  81.  
  82.  
  83. #pragma region Windows Form Designer generated code
  84. /// <summary>
  85. /// Required method for Designer support - do not modify
  86. /// the contents of this method with the code editor.
  87. /// </summary>
  88. void InitializeComponent(void)
  89. {
  90. this->components = (gcnew System::ComponentModel::Container());
  91. System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
  92. this->panel1 = (gcnew System::Windows::Forms::Panel());
  93. this->contextMenuStrip1 = (gcnew System::Windows::Forms::ContextMenuStrip(this->components));
  94. this->addToolStripMenuItem1 = (gcnew System::Windows::Forms::ToolStripMenuItem());
  95. this->subToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  96. this->mulToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  97. this->divToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  98. this->button4 = (gcnew System::Windows::Forms::Button());
  99. this->button3 = (gcnew System::Windows::Forms::Button());
  100. this->button2 = (gcnew System::Windows::Forms::Button());
  101. this->button1 = (gcnew System::Windows::Forms::Button());
  102. this->Result = (gcnew System::Windows::Forms::TextBox());
  103. this->SecondOperand = (gcnew System::Windows::Forms::TextBox());
  104. this->FirstOperand = (gcnew System::Windows::Forms::TextBox());
  105. this->label3 = (gcnew System::Windows::Forms::Label());
  106. this->label2 = (gcnew System::Windows::Forms::Label());
  107. this->label1 = (gcnew System::Windows::Forms::Label());
  108. this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
  109. this->operationToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  110. this->addToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  111. this->subtractToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  112. this->multiplyToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  113. this->divideToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  114. this->exitToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  115. this->panel2 = (gcnew System::Windows::Forms::Panel());
  116. this->button8 = (gcnew System::Windows::Forms::Button());
  117. this->button7 = (gcnew System::Windows::Forms::Button());
  118. this->button6 = (gcnew System::Windows::Forms::Button());
  119. this->button5 = (gcnew System::Windows::Forms::Button());
  120. this->button9 = (gcnew System::Windows::Forms::Button());
  121. this->panel1->SuspendLayout();
  122. this->contextMenuStrip1->SuspendLayout();
  123. this->menuStrip1->SuspendLayout();
  124. this->panel2->SuspendLayout();
  125. this->SuspendLayout();
  126. //
  127. // panel1
  128. //
  129. this->panel1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
  130. this->panel1->ContextMenuStrip = this->contextMenuStrip1;
  131. this->panel1->Controls->Add(this->button4);
  132. this->panel1->Controls->Add(this->button3);
  133. this->panel1->Controls->Add(this->button2);
  134. this->panel1->Controls->Add(this->button1);
  135. this->panel1->Controls->Add(this->Result);
  136. this->panel1->Controls->Add(this->SecondOperand);
  137. this->panel1->Controls->Add(this->FirstOperand);
  138. this->panel1->Controls->Add(this->label3);
  139. this->panel1->Controls->Add(this->label2);
  140. this->panel1->Controls->Add(this->label1);
  141. this->panel1->Location = System::Drawing::Point(18, 75);
  142. this->panel1->Name = L"panel1";
  143. this->panel1->Size = System::Drawing::Size(360, 180);
  144. this->panel1->TabIndex = 0;
  145. //
  146. // contextMenuStrip1
  147. //
  148. this->contextMenuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(4) {this->addToolStripMenuItem1,
  149. this->subToolStripMenuItem, this->mulToolStripMenuItem, this->divToolStripMenuItem});
  150. this->contextMenuStrip1->Name = L"contextMenuStrip1";
  151. this->contextMenuStrip1->Size = System::Drawing::Size(97, 92);
  152. //
  153. // addToolStripMenuItem1
  154. //
  155. this->addToolStripMenuItem1->Name = L"addToolStripMenuItem1";
  156. this->addToolStripMenuItem1->Size = System::Drawing::Size(96, 22);
  157. this->addToolStripMenuItem1->Text = L"Add";
  158. this->addToolStripMenuItem1->Click += gcnew System::EventHandler(this, &Form1::Add);
  159. //
  160. // subToolStripMenuItem
  161. //
  162. this->subToolStripMenuItem->Name = L"subToolStripMenuItem";
  163. this->subToolStripMenuItem->Size = System::Drawing::Size(96, 22);
  164. this->subToolStripMenuItem->Text = L"Sub";
  165. this->subToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::Sub);
  166. //
  167. // mulToolStripMenuItem
  168. //
  169. this->mulToolStripMenuItem->Name = L"mulToolStripMenuItem";
  170. this->mulToolStripMenuItem->Size = System::Drawing::Size(96, 22);
  171. this->mulToolStripMenuItem->Text = L"Mul";
  172. this->mulToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::Mul);
  173. //
  174. // divToolStripMenuItem
  175. //
  176. this->divToolStripMenuItem->Name = L"divToolStripMenuItem";
  177. this->divToolStripMenuItem->Size = System::Drawing::Size(96, 22);
  178. this->divToolStripMenuItem->Text = L"Div";
  179. this->divToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::Div);
  180. //
  181. // button4
  182. //
  183. this->button4->Location = System::Drawing::Point(283, 128);
  184. this->button4->Name = L"button4";
  185. this->button4->Size = System::Drawing::Size(70, 23);
  186. this->button4->TabIndex = 9;
  187. this->button4->Text = L"&Div";
  188. this->button4->UseVisualStyleBackColor = true;
  189. this->button4->Click += gcnew System::EventHandler(this, &Form1::Div);
  190. //
  191. // button3
  192. //
  193. this->button3->Location = System::Drawing::Point(283, 93);
  194. this->button3->Name = L"button3";
  195. this->button3->Size = System::Drawing::Size(70, 23);
  196. this->button3->TabIndex = 8;
  197. this->button3->Text = L"&Mul";
  198. this->button3->UseVisualStyleBackColor = true;
  199. this->button3->Click += gcnew System::EventHandler(this, &Form1::Mul);
  200. //
  201. // button2
  202. //
  203. this->button2->Location = System::Drawing::Point(283, 55);
  204. this->button2->Name = L"button2";
  205. this->button2->Size = System::Drawing::Size(70, 23);
  206. this->button2->TabIndex = 7;
  207. this->button2->Text = L"&Sub";
  208. this->button2->UseVisualStyleBackColor = true;
  209. this->button2->Click += gcnew System::EventHandler(this, &Form1::Sub);
  210. //
  211. // button1
  212. //
  213. this->button1->Location = System::Drawing::Point(283, 14);
  214. this->button1->Name = L"button1";
  215. this->button1->Size = System::Drawing::Size(70, 23);
  216. this->button1->TabIndex = 6;
  217. this->button1->Text = L"&Add";
  218. this->button1->UseVisualStyleBackColor = true;
  219. this->button1->Click += gcnew System::EventHandler(this, &Form1::Add);
  220. //
  221. // Result
  222. //
  223. this->Result->Location = System::Drawing::Point(143, 128);
  224. this->Result->Name = L"Result";
  225. this->Result->ReadOnly = true;
  226. this->Result->Size = System::Drawing::Size(117, 20);
  227. this->Result->TabIndex = 5;
  228. //
  229. // SecondOperand
  230. //
  231. this->SecondOperand->Location = System::Drawing::Point(143, 75);
  232. this->SecondOperand->Name = L"SecondOperand";
  233. this->SecondOperand->Size = System::Drawing::Size(117, 20);
  234. this->SecondOperand->TabIndex = 4;
  235. //
  236. // FirstOperand
  237. //
  238. this->FirstOperand->Location = System::Drawing::Point(143, 24);
  239. this->FirstOperand->Name = L"FirstOperand";
  240. this->FirstOperand->Size = System::Drawing::Size(117, 20);
  241. this->FirstOperand->TabIndex = 3;
  242. //
  243. // label3
  244. //
  245. this->label3->AutoSize = true;
  246. this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
  247. static_cast<System::Byte>(0)));
  248. this->label3->Location = System::Drawing::Point(21, 128);
  249. this->label3->Name = L"label3";
  250. this->label3->Size = System::Drawing::Size(43, 13);
  251. this->label3->TabIndex = 2;
  252. this->label3->Text = L"Result";
  253. //
  254. // label2
  255. //
  256. this->label2->AutoSize = true;
  257. this->label2->Location = System::Drawing::Point(21, 75);
  258. this->label2->Name = L"label2";
  259. this->label2->Size = System::Drawing::Size(88, 13);
  260. this->label2->TabIndex = 1;
  261. this->label2->Text = L"Second Operand";
  262. //
  263. // label1
  264. //
  265. this->label1->AutoSize = true;
  266. this->label1->Location = System::Drawing::Point(21, 24);
  267. this->label1->Name = L"label1";
  268. this->label1->Size = System::Drawing::Size(70, 13);
  269. this->label1->TabIndex = 0;
  270. this->label1->Text = L"First Operand";
  271. //
  272. // menuStrip1
  273. //
  274. this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->operationToolStripMenuItem,
  275. this->exitToolStripMenuItem});
  276. this->menuStrip1->Location = System::Drawing::Point(0, 0);
  277. this->menuStrip1->Name = L"menuStrip1";
  278. this->menuStrip1->Size = System::Drawing::Size(390, 24);
  279. this->menuStrip1->TabIndex = 1;
  280. this->menuStrip1->Text = L"menuStrip1";
  281. //
  282. // operationToolStripMenuItem
  283. //
  284. this->operationToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(4) {this->addToolStripMenuItem,
  285. this->subtractToolStripMenuItem, this->multiplyToolStripMenuItem, this->divideToolStripMenuItem});
  286. this->operationToolStripMenuItem->Name = L"operationToolStripMenuItem";
  287. this->operationToolStripMenuItem->Size = System::Drawing::Size(72, 20);
  288. this->operationToolStripMenuItem->Text = L"&Operation";
  289. //
  290. // addToolStripMenuItem
  291. //
  292. this->addToolStripMenuItem->Name = L"addToolStripMenuItem";
  293. this->addToolStripMenuItem->Size = System::Drawing::Size(152, 22);
  294. this->addToolStripMenuItem->Text = L"&Add";
  295. this->addToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::Add);
  296. //
  297. // subtractToolStripMenuItem
  298. //
  299. this->subtractToolStripMenuItem->Name = L"subtractToolStripMenuItem";
  300. this->subtractToolStripMenuItem->Size = System::Drawing::Size(152, 22);
  301. this->subtractToolStripMenuItem->Text = L"&Subtract";
  302. this->subtractToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::Sub);
  303. //
  304. // multiplyToolStripMenuItem
  305. //
  306. this->multiplyToolStripMenuItem->Name = L"multiplyToolStripMenuItem";
  307. this->multiplyToolStripMenuItem->Size = System::Drawing::Size(152, 22);
  308. this->multiplyToolStripMenuItem->Text = L"&Multiply";
  309. this->multiplyToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::Mul);
  310. //
  311. // divideToolStripMenuItem
  312. //
  313. this->divideToolStripMenuItem->Name = L"divideToolStripMenuItem";
  314. this->divideToolStripMenuItem->Size = System::Drawing::Size(152, 22);
  315. this->divideToolStripMenuItem->Text = L"&Divide";
  316. this->divideToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::Div);
  317. //
  318. // exitToolStripMenuItem
  319. //
  320. this->exitToolStripMenuItem->Name = L"exitToolStripMenuItem";
  321. this->exitToolStripMenuItem->Size = System::Drawing::Size(37, 20);
  322. this->exitToolStripMenuItem->Text = L"&Exit";
  323. this->exitToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::Exit);
  324. //
  325. // panel2
  326. //
  327. this->panel2->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
  328. this->panel2->Controls->Add(this->button8);
  329. this->panel2->Controls->Add(this->button7);
  330. this->panel2->Controls->Add(this->button6);
  331. this->panel2->Controls->Add(this->button5);
  332. this->panel2->Location = System::Drawing::Point(18, 27);
  333. this->panel2->Name = L"panel2";
  334. this->panel2->Size = System::Drawing::Size(135, 45);
  335. this->panel2->TabIndex = 3;
  336. //
  337. // button8
  338. //
  339. this->button8->FlatStyle = System::Windows::Forms::FlatStyle::Popup;
  340. this->button8->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"button8.Image")));
  341. this->button8->Location = System::Drawing::Point(67, 6);
  342. this->button8->Name = L"button8";
  343. this->button8->Size = System::Drawing::Size(30, 30);
  344. this->button8->TabIndex = 3;
  345. this->button8->UseVisualStyleBackColor = true;
  346. this->button8->Click += gcnew System::EventHandler(this, &Form1::Mul);
  347. //
  348. // button7
  349. //
  350. this->button7->FlatStyle = System::Windows::Forms::FlatStyle::Popup;
  351. this->button7->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"button7.Image")));
  352. this->button7->Location = System::Drawing::Point(35, 6);
  353. this->button7->Name = L"button7";
  354. this->button7->Size = System::Drawing::Size(30, 30);
  355. this->button7->TabIndex = 2;
  356. this->button7->UseVisualStyleBackColor = true;
  357. this->button7->Click += gcnew System::EventHandler(this, &Form1::Sub);
  358. //
  359. // button6
  360. //
  361. this->button6->FlatStyle = System::Windows::Forms::FlatStyle::Popup;
  362. this->button6->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"button6.Image")));
  363. this->button6->Location = System::Drawing::Point(99, 6);
  364. this->button6->Name = L"button6";
  365. this->button6->Size = System::Drawing::Size(30, 30);
  366. this->button6->TabIndex = 1;
  367. this->button6->UseVisualStyleBackColor = true;
  368. this->button6->Click += gcnew System::EventHandler(this, &Form1::Div);
  369. //
  370. // button5
  371. //
  372. this->button5->FlatStyle = System::Windows::Forms::FlatStyle::Popup;
  373. this->button5->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"button5.Image")));
  374. this->button5->Location = System::Drawing::Point(3, 6);
  375. this->button5->Name = L"button5";
  376. this->button5->Size = System::Drawing::Size(30, 30);
  377. this->button5->TabIndex = 0;
  378. this->button5->UseVisualStyleBackColor = true;
  379. this->button5->Click += gcnew System::EventHandler(this, &Form1::Add);
  380. //
  381. // button9
  382. //
  383. this->button9->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
  384. this->button9->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"button9.Image")));
  385. this->button9->ImageAlign = System::Drawing::ContentAlignment::MiddleLeft;
  386. this->button9->Location = System::Drawing::Point(303, 27);
  387. this->button9->Name = L"button9";
  388. this->button9->Size = System::Drawing::Size(75, 45);
  389. this->button9->TabIndex = 4;
  390. this->button9->Text = L"&Exit";
  391. this->button9->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
  392. this->button9->UseVisualStyleBackColor = true;
  393. this->button9->Click += gcnew System::EventHandler(this, &Form1::Exit);
  394. //
  395. // Form1
  396. //
  397. this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  398. this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  399. this->ClientSize = System::Drawing::Size(390, 267);
  400. this->Controls->Add(this->button9);
  401. this->Controls->Add(this->panel1);
  402. this->Controls->Add(this->panel2);
  403. this->Controls->Add(this->menuStrip1);
  404. this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::Fixed3D;
  405. this->MainMenuStrip = this->menuStrip1;
  406. this->Name = L"Form1";
  407. this->Text = L"Calculator (Lauris Kristopanovs)";
  408. this->panel1->ResumeLayout(false);
  409. this->panel1->PerformLayout();
  410. this->contextMenuStrip1->ResumeLayout(false);
  411. this->menuStrip1->ResumeLayout(false);
  412. this->menuStrip1->PerformLayout();
  413. this->panel2->ResumeLayout(false);
  414. this->ResumeLayout(false);
  415. this->PerformLayout();
  416.  
  417. }
  418. #pragma endregion
  419. private: System::Void Exit(System::Object^ sender, System::EventArgs^ e) {
  420. Close();
  421. }
  422. private: System::Void Add(System::Object^ sender, System::EventArgs^ e) {
  423. try {
  424. Result->Text = Convert::ToString(
  425. Convert::ToDouble(FirstOperand->Text) +
  426. Convert::ToDouble(SecondOperand->Text)
  427. );
  428. }
  429. catch(...) {
  430. MessageBox::Show("Error in operands !",
  431. "Calculator Error", MessageBoxButtons::OK,
  432. MessageBoxIcon::Error);
  433. }
  434. }
  435. private: System::Void Sub(System::Object^ sender, System::EventArgs^ e) {
  436. try {
  437. Result->Text = Convert::ToString(
  438. Convert::ToDouble(FirstOperand->Text) -
  439. Convert::ToDouble(SecondOperand->Text)
  440. );
  441. }
  442. catch(...) {
  443. MessageBox::Show("Error in operands !",
  444. "Calculator Error", MessageBoxButtons::OK,
  445. MessageBoxIcon::Error);
  446. }
  447. }
  448. private: System::Void Mul(System::Object^ sender, System::EventArgs^ e) {
  449. try {
  450. Result->Text = Convert::ToString(
  451. Convert::ToDouble(FirstOperand->Text) *
  452. Convert::ToDouble(SecondOperand->Text)
  453. );
  454. }
  455. catch(...) {
  456. MessageBox::Show("Error in operands !",
  457. "Calculator Error", MessageBoxButtons::OK,
  458. MessageBoxIcon::Error);
  459. }
  460. }
  461. private: System::Void Div(System::Object^ sender, System::EventArgs^ e) {
  462. try {
  463. Result->Text = Convert::ToString(
  464. Convert::ToDouble(FirstOperand->Text) /
  465. Convert::ToDouble(SecondOperand->Text)
  466. );
  467. }
  468. catch(...) {
  469. MessageBox::Show("Error in operands !",
  470. "Calculator Error", MessageBoxButtons::OK,
  471. MessageBoxIcon::Error);
  472. }
  473. }
  474. };
  475. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement