[Fs4] Fillestar4

4 out of 5 dentists recommend this WordPress.com site

Kategori: C-Sharp

Open System Folder and File in c#

[Fs4]Open System Folder and File

Fungsi aplikasi ini sebenarnya sangatlah sederhana , yaitu sebagai Shortcut yang ada di Windows…

Oke berikut syntaxnnya :

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 _Fs4_OpenFunctionality
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void BtnAddRemove_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("appwiz.cpl");
        }

        private void BtndDateTime_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("timedate.cpl");
        }

        private void BtnSystemProperty_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("sysdm.cpl");
        }

        private void BtnExplorer_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("Explorer.exe");
        }

        private void BtnControlPanel_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("Control.exe");
        }
    }
}
 

Demo Project

Terima Kasih ^_^

[Fs4]Open TextFiles in C# [c sharp]

[Fs4]Open TextFiles

Aplikasi saya buat dengan ide pengamanan FileText (.txt) di dalam folder tertentu dan me-lock nya, jadi tidak sembarang orang dapat membuka folder tersebut yang didalamnya berisi FileText yang penting atau bersifat pribadi : seperti password atau sebagainya ^_^ …

Oke langsung saya bahas :

1. Buat Form Baru
Klik File -> New – Project [ctrl + shift + N]

2. Pilih Windows Form Application

3. Setting Form Seperti Gambar di atas ^_^ atau terserah agan

Tambahkan:

contextMenuStrip1
openFileDialog1
saveFileDialog1
folderBrowserDialog1

&

using System.IO;
using System.Diagnostics;
using System.Security.AccessControl;
Berikut Syntax Form1.cs
private void Openbutton_Click(object sender, EventArgs e)
        {
            openFileDialog1.Title = "[Fs4]OpentextFiles";
            folderName = folderBrowserDialog1.SelectedPath;
            //Filter to only text files
            openFileDialog1.Filter = "TextFile|*.txt";
            openFileDialog1.FileName = String.Empty;
          
            //Open file dialog and store the returned value
            DialogResult result = openFileDialog1.ShowDialog();

            //If Open Button was pressed
            if (result == DialogResult.OK)
            {
                //Create a stream which points to the file
                Stream fs = openFileDialog1.OpenFile();

                //Create a reader using the stream
                StreamReader reader = new StreamReader(fs);
                //Read Contents
                richTextBox1.Text = reader.ReadToEnd();
                textBoxName.Text = openFileDialog1.FileName;
                //this.label1.Text = folderBrowserDialog1.SelectedPath;
                //Close the reader and the stream
                reader.Close();
            }
        }
private void Savebutton_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Title = "[Fs4]SavetextFiles";
            //Specify the extensions allowed
            saveFileDialog1.Filter = "Text File|.txt";
            //Empty the FileName text box of the dialog
            saveFileDialog1.FileName = textBoxName.Text;
            //Set default extension as .txt
            //saveFileDialog1.DefaultExt = textBoxName.Text;

            //Open the dialog and determine which button was pressed
            DialogResult result = saveFileDialog1.ShowDialog();

            //If the user presses the Save button
            if (result == DialogResult.OK)
            {
                //Create a file stream using the file name
                FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.Create);

                //Create a writer that will write to the stream
                StreamWriter writer = new StreamWriter(fs);
                //Write the contents of the text box to the stream
                writer.Write(richTextBox1.Text);
                //Close the writer and the stream
                writer.Close();
            }
        }

Pada contextMenuStrip1

private void saveTextToolStripMenuItem_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Title = "[Fs4]OpentextFiles";
            saveFileDialog1.Filter = "Text File|.txt";
            saveFileDialog1.FileName = textBoxName.Text;

            DialogResult result = saveFileDialog1.ShowDialog();

            if (result == DialogResult.OK)
            {
                FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.Create);

                StreamWriter writer = new StreamWriter(fs);
                writer.Write(richTextBox1.Text);
                writer.Close();
            }
        }
private void buttonBrowse_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBoxFile.Text = folderBrowserDialog1.SelectedPath;
            }
        }

