Saturday, July 30, 2011

C Sharp

Like so many things in .NET, this turned out to be easy - as long as you know how to do it.


Following effective thirty line grid code will show all the Tamil letters, and can select and make a text:




using System;
using System.Windows.Forms;
using System.Drawing;

public class dataGrid:Form {

   public static void Main() {
      Application.Run(new dataGrid());
      Application.Exit();
   } 

   DataGridView datagrid = new DataGridView();
   TextBox text = new TextBox();
      
   public dataGrid() {          
       
      int i,j;
      String[] UCodeValues = {
         " ","அ","ஆ","இ","ஈ","உ","ஊ","எ","ஏ","ஐ","ஒ","ஓ","ஔ",
         "க்","க","கா","கி","கீ","கு","கூ","கெ","கே","கை","கொ","கோ","கௌ",
         "ங்","ங","ஙா","ஙி","ஙீ","ஙு","ஙூ","ஙெ","ஙே","ஙை","ஙொ","ஙோ","ஙௌ",
         "ச்","ச","சா","சி","சீ","சு","சூ","செ","சே","சை","சொ","சோ","சௌ",
         "ஞ்","ஞ","ஞா","ஞி","ஞீ","ஞு","ஞூ","ஞெ","ஞே","ஞை","ஞொ","ஞோ","ஞௌ",
         "ட்","ட","டா","டி","டீ","டு","டூ","டெ","டே","டை","டொ","டோ","டௌ",
         "ண்","ண","ணா","ணி","ணீ","ணு","ணூ","ணெ","ணே","ணை","ணொ","ணோ","ணௌ",
         "த்","த","தா","தி","தீ","து","தூ","தெ","தே","தை","தொ","தோ","தௌ",
         "ந்","ந","நா","நி","நீ","நு","நூ","நெ","நே","நை","நொ","நோ","நௌ",
         "ப்","ப","பா","பி","பீ","பு","பூ","பெ","பே","பை","பொ","போ","பௌ",
         "ம்","ம","மா","மி","மீ","மு","மூ","மெ","மே","மை","மொ","மோ","மௌ",
         "ய்","ய","யா","யி","யீ","யு","யூ","யெ","யே","யை","யொ","யோ","யௌ",
         "ர்","ர","ரா","ரி","ரீ","ரு","ரூ","ரெ","ரே","ரை","ரொ","ரோ","ரௌ",
         "ல்","ல","லா","லி","லீ","லு","லூ","லெ","லே","லை","லொ","லோ","லௌ",
         "வ்","வ","வா","வி","வீ","வு","வூ","வெ","வே","வை","வொ","வோ","வௌ",
         "ழ்","ழ","ழா","ழி","ழீ","ழு","ழூ","ழெ","ழே","ழை","ழொ","ழோ","ழௌ",
         "ள்","ள","ளா","ளி","ளீ","ளு","ளூ","ளெ","ளே","ளை","ளொ","ளோ","ளௌ",
         "ற்","ற","றா","றி","றீ","று","றூ","றெ","றே","றை","றொ","றோ","றௌ",
         "ன்","ன","னா","னி","னீ","னு","னூ","னெ","னே","னை","னொ","னோ","னௌ",
         "ஜ்","ஜ","ஜா","ஜி","ஜீ","ஜு","ஜூ","ஜெ","ஜே","ஜை","ஜொ","ஜோ","ஜௌ",
         "ஷ்","ஷ","ஷா","ஷி","ஷீ","ஷு","ஷூ","ஷெ","ஷே","ஷை","ஷொ","ஷோ","ஷௌ",
         "ஹ்","ஹ","ஹா","ஹி","ஹீ","ஹு","ஹூ","ஹெ","ஹே","ஹை","ஹொ","ஹோ","ஹௌ",
         "ஸ்","ஸ","ஸா","ஸி","ஸீ","ஸு","ஸூ","ஸெ","ஸே","ஸை","ஸோ","ஸோ","ஸௌ",
         "ஃ",""+(char)3021,""+(char)3006,""+(char)3007,""+(char)3008,
         ""+(char)3009,""+(char)3010,""+(char)3014,""+(char)3015,
         ""+(char)3016,""+(char)3018,""+(char)3019,""+(char)3020,"ஸ்ரீ",
         ",",".",";",":","?","!","(",")","-"," "," "," "," ",
         "0","1","2","3","4","5","6","7","8","9"," "," "," " 
      };

      int ncol = 26, nrow = 13;
      int cellht = 20, cellwdth = 35;
      datagrid.ColumnCount = ncol;
      datagrid.RowCount = nrow;
      for (j=0; j<datagrid.ColumnCount;j++) {
      datagrid.Columns[j].Width = cellwdth;
      datagrid.Columns[j].ReadOnly = true;
      datagrid.Columns[j].Resizable = DataGridViewTriState.False;
      for (i=0; i<datagrid.RowCount;i++) {
         if (j==0) datagrid.Rows[i].Height = cellht;
         if (j==0) datagrid.Rows[i].ReadOnly = true;
         if (j==0) datagrid.Rows[i].Resizable = DataGridViewTriState.False;
         if (j*nrow+i < UCodeValues.Length) 
            datagrid[j,i].Value = UCodeValues[j*nrow+i];
         }
      }
      datagrid.ColumnHeadersVisible = false;
      datagrid.RowHeadersVisible = false;
      datagrid.Click += new EventHandler(datagrid_click);
      this.Text = "தமிழ் எழுத்துக்கள்";
      this.Size = new Size(ncol*cellwdth+30,(nrow+3)*cellht+40+25);
      this.Location = new Point(100,50);
      this.StartPosition = FormStartPosition.Manual;
      this.FormBorderStyle = FormBorderStyle.Sizable;
      //this.CancelButton = buttonExit;
      this.MaximizeBox = false;
      this.MinimizeBox = false;
      text.Size = new Size(10*cellwdth,cellht);
      text.Location = new Point((int)(1.75*cellwdth),(int)(1.5*cellht));
      datagrid.Size = new Size(ncol*cellwdth+3,nrow*cellht+3);
      datagrid.Location = new Point(5,this.Height-datagrid.Height-43);
      this.Controls.Add(text);
      this.Controls.Add(datagrid);
      this.Show();
   }

   private void datagrid_click(object sender, EventArgs e) {
      text.Text += (String)datagrid.CurrentCell.Value;
   }

}





You need csharp compiler to compile the code obviously. You can download the compiler from MicroSoft site, which is free for non-commercial use. Save this code in a .cs file (file named with extension .cs). Compile typing: csc <name>.cs in a command prompt window. Run typing just <name> .