Example with DialogControls:-




Add a new Form i.e.,FormDialogs to the Windows Application WABasics

Create one label,one textboxe and four buttons ,one colorDialog,one fontDialog,one openFileDialog,one SaveDialog  set the following properties to them

[colorDialog1,fontDialog1,openFileDialog1,saveDialog1 will appear in Component tray only not on the Form]

label1:
     Text      :         Enter Any Data
     Name     :         lblSample
button1:
     Name     :         btnOpen
     Text       :         Open…..

button2:
     Name     :         btnSave
     Text       :         Save…..

button3:
     Name     :         btnFont
     Text       :         Font…..

button4:
     Name     :         btnColor
     Text       :         Color….


Design :-



Generate the EventHandlers for btnOpen ,btnSave,btnFont,btnColor Events
& write the following code in Source[FormDialogs.cs] 

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

        private void btnOpen_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "TextFiles|*.txt|Word Files|*.doc|Excel Files|*.xls|All Files|*.*";
            openFileDialog1.ShowDialog();
            txtSample.Text = openFileDialog1.FileName;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            saveFileDialog1.ShowDialog();
            txtSample.Text = saveFileDialog1.FileName;
        }

        private void btnFont_Click(object sender, EventArgs e)
        {
            fontDialog1.ShowDialog();
            txtSample.Font = fontDialog1.Font;
        }

        private void btnColor_Click(object sender, EventArgs e)
        {
            colorDialog1.ShowDialog();
            txtSample.BackColor = colorDialog1.Color;
        }
    }
}





Result :-



No comments:

Post a Comment