Posted by : Aulia Ihza H - 0089
Monday, March 22, 2021
1.Persiapan
- Menginstall Visual Studio dengan Pilihan .NET Desktop Developer
- Atau Visual Studio Code dengan .NET
2.Program Hello World
3.Program Currency Converter
Tampilan Awal Forms. Toolbox memiliki atribut di sisi kiri yang siap di-drag. Toolbox kanan bawah untuk mengatur properti dari atribut yang ditarik seperti nama objek dan ukuran teks |
Setelah beberapa atribut didrag |
Dan diganti propertinya seperti Common Box |
Pada Nama Form.Designer.CS akan ada Nama-nama Atribut yang siap dialokasikan pada Nama-Form.CS private System.Windows.Forms.NumericUpDown numericUpDown1; private System.Windows.Forms.ComboBox comboBox1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label4; private System.Windows.Forms.ComboBox comboBox2; private System.Windows.Forms.Button button1; private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox textBox1; |
Berikut Isi Kode dari Nama-Form.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Converter() { float input = (float)this.numericUpDown1.Value; float output = input; if (this.comboBox1.SelectedItem.ToString() == "IDR") { if (this.comboBox2.SelectedItem.ToString() == "JPY") { output = (float)(0.0076 * input); } if (this.comboBox2.SelectedItem.ToString() == "USD") { output = (float)(0.000069 * input); } if (this.comboBox2.SelectedItem.ToString() == "EUR") { output = (float)(0.000058 * input); } if (this.comboBox2.SelectedItem.ToString() == "RS") { output = (float)(0.0050 * input); } } if (this.comboBox1.SelectedItem.ToString() == "USD") { if (this.comboBox2.SelectedItem.ToString() == "IDR") { output = (float)(14392.45 * input); } if (this.comboBox2.SelectedItem.ToString() == "JPY") { output = (float)(108.76 * input); } if (this.comboBox2.SelectedItem.ToString() == "EUR") { output = (float)(0.84 * input); } if (this.comboBox2.SelectedItem.ToString() == "RS") { output = (float)(72.37 * input); } } this.textBox1.Text = output.ToString("0.##"); } private void Form1_Load(object sender, EventArgs e) { this.comboBox1.SelectedItem = "IDR"; this.comboBox2.SelectedItem = "USD"; } private void label1_Click(object sender, EventArgs e) { } private void label2_Click(object sender, EventArgs e) { } private void label4_Click(object sender, EventArgs e) { } private void label3_Click_1(object sender, EventArgs e) { } private void button1_Click_1(object sender, EventArgs e) { Converter(); } } }
Dan Demo kodenya