C# - How to make a textbox that only accepts numbers or only characters

C# - How to make a textbox that only accepts numbers or only characters

                                                                                                                                                           

in this c# tutorial we will see how to make a textbox that only accepts numbers or only characters in C# .



Project Source Code :

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;

namespace WindowsFormsApplication1
{
    public partial class TextBox_Numbers_Characters : Form
    {
        public TextBox_Numbers_Characters()
        {
            InitializeComponent();
        }

        private void TXTB_ONLY_CHAR_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(!char.IsControl(e.KeyChar) && !char.IsLetter(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void TXTB_ONLY_NUMBER_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void TXTB_CHAR_AND_NUMBER_KeyPress(object sender, KeyPressEventArgs e)
        {
            // allow digit + char + white space
            if (!char.IsControl(e.KeyChar) && !char.IsLetterOrDigit(e.KeyChar) && !char.IsWhiteSpace(e.KeyChar))
            {
                e.Handled = true;
            }
        }

    }
}


=> OutPut :

Textbox Accepts Only Numbers Or Only Characters
Textbox Accepts Only Numbers Or Only Characters In C#

How To Add Flash Object In C# Form

How To Add Flash Object In C# Form

How To Add Flash Object In C# Form

                                                                                                                                                           

in this c# tutorial we will see how to add flash object in C# components used "shockwave flash object" .




    Steps :
1) Right click on the box tools .
2) choose: choose items .
3) select: shockwave flash object .

4) add in the form .
5) go to his property ==> in movie write the path of the flash object (.swf).

How to Create a Drop Down Menu in C#

How to Create a Drop Down Menu in C#

                                                                                                                                                                

in this c# tutorial we will see how to Create a Drop Down Menu in C# using TextBoxes . components used "TextBoxes" "GroupBox" and "timer".



Project Source Code :

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;

namespace WindowsFormsApplication1
{
    public partial class Drop_Down_Menu : Form
    {

        public Drop_Down_Menu()
        {
            InitializeComponent();
        }

        int t1 = 45;
        int t2 = 45;
        int t3 = 45;

        private void button1_MouseHover(object sender, EventArgs e)
        {
            this.panel2.Size = new Size(this.panel2.Size.Width, t2);
            this.panel3.Size = new Size(this.panel3.Size.Width, t3);
            timer1.Start();
        }

        private void button1_MouseLeave(object sender, EventArgs e)
        {
            timer1.Stop();
            t1 = 45;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (t1 > 225)
            { timer1.Stop(); }
            else
            {
                this.panel1.Size = new Size(this.panel1.Size.Width, t1);
                t1 += 5;
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            if (t2 > 225)
            { timer2.Stop(); }
            else
            {
                this.panel2.Size = new Size(this.panel2.Size.Width, t2);
                t2 += 5;
            }
        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            if (t3 > 225)
            { timer3.Stop(); }
            else
            {
                this.panel3.Size = new Size(this.panel3.Size.Width, t3);
                t3 += 5;
            }
        }

        private void button10_MouseHover(object sender, EventArgs e)
        {
            this.panel1.Size = new Size(this.panel1.Size.Width, t1);
            this.panel3.Size = new Size(this.panel3.Size.Width, t3);
            timer2.Start();
        }

        private void button10_MouseLeave(object sender, EventArgs e)
        {
            timer2.Stop();
            t2 = 45;
        }

        private void button15_MouseHover(object sender, EventArgs e)
        {
            this.panel1.Size = new Size(this.panel1.Size.Width, t1);
            this.panel2.Size = new Size(this.panel2.Size.Width, t2);
            timer3.Start();
        }

        private void button15_MouseLeave(object sender, EventArgs e)
        {
            timer3.Stop();
            t3 = 45;
        }

        private void Drop_Down_Menu_MouseHover(object sender, EventArgs e)
        {
            this.panel1.Size = new Size(this.panel1.Size.Width, t1);
            this.panel3.Size = new Size(this.panel3.Size.Width, t3);
            this.panel2.Size = new Size(this.panel2.Size.Width, t2);
        }
    }
}


=> OutPut :

drop down menu in c#
C# Drop Down Menu

C# Create a Dynamic Menu With Textboxes

C# Create a Dynamic Menu With Textboxes

C# Create a Dynamic Menu With Textboxes

                                                                                                                                                                  

in this c# tutorial we will see how to make a Dynamic Menu using TextBoxes with C# .
components used "TextBoxes"and  "timer".



an example of a single TextBox.

Project Source 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.Threading;

namespace Something
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        int t1 = 76;

private void timer1_Tick(object sender, EventArgs e)
        {
            if (t1 > 176)
            {
                timer1.Stop();
                this.textBox1.BorderStyle = BorderStyle.FixedSingle;
            }
            else
            {
                this.textBox1.Size = new Size(t1, this.textBox1.Size.Height);
                t1+=2;
            } 

        }

        private void textBox1_MouseHover(object sender, EventArgs e)
        {
            timer1.Start();
        }

private void textBox1_MouseLeave(object sender, EventArgs e)
        {
            timer1.Stop();
            t1 = 76;
            this.textBox1.Size = new Size(t1, this.textBox1.Size.Height);
            this.textBox1.BorderStyle = BorderStyle.None;
        }

private void textBox1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("something");
        }
    }
}

////////////////////////////////// END