Bug with SelectNextControl

Topics related to the Krypton Toolkit.

Moderators: Phil Wright, Chris Porter

Bug with SelectNextControl

Postby Troopers » Fri Jul 30, 2010 5:52 pm

Hi,

The method SelectNextControl of the base class control doesn't work with the Krypton Toolkit controls.
I have created a form with a Krypton panel with the dock property to Fill
Then add this code :
Code: Select all
   public partial class Form1
   {
      public Form1()
      {
         InitializeComponent();

         // Create a textbox
         KryptonTextBox ktbTextBox = new KryptonTextBox();
         ktbTextBox.Name = "Control1";
         ktbTextBox.Text = "";
         ktbTextBox.Location = new System.Drawing.Point(3, 20);
         ktbTextBox.KeyDown += new KeyEventHandler(TextBox_KeyDown);
         ktbTextBox.TabIndex = 1;
         kpPanel.Controls.Add(ktbTextBox);

         ktbTextBox = new KryptonTextBox();
         ktbTextBox.Name = "Control2";
         ktbTextBox.Text = "";
         ktbTextBox.Location = new System.Drawing.Point(3, 60);
         ktbTextBox.KeyDown += new KeyEventHandler(TextBox_KeyDown);
         ktbTextBox.TabIndex = 2;
         kpPanel.Controls.Add(ktbTextBox);

         ktbTextBox = new KryptonTextBox();
         ktbTextBox.Name = "Control3";
         ktbTextBox.Text = "";
         ktbTextBox.Location = new System.Drawing.Point(3, 100);
         ktbTextBox.KeyDown += new KeyEventHandler(TextBox_KeyDown);
         ktbTextBox.TabIndex = 3;
         kpPanel.Controls.Add(ktbTextBox);
      }

      /// <summary>
      /// Occurs on control key down
      /// </summary>
      /// <param name="sender">Event sender</param>
      /// <param name="e">Event arguments</param>
      private void TextBox_KeyDown(object sender, KeyEventArgs e)
      {
         // If it's the ENTER key
         if(e.KeyCode == System.Windows.Forms.Keys.Enter)
         {
            // Get the current control
            KryptonTextBox cControl = ((KryptonTextBox)sender);
            // Set focus on the next control, so perform the validating event on the current control
            cControl.Parent.SelectNextControl(cControl, true, true, false, false);
            
         }
      }
   }


The focus must pass to the next control when ENTER is pressed, It doesn't work
If i replace KryptonTextBox by TextBox, it works
Troopers
 
Posts: 8
Joined: Fri Apr 02, 2010 10:03 pm

Re: Bug with SelectNextControl

Postby Phil Wright » Thu Aug 05, 2010 3:18 pm

The complication is that the KryptonTextBox, along with some of the other Toolkit controls, the actual KryptonTextBox is just a container that has inside it a standard TextBox for the text drawing. So when you SelectNextControl specifies False for the nesting of controls it means it will not find that embedded TextBox inside the KryptonTextBox itself. Hence the problems you have. I have added a TextBox and a KryptonTextBox to a form and found the following settings would then work for it...

Code: Select all
        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == System.Windows.Forms.Keys.Enter)
            {
                TextBox cControl = ((TextBox)sender);
                cControl.Parent.SelectNextControl(cControl, true, true, true, false);
            }
        }

        private void kryptonTextBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == System.Windows.Forms.Keys.Enter)
            {
                KryptonTextBox cControl = ((KryptonTextBox)sender);
                cControl.Parent.SelectNextControl(cControl.TextBox, true, true, true, false);
            }
        }
Phil Wright
Site Admin
 
Posts: 2720
Joined: Thu Apr 13, 2006 2:55 pm
Location: Melbourne, Australia

Re: Bug with SelectNextControl

Postby Troopers » Mon Aug 23, 2010 6:47 pm

Ok, thanks, It's work
Troopers
 
Posts: 8
Joined: Fri Apr 02, 2010 10:03 pm


Return to Krypton Toolkit

Who is online

Users browsing this forum: Google [Bot] and 0 guests