Click here to Skip to main content
15,891,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,

I want to create a TextBox control where the user can input text in DevNagri. I Have written a Text Box Control class, the code is shown below. I have overridden the ProcessCmdKey Message. However, sometimes it works and sometimes it simply hangs.

I am unable to find the reason for this weird behavior.

Any help is greatly appreciated.

C#
public partial class CHindiEdit : TextBox
   {
       private Font m_font;
       private int m_nSize;
       private string m_strText;
       public CHindiEdit()
       {
           m_nSize = 12;
           InitializeComponent();
       }
       public int HindiFontSize
       {
           get { return m_nSize; }
           set
           {
               m_nSize = value;
               this.Font = new Font("Lucida Sans Unicode", m_nSize);
           }
       }
       public CHindiEdit(IContainer container)
       {
           container.Add(this);
           this.FontChanged += new EventHandler(HindiEdit_OnFontChanged);
           InitializeComponent();
       }
       private void HindiEdit_OnFontChanged( object o, EventArgs e )
       {
           if (m_nSize < 10) m_nSize = 10;
           m_font = new Font("Lucida Sans Unicode", m_nSize);
           this.Font = m_font;
       }
       protected override bool ProcessCmdKey(ref System.Windows.Forms.Message m, System.Windows.Forms.Keys k)
       {
           int nHCode  = 0x906;
           bool bGot = GetHindiCode(m, k, ref nHCode ) ;
           if (bGot)
           {
               char chVal = (char)nHCode;
               string strChar = "" + chVal + "";
               System.Windows.Forms.SendKeys.Send(strChar);
               return true;
           }
           // if not pushing Enter Key, then process the signal as usual
           return base.ProcessCmdKey(ref m, k);
       }
       bool GetHindiCode(Message m, Keys k, ref int nHCode )
       {
           if (m.Msg == 256)
           {
               switch (k)
               {
                   case System.Windows.Forms.Keys.A: nHCode = 0x906; break;
                   case System.Windows.Forms.Keys.B: nHCode = 0x907; break;
                   case System.Windows.Forms.Keys.C: nHCode = 0x908; break;
                   case System.Windows.Forms.Keys.D: nHCode = 0x909; break;
                   case System.Windows.Forms.Keys.E: nHCode = 0x90A; break;
                   case System.Windows.Forms.Keys.F: nHCode = 0x90B; break;
                   case System.Windows.Forms.Keys.G: nHCode = 0x90C; break;
                   case System.Windows.Forms.Keys.H: nHCode = 0x90D; break;
                   case System.Windows.Forms.Keys.I: nHCode = 0x90E; break;
                   default: nHCode = 0x906; break;
               }
               return true;
           }
           return false ;
       }
   } 
Posted
Updated 18-Mar-11 0:22am
v2
Comments
Sergey Alexandrovich Kryukov 18-Mar-11 18:50pm    
Do you mean Devangari script; or I did not understand you?
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900