Wednesday, 3 April 2013

Example of PictureBox Control, colorDialog, openDialog and saveDialog control.

 Example of PictureBox Control, colorDialog, openDialog and saveDialog control.

Add a colorDialog, fontDialog, openFileDialog and saveDialog to the form and design as following :




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

        private void button1_Click(object sender, EventArgs e)
        {
            DialogResult dr = colorDialog1.ShowDialog();
            if (dr == DialogResult.OK)
                button1.BackColor = colorDialog1.Color;


        }

        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult dr = fontDialog1.ShowDialog();
            if (dr == DialogResult.OK)
                button2.Font = fontDialog1.Font;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            openFileDialog1.FileName = " ";
            openFileDialog1.Filter = "ImageFiles(*.jpg)|*.jpg|Icon Files(*.ico)|*.ico|All Files(*.*)|*.*";
            DialogResult dr = openFileDialog1.ShowDialog();
            if (dr != DialogResult.Cancel)
                pictureBox1.ImageLocation = openFileDialog1.FileName;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Filter = "ImageFiles(*.jpg)|*.jpg|Icon Files(*.ico)|*.ico|All Files(*.*)|*.*";
            DialogResult dr = saveFileDialog1.ShowDialog();
            if (dr != DialogResult.Cancel)
            {
                string fname = saveFileDialog1.FileName;
                pictureBox1.Image.Save(fname);
            }
        }
    }
}

RichTextBox ,MessageBox and Masked TextBox Control

RichTextBox control is similr to a text box but provides advanced text entry and editing features like paragragh formatting. This control provides a set of properties and methods to perform formatting of the text.

Properties
Font, BackColor, ForeColor, Wordwrap, modified
Methods
 Cut(), Copy(), Paste(),Undo(), Redo(), SelectAll(), DeselectAll()
SaveFile(String fname, RichTextBoxStream Type t)
LoadFile(String fname,RichTextBox Straem Type t)

RichTextBox Stream Type is an enum which provides with a list of formats in which we want to save the file like plain Text(for notepad), RichText(for wordpad), etc
MessageBox Control

This control is use for diplaying message within a Windows application to the end user. The type of message being displayed can be euther an alert or warning or error or information messages etc.

To display the message in messagebox we can use overloaded method show which returns value of type dialog result which tells which button has been clicked on the messagebox.

show(string msg)    
show(string msg, string title, MessageBoxButtons)
show(string msg,string title, MessageBoxButtons buttons,MessageBox icon icon)

MessageBox
buttons is an enum which will list a set of constants to  choose like what type of icon image has to be displayed on the messagebox.


Masked TextBox
 This control is an extension to text box which is provided for distinguishing between proper and improper input i.e we can take the input from the user in specified format like date, time and PNR number etc. To set the format in which the input has to be entered we are provided with property masked.  Once we select the property in property window we will find a button inside it click on it which opens a  window displaying a list of predefined formats to choose, we can either select a required format for it or choose custom and enter the input format within the masked textbox  below using zeroes.

For Example:
Railway PNR No: 000-0000000
Date                   : 00/00/00
Time                   : 00:00:00

PictureBox Control

This control is use for displaying images on the UI. To display an image in the picture box first bind the image to picture box use any of the following properties:

-ImageLocation= "<path of the image>"
-Image=Image.FromFile("<path of the image>")

When we bind an image to the picture box and control how the picture box will handle image placement and control sizing we are given with property SizeMode. It is an enumerated property that can be set to any of the following:

SizeMode:
  • Normal[default]
  • Strech Image
  • AutoSize
  • CenterImage
By default, the picture box control doesn't provide any border we can use the border style property and specify what type of border the picture box control should have. This is also enumerated property that can be set to any other property.

Border Style :
  • None[default]
  • FixedSingle
  • Fixed 3D

Monday, 1 April 2013

ComboBox, ListBox and CheckListBox

We use these three controls to provide a users with the list of values to choose from.
  1.  ComboBox: It is a combination of two controls :
  • DropDown list
  • TextBox
It allows us to either select a value from the list of values as well as enter a new value in the list but provides only single selection.

     2.  ListBox: This control also provides with list of values to choose from and by default this control also support single selection only but can be customized to multi-selection by setting a property SelectionMode either as multi simple or muti extended.
  • SelectionMode[Enumerated Property]
  • None
  • One[default]
  • Multi Simple(Only Mouse Click)
  • Multi Extended(ctrl+ Mouse Click)
     3.   CheckList Box : This control also provides a list of values to choose from but it displays a checkbox beside each item from selection. By default this control supports multi-selection.

Thursday, 28 March 2013

Radio Button and Check Box


This two controls will be used when we want to provide the user with the list of values to choose from.The difference between these two controls is, radio button control is used when only a single value has to be selected from the list whereas check box is used when we want to provide multiple values to choose from list.
As a radio button supports single selection only once we select the second radio button automatically the first one gets deselected. But if we have requirement of using radio button under different places or option we need to group radio buttons by placing them on a separate container like panel, groupbox etc so that one radio button can be selected from each group.

Checked is a property provided by radio buttons and check box control to identify which control has been selected its a Boolean property that returns true if the control is not selected.