300x250 AD TOP

helooo
Showing posts with label Win-forms. Show all posts
Showing posts with label Win-forms. Show all posts
Tagged under:

Numeric Textbox

Description:-

Formatting user input plays a major role in form data validations, so below example shows how to validate a text box for taking only numeric values of desired maximum size(example 10digt phone number).
Form1.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 Numerictextbox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
if (!(Char.IsDigit(e.KeyChar) || Char.IsControl(e.KeyChar)))
            { e.Handled = true; }




//Using Function

        }
           if (!(Char.IsDigit(e.KeyChar) || Char.IsControl(e.KeyChar)))
            { e.Handled = true; }
        }
        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {

int asciiCode = Convert.ToInt32(e.KeyChar);
if ((asciiCode >= 48 && asciiCode <=57)||Char.IsControl(e.KeyChar))


         
//Using ANSCII code


 {
        //Do nothing
   }
            else
            {
                e.Handled = true;
            }
        }
    }
}
  
Design :Form1

Property
Event
MaxLength=10                  (txtbox1)(txtbox2)     
KeyPress                            (txtbox1)(txtbox2)

Screens:
------
         Fig:Form1



 Download entire project click below Icon
Tagged under:

Combination of Keypress

Description:-

 Combination of Key Press In C# win forms is used to create user friendly applications,
Without clicking buttons and redirecting to several forms is avoided by providing key combinations.
Form1.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 keypresss
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
if (e.Alt && e.KeyCode==Keys.F5)

         
//Core Concept
  {
                report r = new report();
                r.Show();
                this.Hide();
            }
        }
    }
}

report.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 keypresss
{
    public partial class report : Form
    {
        public report()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form1 f = new Form1();
            f.Show();
            this.Show();

        }
    }
}

Design :Form1

Property
Event
KeyPreview=false          
KeyDown

Screens:
-------

         Fig:Form1


         Fig:report



Click below Icon for full project download    


Tagged under:

Redirection in Winforms

Description:-

Redirection is nothing but control transfers from one form to another form,
Below code explains how redirection takes place in win-forms application
Form1.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 transfering
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

      private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Form2 f2 = new Form2();         //this is second form object creation
            f2.Show();                                 //showing the second form
            this.Hide();                               //hiding the Currunt form (Form1)
        }
    }
}

Form2.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 transfering
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Form1 f1 = new Form1();         //creating object for Form1
            f1.Show();                                 //showing Form1
            this.Hide();                               //hiding Current form(Form2)
        }
    }
}

Screens:
-------
         Fig:Form1






         Fig:Form2




Click below Icon for full project download