Monday 31 December 2012

Tutorial Menampilkan Gambar & Identitas Pada Form 2 C#

Gambar 0.1
Gambar 0.1 adalah tampilan pada form 1 yang berisikan coding sebagai berikut :


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.Items.Add("Islam");
            comboBox1.Items.Add("Kristen");
            comboBox1.Items.Add("Katolik");
            comboBox1.Items.Add("Hindu");
            comboBox1.Items.Add("Budha");
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string a, b, c, d, f;
            if (radioButton1.Checked == true)
            {
                a = "Laki-laki";
            }
             else
            {
                a = "Perempuan";
            }
            if (checkBox1.Checked == true)
            {
                b = "Sepak Bola";
            }
            else
            {
                b = "";
            }
            if (checkBox2.Checked == true)
            {
                c = "Badminton";
            }
            else
            {
                c = "";
            }
            if (checkBox3.Checked==true)
            {
                d = "Basket";
            }
            else
            {
                d="";
            }
            if (checkBox4.Checked==true)
            {
                f = "Volley";
            }
            else 
            {
                f="";
            }
            Form2 baru = new Form2();
            baru.richTextBox1.Text  
                = "\nNama\t\t: " + textBox1.Text + "\nAlamat\t\t: " + textBox2.Text +
                "\nJenis Kelamin\t: " + a + "\nHobi\t\t\t: " + b + c + d + f;
            baru.pictureBox1.Image = pictureBox1.Image;
            baru.Show();
            
        }
        private void tabPage2_Click(object sender, EventArgs e)
        {
        }
        private void button2_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
        }
    }
}

Gambar 0.2
Pada Gambar 0.2 adalah tampilan form pada form 2,,jadi disini kita membuat form baru ,,dan akan menampilkannya pada form2 ,jadi kita menggabungkan 2 form dan ini kodingnya :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
        }
        private void Form2_Load(object sender, EventArgs e)
        {
        }
    }
}


Dan Gambar 0.3 adalah tampilan pada form1 bagian tab page .
Gambar 0.3

Dan Gambar 0.4 adalah Gambar Sebelum ditambahkannya gambar pada form 1 tab page 2 "
Gambar 0.4

0 komentar:

Post a Comment

Note: only a member of this blog may post a comment.