private void buttonLock_Click(object sender, EventArgs e)
        {
            try
            {
                string folderPath = textBoxFile.Text;
                string adminUserName = Environment.UserName;// getting your adminUserName
                DirectorySecurity ds = Directory.GetAccessControl(folderPath);
                FileSystemAccessRule fsa = new FileSystemAccessRule(adminUserName, FileSystemRights.FullControl, AccessControlType.Deny);

                ds.AddAccessRule(fsa);
                Directory.SetAccessControl(folderPath, ds);
                MessageBox.Show("Locked");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }   
        }

private void buttonUnlock_Click(object sender, EventArgs e)
        {
            try
            {
                string folderPath = textBoxFile.Text;
                string adminUserName = Environment.UserName;// getting your adminUserName
                DirectorySecurity ds = Directory.GetAccessControl(folderPath);
                FileSystemAccessRule fsa = new FileSystemAccessRule(adminUserName, FileSystemRights.FullControl, AccessControlType.Deny);

                ds.RemoveAccessRule(fsa);
                Directory.SetAccessControl(folderPath, ds);
                MessageBox.Show("UnLocked");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            } 
        }
Demo Project
Terima Kasih ^_^

Membuat Sliding Effect Form c-sharp

Kali ini saya akan menjelaskan bagaimana membuat Sliding Effect di Form c# yang tentu saja sangat keren menurut saya, heeehee he ^_^
 Oke lanjut
1. Buatlah dua Form dengan Nama Form1 dan MainForm seperti Gambar di atas
Di MainForm buatlah Button [Creat Sliding] untuk memanggil Form1
 Untuk syntax’y dibawah ini ;

Full Code
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;
using System.Runtime.InteropServices; //Tambahkan using System disamping di MainForm

namespace Sliding_Effect
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bool IsOpen = false;
            FormCollection fc = Application.OpenForms;
            foreach (Form f in fc)
            {
                if (f.Name == “Form1”)
                {
                    IsOpen = true;
                    f.Focus();
                    break;
                }
            }
            if (IsOpen == false)
            {
                Form1 form = new Form1();
                form.Show();
            }
        }
    }
}

Kemudian di Form1 buatlah Button [Close Sliding] untuk keluar
 Untuk Syntax’y ;

Full Code
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;
using System.Runtime.InteropServices;

namespace Sliding_Effect
{
    public partial class Form1 : Form
    {
        //Constants
        const int AW_SLIDE = 0X40000;
        const int AW_HOR_POSITIVE = 0X1;
        const int AW_HOR_NEGATIVE = 0X2;
        const int AW_BLEND = 0X80000;
        [DllImport(“user32”)]
        static extern bool AnimateWindow(IntPtr hwnd, int time, int flags);

        public Form1()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            //Load the Form At Position of Main Form
            int WidthOfMain = Application.OpenForms[“MainForm”].Width;
            int HeightofMain = Application.OpenForms[“MainForm”].Height;
            int LocationMainX = Application.OpenForms[“MainForm”].Location.X;
            int locationMainy = Application.OpenForms[“MainForm”].Location.Y;
            //Set the Location
            this.Location = new Point(LocationMainX + WidthOfMain, locationMainy + 10);
            //Animate form
            AnimateWindow(this.Handle, 500, AW_SLIDE | AW_HOR_POSITIVE);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}



Download Full code and The Project
Password : Filletar4

Membuat Validasi Angka dan Huruf di TextBox dengan BaloonToolTip Tc-sharp

Langsung saja

1. Kalian buat form dulu Buat seperti gambar diatas
2. Atur Propertiesnya
 Label1 Text : Validasi Angka
 Label2 Text : Validasi Huruf
 Button1 Text : Clear All TextBox
 TextBox1 Name : tVangka
 TextBox2 Name : tVhuruf

