C#


   C#(C- Sharp)
      =================
 Defination :- It is a kind of .net compatiable, Object Oriented, Event driven programming language.

C# = C + C++  + VB + Java

* C# is the mother language of .net
* Windows 2003 --- written in c#
*C# is highly case sensitive programming lang.
Class name/ package name / function name --->first letter in  uppercase
            Second word ka first chr in Uppercase

C# programming :-

1)Console Programming

Write in notepad and run at command prompt

2)Windows Programming

Visual studio.net


=============================================================
Console Programming :-

How :-
1) Open notepad
Rules :-
  a) Save the file with any name(unlike java ) with extension .cs


2) Command prompt (.net wala)

c:\>csc a.cs
c:\>a (to run)



Software for .NET :- Visual studio.net 2008 / 2005
Framework :-
 Framework 1.0 - Visual studio.net 2000
 Framework 1.1 - Visual studio.net 2003
 Framework 2.0 - Visual studio.net 2005
 Framework 3.0 - Visual studio.net 2008
 Framework 3.5 - Visual studio.net 2008
          Framework 4.0 - Visual studio.net 2010

Developer pc:- Visual studio.net 2008
client pc:- only framework(free download)

 

 C# Windows Programming
==========================
Terms:-
 1. Solution:- Collection of project
 2. project :- collection of module
 3. module :- Fundamental unit of project
  types of modules:-
1. Form(Visible)
2. class(for class and object)

A PROJECT CAN CONTAIN MULTIPLE MODULES
A SOLUTION CAN CONATIN MULTIPLE PROJECT

 4. TOOLBOX :- COLLECTION OF CONTROLS.
 5. CONTROLS :- GRAPHICAL REPRESENTATION OF OBJECT.
eg: BUTTON / TEXTBOX / CHECKBOX/RADIOBUTTON/LISTBOX
TYPES OF CONTROLL :-
1. STANDARD CONTROLL:-
VISIBLE IN TOOOLBOX
2. ACTIVEX CONTROLL
THIRD PARTY , USER DEFINED
FROM OTHER SOURCE

6. PROPERTY WINDOW :-
IT CONTAIN THE LIST OF PROPERTIES ASSOCIATED WITH CONTROLL(BUTTON) OR CONTAINER(FORM)
HOW TO SEE:-SELECT ITEM-RC-PROPERTY WINDOW
(RCP)
EG:- BACKCOLOR/FORECOLOR/TEXT/NAME
7. DESIGN TIME :- WHEN WE ARE DESIGING THE FORM.
TO CHANEG THE PROPERTY IN DESIGN TIME
WE USE PROPERTY WINDOW

8. RUN TIME :- WHEN WE ARE RUNNING THE FORM.
TO CHANGE PROPERTY IN RUN TIME:-
CODING..

9. SOLTUION EXPLORER :- TREE LIKE STRUCTURE FOR SOLUTION,  PROJECT AND FOMRS

  TO RUN :- F5

PROPERTY(RCP):-
=============
NAME : FOR INDETIFICATION
TEXT : FOR DISPLAY
BACKCOLOR: FOR BACKCOLOR
FORECOLOR :- FOR FORECOLOR
FONT :- FOR FONT
FORM PROPERTY :
WINDOW START POSITION : CENTER SCREEN
WINDOW STATE : MAXIMIZE
OPACITY : FOR VISIBILITY(BY DEFAULT 100%)
FORMBORDERSTYLE : BY DEFAULT SIZABLE
: NONE
BACKGROUND IMAGE:
BACKGROUND IMAGE LAYOUT: TILE/STRECH


 private void Form1_Load(object sender, EventArgs e)
        {
            this.BackColor = Color.Red;
            this.Text = "jai siya ram";
            button1.Text = "okkkk";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.BackColor = Color.Purple;  
        }


For Display :-
=================
MessageBox.Show("Prompt", "title", MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);      


===================================
To exit after click on button:-
==================================
DialogResult drs = new DialogResult();
        private void button1_Click(object sender, EventArgs e)
        {
            drs=MessageBox.Show("Want to exit ??", "Exit Window", MessageBoxButtons.OKCancel, MessageBoxIcon.Stop);    
            //this.Close(); //Individual form
            //Application.Exit();
            if (drs.ToString() == "OK")
            {
                System.Environment.Exit(0);
            }
        }


Textbox(add/subtract)
=======================
work as your image draw:
Three text box / Three label/ two button
=========================================
private void button1_Click(object sender, EventArgs e)
        {
            int n =Int32.Parse(txtNumber1.Text);
            int m = Int32.Parse(txtNumber2.Text);
            int sum = n + m;
            txtresult.Text = sum.ToString();  
          
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int n = Int32.Parse(txtNumber1.Text);
            int m = Int32.Parse(txtNumber2.Text);
            int sum = n - m;
            txtresult.Text = sum.ToString();
        }


