Tuesday, April 28, 2015

Quiz Pra UTS Network Programming 2



Post baru sebelum UTS.. quiz network programming 2.. oke langsung aja bikin form seperti ini..
form terdiri dari satu label, satu richtextbox, satu button..
ketentuannya :

posisi awal form : tengah (center)
minimize dan maximize disable
ketika awal running, richtextbox akan menampilkan informasi software dan hardware (oS, prosesor, arsitektur, motherboard)
informasi dibuat method dan dipanggil pada form_load
ketika button diklik maka informasi akan disimpan dengan format .txt

pertama buat form seperti ini. satu label, satu richtextbox, satu button


 jangan lupa tambahin headernya


ini pas running, klik simpan

bakalan muncul savedialog

coba buka filenya pake notepad

berikut full code nya

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;
using Microsoft.Win32;
using System.IO;

namespace quizprauts
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();          
            this.StartPosition=FormStartPosition.CenterScreen;
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            this.MaximizeBox=false;
            this.MinimizeBox=false;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            munculinfoRichtext();
        }

        void munculinfoRichtext()
        {
            RegistryKey buka = Registry.LocalMachine;

            RegistryKey os = buka.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
            RegistryKey proci = buka.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
            RegistryKey arsitek = buka.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
            RegistryKey mobo = buka.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\BIOS");

            richTextBox1.Text = Convert.ToString(os.GetValue("ProductName")) + " " + Convert.ToString(proci.GetValue("ProcessorNameString")) + " " + Convert.ToString(arsitek.GetValue("Identifier")) + " " + Convert.ToString(mobo.GetValue("BaseBoardManufacturer"));
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SaveFileDialog simpan = new SaveFileDialog();
            simpan.Filter = "Text document | *.txt";
            simpan.RestoreDirectory = true;
            if(simpan.ShowDialog() !=DialogResult.Cancel)
            {
                StreamWriter filesimpan = new StreamWriter(File.Create(simpan.FileName));
                filesimpan.Write(richTextBox1.Text);
                filesimpan.Dispose();
            }
        }
    }
}

file project DOWNLOAD (Visual Studio 2012 recomended atau dengan net framework 4.5)

0 comments:

Post a Comment