h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

Rename File or folder in C#.net

1) Rename a File in C#.net
string path = @"C:\Documents and Settings\Narayanan\My Documents\Others\Txt\test\";
string Orgifile = path + "\\Test.txt";
string Renamefile = path + "\\Test1.txt";
File.Move(Orgifile, Renamefile);
2) Rename a Folder in C#.net
string path = @"C:\Documents and Settings\Narayanan\My Documents\Others\Txt";
string OriFolder = path + "\\test";
string RenameFolder = path + "\\Test1.txt";
Directory.Move(OrgiFolder, RenameFolder);

Collections in C#.net

What is mean by Collections?
Collections contain number of classes to required for storing group of related objects.
What are the Collections Classes?
1) Array List
2) Queue
3) Stack
4) StringCollection
5) BitArray
1) Array List:
Can Store any type of object.
Expand to any required capacity
2) Queue:
First in First Out (FIFO) Collection.
On messaging server to store messages temp before Processing
3) Stack:
Last in First Out (LIFO) Collection.
Stack to track change so that the most recent change can be undone.
4) StringCollection:
Like ArrayList, except values are strongly typed as a strings.
Does not support Sorting.
5) BitArray:
A collection of Boolean values.
ArrayList:
Now, we discussed about How to use Arraylist.Add Method in C#.net?
Using System.Collections
ArrayList ArrayLst = new ArrayList ()
ArrayLst.Add("Hello");
ArrayLst.Add ("World");
foreach (Object Obj in ArrayLst)
Console.WriteLine (Obj.Tostring ())
Output:
Hello World

Basic steps for creating a program in .Net

Introduction:
  This article may be considered as a guide for wirting programs in any .net Language. So Please read this article read carefully .If you want any suggestions and Comments to this Mail ID:irnaraayanan@yahoo.com
File Name:
   What is the entire file names created at the time of Project?
In C#.net
 File Name (Suffix):   .cs .
Usage:                        It is a Class File
File Name (Suffix):   .csproj.
Usage:                        It is a Project File
In VB.net
 File Name (Suffix):   .vb .
Usage:                        It is a Class File
File Name (Suffix):   .vbproj.
Usage:                        It is a Project File
IN ASP.Net
File Name (Suffix):   .aspx .
Usage:                        It is a ASP.Net File
File Name (Suffix):   .ascx.
Usage:                        User Defined Control in ASP.Net
File Name (Suffix):   .asmx.
Usage:                        Web service in ASP.Net
 File Name (Suffix):   .sln.
Usage:                        .Net Solution File
Common File Names in .net

  • Machine.config
  • App.config
  • Web.config
  • Assemble.vb
  • Global.asax
File Layout:
   Each .net Source file will contain only one Public class. When private classes and interfaces are associated within Public class. Here I give the example  for File Layout.

Class Name: Test
File Name: Test.cs

Class layout:
   Class/Interface Header comments
Nested Types
Object Declaration
Constructors
Properties
Methods
Method Layout:
   Method Commets
Local variable Declaration
Code
Declarations variables should be meaningful and related your Project .Don't declare single letter like (a, b).
Blank Lines:
   One blank line should always be used between
Methods,
Properties
Local variable in the Method and it's a first statement.
Class names must be nouns or nouns phrase
Use Properties spelled Plural Form to a name Collection Class.
Use Pascal Casing.
Do not use any class prefix
Use Singular names for Enum.
Use plural names for bit field.
Use the Char "I" as a prefix to indicate that the type is an Interface.
Use the Char "m_" as a prefix to indicate that the Module variable
Use the Char "l_" as a prefix to indicate that the Local variable
Name Methods with verbs or verb phrase.
Pascal Casing : First char of the word is capital  .Ex: MyCount
Camel Casing : First char of the word is capital except  the first one  .Ex: myCount

Back color for MDI in C#.net

MdiClient ctlMDI;
            foreach (Control ctl in this.Controls)
            {
                try
                {
                   ctlMDI = (MdiClient)ctl;
                    ctlMDI.BackColor = Color.Yellow;
                }
                catch (InvalidCastException exc)
                {
                    MessageBox.Show(exc.Message);
                }
            }
            }

Form will open by pressing the Enter key or Space Bar

KeyPreview = true 

Resize ComboBox in C#.net

private void cmbwidth(ComboBox cmb)
        {
            System.Drawing.Graphics g = cmb.CreateGraphics();
            float maxwidth = 0f;
            foreach (object o in cmb.Items)
            {
                float w = g.MeasureString(o.ToString(), cmb.Font).Width;
                if (w > maxwidth)
                    maxwidth = w;
            }
            g.Dispose();
            cmb.Width = (int)maxwidth + 20;
        }

Count of repeated characters in String in C#.net

Function/ Method:
public static int countofrepeatedchar(string inputstring, char ch)
        {
            char[] Inputstring = inputstring.ToCharArray();
            char Ch = ch;
            int cntofchar = Inputstring.Length;
                foreach (char chr in Inputstring)
                {
                    if (chr == Ch)
                    {
                        result++;
                    }
       
            }


            return result;
        }

int res = countofrepeatedchar("123456123",'4');
            MessageBox.Show(res.ToString());

Square Root Calculation in C#.Net

Declaration part:
public static string strvalue;


public static stringres;

Function/Method:
#region Square Root 
      public static string  squareRoot(double fv, double sv)
      {
          double Result;
         
          for (int idx = 1; idx < sv+1; idx++)
          {
              if (idx == 1)
              {
                  Result = Math.Pow(fv, idx);
                  res = Convert.ToString(Result);
              }
              else if (idx >  1)
              {
                  Result = Math.Pow(fv, idx);
                  res = res  + "," + Convert.ToString(Result);
              }
          }
          strvalue =res;
          return strvalue;
      }
      #endregion Square Root
 
Call function in Your Application : 
string str = squareRoot(2, 10);
MessageBox.Show(str);
 

Font names in Combobox using C#.Net

Declaration Part:


Using System.Drawings.Text





Code for getting font name into ComboBox :

InstalledFontCollection inst = new InstalledFontCollection();
            foreach (FontFamily fnt in inst.Families)
            {
                comboBox1.Items.Add(fnt.Name);
            }







Tooltip for TextBox

Tooltip for TextBox -- Coding  
private void textBox1_TextChanged(object sender, EventArgs e)
{
  if (textBox1.Text != "")
  {
     string str = textBox1.Text;
     toolTip1.Show(str, textBox1, 1, 10);
  }
  else
 {
   toolTip1.Hide(textBox1);
 }
}