property :- maxlength/readonly


tooltip :-
=========
Select toltip from toolbox.
select controll -rcp- tooltip on tooltip1

//balnk not allowed
        private void txtNumber1_Leave(object sender, EventArgs e)
        {
            if (txtNumber1.Text == "")
            {
                MessageBox.Show("Blank not allowed");
                txtNumber1.Focus();
            }
        }
        //To allow digit only
        private void txtNumber1_KeyPress(object sender, KeyPressEventArgs e)
        {
            //TO GET ASCII VALUE OF ANY CHR.
            //MessageBox.Show(Convert.ToInt32(e.KeyChar).ToString());    
            //to allow backspace
            if (Convert.ToInt32(e.KeyChar).ToString() != "8")
            {
                if (Char.IsDigit(e.KeyChar) == false)
                {
                    MessageBox.Show("Only digit allowed");
                    e.Handled = true;
                }
            }
            //h.w. :- decimal allowed
        }

String handling:-
====================
//String handling :-
        private void Form1_Load(object sender, EventArgs e)
        {
            string nm = "Agile SOFTECH PVT. LTD.";
            //MessageBox.Show(nm.ToLower());
            //MessageBox.Show(nm.ToUpper());
            //MessageBox.Show(nm.Replace(".", ""));
            //MessageBox.Show(nm.Replace("A", "S"));
            //MessageBox.Show(nm.Substring(3, 5)); //TO PICK THE CHR FROM SPECIFIC POSITION AND SPECIFIC NUMBER
            ////3RD POSTION SE- 5 CHR
            //MessageBox.Show(nm.IndexOf("E").ToString());  
            ////Indexof : first occurance search , return position(int) , position start - 0
            //MessageBox.Show(nm.IndexOf("E",7).ToString());
            ////Indexof : first occurance search , return position , position start - 7
            //MessageBox.Show(nm.LastIndexOf("E").ToString());
            ////LastIndexOf : last occurance search , return position , position start - 0
            //////Q : display AGILE only from above string
            ////MessageBox.Show(nm.Substring(0,nm.IndexOf(" ")));  
            //////Q : Display all the chr after .
            ////MessageBox.Show(nm.Substring(nm.IndexOf(".")+1));  
            //////Display the length :-
            ////MessageBox.Show(nm.Length.ToString());
            //////Split function :For break or split
            ////string nm1 = "01/04/2009";
            //////output :- 01-April-2009
            ////string[] dt;
            ////dt = nm1.Split('/');
            //////MessageBox.Show(dt[0]); //01
            //////MessageBox.Show(dt[1]); //04
            //////MessageBox.Show(dt[2]); //2009
            ////string mon="";
            ////if (dt[1] == "04")
            ////{
            ////    mon = "April";
            ////}
            ////if (dt[1] == "03")
            ////{
            ////    mon = "March";
            ////}
            ////MessageBox.Show(dt[0] + "-" + mon + "-" + dt[2]);

            string[] nms = nm.Split(' ');
            ////foreach (string k in nms)
            ////{
            ////    MessageBox.Show(k);
            ////}
            if (nms[0].ToUpper() == "AGILE")
            {
                MessageBox.Show("thanks");
            }
            string nm9=" Santosh ";
            string nm8=" Kumar ";
            if (nm9.Trim() == "Santosh")
            {
                MessageBox.Show("Barabar hai");
            }
            //trim is used to remove the space from  both side
            //ltrim :- left
            //rtrim :- right

            //Summary :-
            /*
             * 1. search : indexof /lastindexof
             * 2. value to pick : substring
             * 3. braek : split
             * 4. replace : replace
             * 5. compare : case (convert it in lower or upper ) and use trim)
             */
 
   MessageBox.Show("\"" + "santosh" + "\"");//"santosh"
            MessageBox.Show("\'" + "santosh"); //'santosh
            MessageBox.Show("san" + "\\" + "tosh"); ; //san\tosh
            //display in two line
            MessageBox.Show("the name is " + "\n" + "santosh");
              


Q 1 :- nm :- Amit Kuamr pandey
     output :- A.K.Pandey
  2 :- nm :- Rajiv's kumar laxman's
     output :- Rajivs Kumar laxmans

  3.:- nm :- the man of actions
     output :- The Man Of Actions
  4.:- nm :- "NOON"
     out put :- pal in drome
       nm= "abc"
     out put :- not pal in drome
  5.nm=Rajiv 3000 987654321
     output :- Name: Rajiv
      Salary:3000
               Mobile no: 987654321


==============================================================
Ans:-
private void Form1_Load(object sender, EventArgs e)
        {
            string nm = "the man of action";
            string[] sp = nm.Split(' ');
            string nm1 = "";
            foreach (string k in sp)
            {
                nm1 = nm1 + k.Substring(0, 1).ToUpper() + k.Substring(1)+" ";
            }
            MessageBox.Show(nm1);
        }



 //eg:- NM :- Ram Lakahn Singh yadav : R.L.S.Yadav
        public string initial(string nm)
        {
            string[] nm1 = nm.Split(' ');
            string nm2 = "";
            foreach (string k in nm1)
            {
                nm2 = nm2 + k.Substring(0, 1)+".";
            }
            nm2 = nm2.Substring(0, nm2.Length - 2);
            nm2 = nm2 + nm1[nm1.Length - 1];
            return nm2;
        }
        public string uppercase(string nm)
        {
            string[] sp = nm.Split(' ');
            for(int i=0;i<sp.Length;i++)
            {
                sp[i] = sp[i].Substring(0, 1).ToUpper() + sp[i].Substring(1);    
            }
            string nm1="";
            foreach (string k in sp)
            {
                nm1 = nm1 + " " + k;
                  
            }
            return nm1;
          
        }
        public string palindrome(string nm)
        {
            string rev="";
            for (int i = 0; i < nm.Length; i++)
            {
                rev = nm.Substring(i, 1) + rev;
            }
            if (rev == nm)
            {
                return "pal in drom";
            }
            else
            {
                return "not pal in drome";
            }
      
        }
        //Rajiv 3000 987654321
        public void fnformat(string nm)
        {
            string[] nm1 = nm.Split(' ');
            MessageBox.Show("Name :"+nm1[0]+"\n"+"Salary :"+nm1[1]+"\n"+"Mobile Number:"+nm1[2]);
        }



======================================================================
Collection :-
================
it is just like array , but always dynamic and can hold any values
unlike array. (Static/ Same data type value)
1. Hastable:
   //hastable is a kind of collection having two values.
            //1. key (id) 2. item (value)
            Hashtable hs = new Hashtable();
            hs.Add("a", "santosh");
            hs.Add("b", 5556);
            hs.Add("c", "agile");
            hs.Add("d", "gzb");
            //MessageBox.Show(hs["c"].ToString());  
            foreach (string k in hs.Keys)
            {
                MessageBox.Show(hs[k].ToString());
            }

2. Arraylist :
   //Key not required, index : 0 like array
   ArrayList hs = new ArrayList();
            hs.Add("santosh");
            hs.Add("5556");
            hs.Add("agile");
            hs.Add("gzb");
            MessageBox.Show(hs[0].ToString());  
            foreach (string k in hs)
            {
                MessageBox.Show(k.ToString());
            }

====================================
Controll collections:-Collections of controlls.
====================================
        FORM_LOAD()
{
   foreach (Control ctl in this.Controls)
            {
                if (ctl is TextBox)
                {
                    ctl.BackColor = Color.Red;  
                }
                else if (ctl is Button)
                {
                    ctl.BackColor = Color.Blue;
                }
                else
                {
                    ctl.BackColor = Color.Orange;
                }
            }
         }  
      
//COUNT NUMBER OF CONTROLS IN FORM:-
MessageBox.Show(this.Controls.Count.ToString());
==================================================================

Controlls :-
===============
1. linklabel:- Work as hyperlink
property : text / activelinkcolor

     System.Diagnostics.Process.Start("www.yahoo.com");
   linkLabel1.LinkVisited = true;
            linkLabel1.VisitedLinkColor = Color.Green;  
            //System.Diagnostics.Process.Start("c:\\a.txt");
            //System.Diagnostics.Process.Start("c:\\untitled.bmp");

2. colordialogue:-To show dialogue of color:
Pick colordialogue from toolbar:
private void button1_Click(object sender, EventArgs e)
        {
            colorDialog1.ShowDialog();
            this.BackColor = colorDialog1.Color;
        }
3. Please pick Richtextbox, Colordialogue, font dialogue , openfiledialogue
 
  Button ke click per ye code :-

private void button1_Click(object sender, EventArgs e)
        {
             openFileDialog1.ShowDialog();
             richTextBox1.LoadFile(openFileDialog1.FileName,RichTextBoxStreamType.PlainText);
             colorDialog1.ShowDialog();
             richTextBox1.ForeColor = colorDialog1.Color;
             fontDialog1.ShowDialog();
             richTextBox1.Font = fontDialog1.Font;  
        }

4.To chnage the color randomly:-
Random r = new Random();
        private void button2_Click(object sender, EventArgs e)
        {
             this.BackColor = Color.FromArgb(r.Next(255), r.Next(100), r.Next(255));
        }

5. Timer :- Use to keep the track of time
Timer : property :
1. Enable
2. interval:- 1000 (1 sec)
code:-
Random r = new Random();
        private void timer1_Tick(object sender, EventArgs e)
        {
           label1.Text = System.DateTime.Now.ToLongTimeString();
           this.BackColor = Color.FromArgb(r.Next(200), r.Next(100), r.Next(200));    
        }

use of progressbar:-pick progressbar and code on timer:
=====================
private void timer1_Tick(object sender, EventArgs e)
        {
            progressBar1.Value = progressBar1.Value + 5;
            if (progressBar1.Value == progressBar1.Maximum)
            {
                timer1.Enabled = false;  
            }
        }

or,

Progressbar-RCP- Style=marquee.


===================================================================
6. listbox(Only list) and comboBox(listbox+textbox)
======================================================
To add item:-
RCP-ITEM- ADD
coding:-
listBox1.Items.Add("hahahahha");
or,
comboBox1.Items.Add("tatatattaa");

private void comboBox1_SelectedIndexChanged()
        {
             MessageBox.Show(comboBox1.Items.Count.ToString());
            //MessageBox.Show(comboBox1.SelectedItem.ToString());    
   this.BackColor = Color.FromName(comboBox1.SelectedItem.ToString());
        }
PROPERTY :-DROPDOWNSTYLE
SIMPLE,DROPDOWN,DROPDOWNLIST

TO REMOVE THE VALUE:-
====================
BUTTON CLICK:-

      comboBox1.Items.RemoveAt(comboBox1.SelectedIndex);    
            comboBox1.Items.Remove(comboBox1.SelectedItem.ToString());


7.DOMAINUpDown :- LIKE LISTBOX OR COMBOBOX:
private void Form1_Load(object sender, EventArgs e)
        {
            domainUpDown1.Items.Add("I01");
            domainUpDown1.Items.Add("I02");
            domainUpDown1.Items.Add("I03");
            domainUpDown1.SelectedIndex = 0;
        }
        private void domainUpDown1_SelectedItemChanged(object sender, EventArgs e)
        {
            MessageBox.Show(domainUpDown1.SelectedItem.ToString());    
        }

===================================================
1. DATETIMEPICKER :- TO GET DATE CALANDER AND TIME

 FORMAT :- BY DEFAULT :- LONG
SHORT (MM/DD/YYYY)

CUSTOME (FOR CUSTOMIZE):- DD/MM/YYYY
custome format :- dd/MM/yyyy
time :for time
show updown : true
========================================
to pick the value from datetimepicker:-

   string txt=dateTimePicker1.Text;
            MessageBox.Show(txt);
            MessageBox.Show(dateTimePicker1.Value.ToString() );


2.F1Help provider :- To provide help after click F1
===================
 help provider -- select controll one by one - RCP- Help string on
 help provider1

To see help button on form:-
Help button : true
Minimize =false
maximize=false

3. errorprovider :-
private void textBox1_Leave(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                errorProvider1.SetError(textBox1, "Blank not allowed");
                textBox1.Focus();
            }
            else
            {
                errorProvider1.Dispose();
            }
        }