 3. Kemudian klik di TextBox1 dengan Properties Event : KeyPress = ValidateInputNumeric

Copy Paste Kode berikut :

string strValid = “0123456789”;
            if (e.KeyChar == (char)56)
                e.Handled = false;
            else
            {

                if (strValid.IndexOf(e.KeyChar) < 0 && !(e.KeyChar == (char)Keys.Back))
                    e.Handled = true;
                else
                    e.Handled = false;
            }

4. Kemudian klik di TextBox2 dengan Properties Event : KeyPress = ValidateInputHuruf
Copy Paste Kode berikut :

string strValid = “0123456789”;
            if (e.KeyChar == (char)56)
                e.Handled = false;
            else
            {

                if (strValid.IndexOf(e.KeyChar) < 0 && !(e.KeyChar == (char)Keys.Back))
                    e.Handled = false;
                else
                    e.Handled = true;
            }

5. Double Klik Button1
Copy Paste Kode berikut :

foreach (Control c in this.Controls)
            {
                if (c is TextBox)
                    (c as TextBox).Clear();
            }

6. Double klik di Form = Form_Load
Copy Paste Kode berikut :

ToolTip textBoxToolTip = new ToolTip();
            textBoxToolTip.ToolTipTitle = “Information”;
            textBoxToolTip.UseFading = true;
            textBoxToolTip.UseAnimation = true;
            textBoxToolTip.IsBalloon = true;
            textBoxToolTip.ShowAlways = true;
            textBoxToolTip.AutoPopDelay = 5000;
            textBoxToolTip.InitialDelay = 1000;
            textBoxToolTip.ReshowDelay = 500;

            //Isi informasi yang ingin dimasukan pada tiap button
            textBoxToolTip.SetToolTip(tVangka, “TextBox harus berisi angka”);
            textBoxToolTip.SetToolTip(tVhuruf, “TextBox harus berisi huruf”);

Untuk Download File Project’y
Download disini
Password : Fillestar4

Kalkulator Sederhana (c-sharp c#)

Berikut saya akan menjelaskan bagaimana membuat Kalkulator Sederhana di Microsoft Visual Studio 2008 (c-sharp) : 1. Pertama kalian buat Form dulu, seperti gambar dibawah ini

2. Atur Setiap Event Button di Properties

Block Button yang di lingkari warna Merah, kemudian atur Event = Click (operatorButton)

Block Button yang di lingkari warna Biru, atur Event = Click (numberButton)
Block Button yang di lingkari warna Hijau, atur Event = Click (equalsButton)

3. Rename Properties TextBox Name : outputTextBox Button [C] Name : dotButton Button Clear Name : clearButton

Berikut Full Code’y:

Full Code
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;
 namespace Kalkulator_Sederhana
{
         public partial class Form1 : Form
         {
               public Form1()
                      {
                            InitializeComponent();
                      }

               private bool isFirst = true;
               private bool shouldClear = true;
               private double firstOperand;
               private double secondOperand;
               private double result = 0;
               private string symbol = String.Empty;

   private void numberButton_Click(object sender, EventArgs e)
  {
           Button sourceButton = (sender as Button);
           double oldNumber, buttonNumber, newNumber; if (shouldClear)
          {
                outputTextBox.Clear();
                oldNumber = 0;
                shouldClear = false;
          }
            else
          {
                oldNumber = Double.Parse(outputTextBox.Text);
          }
          buttonNumber = Double.Parse(sourceButton.Text);
          newNumber = (oldNumber * 10) + buttonNumber;
          if (isFirst) { firstOperand = newNumber;
          }
            else
         {
          secondOperand = newNumber;
          }
         outputTextBox.Text += sourceButton.Text;
         Calculate(symbol);
   }
   private void Calculate(string operatorSymbol)
 {
 if (isFirst)
{
 result = firstOperand; return;
}
 switch (operatorSymbol)
 {
case “+”: result = firstOperand + secondOperand;
 break; case “-“: result = firstOperand – secondOperand;
 break;
 case “*”: result = firstOperand * secondOperand;
 break;
 case “/”: result = firstOperand / secondOperand;
 break;
 }
 }

 private void operatorButton_Click(object sender, EventArgs e)
{
 firstOperand = result; Button sourceButton = (sender as Button);
 string operatorSymbol = sourceButton.Text;
 if (isFirst) isFirst = false;
 shouldClear = true;
 symbol = operatorSymbol;
outputTextBox.Text = result.ToString();
}

 private void equalsButton_Click(object sender, EventArgs e)
{
 outputTextBox.Text = result.ToString();
 isFirst = true; shouldClear = true;
}

   private void clearButton_Click(object sender, EventArgs e)
{
    outputTextBox.Text = “0”;
    result = 0;
    isFirst = true; shouldClear = true;
}

 private void Form1_Load(object sender, EventArgs e)
 {
       outputTextBox.Focus();
 }
 }
 }

Download Project disini
Pass : Fillestar4

Terima Kasih
Maaf bila penjelasanya agak nda jelas ^_^