***Extender property :- Extends by controll...

 Tooltip / Helpprovider / errorprovider


 Anchor :- THE GAP BETWEEN THE EDGE OF CONTROLL AND THE EDGE OF CONTAINER
CONTROLL :- ANCHOR :- TOP,LEFT
     BOTTOM RIGHT

 DOCKING :- POSITIOING OF CONTROLL :
BY DEFAULT NORMALLY :- NONE
TOP,BOTTOM ,LEFT,RIGHT

==>CURSOR:- FORM-RCP-CURSOR..
  USER DEFINED CURSOR:
SOLUTION EXPLORER :-SELECT PROJECT - RC- ADD -ADD NEW ITEM
-- CUSROR - KALAKARI --SAVE AS (C:\,D:\)

private void Form1_Load(object sender, EventArgs e)
        {
            this.Cursor = new Cursor("C:\\CURSOR1.CUR");
        }
==BITMAP :- SOLUTION EXPLORER :-SELECT PROJECT - RC- ADD -ADD NEW ITEM
-- BITMAP - KALAKARI --SAVE AS (C:\,D:\)

FORM-RCP-BACK GROUND IMAGE..

===ICON :- SOLUTION EXPLORER :-SELECT PROJECT - RC- ADD -ADD NEW ITEM
-- ICON - KALAKARI --SAVE AS (C:\,D:\)
FORM-RCP-ICON..




 

   

Comments

Popular posts from this blog

C# Connectivity with MySql Server..