I have code for working enter key press as a tab but it lost keypress enter control
code is
if (e.KeyCode == Keys.Enter)
{
//If so, it gets the next control and applies the focus to it
nextControl = GetNextControl(ActiveControl, !e.Shift);
if (nextControl == null)
{
nextControl = GetNextControl(null, true);
}
nextControl.Focus();
//Finally - it suppresses the Enter Key
e.SuppressKeyPress = true;
}
}
I want enter key as tab but without loosing events
theLizardPosted Jul 8, 2015, 10:23 PM
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MoveNext
{
public partial class Form1 : Form
{
Control[] container = new Control[0];
Control[] sorted = new Control[0];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
findControls();
}
private void findControls()
{
for (int i = 0; i < this.Controls.Count; i++)
{
if (this.Controls[i].Tag.ToString().Length > 0 )
{
Array.Resize(ref container, container.Count() + 1);
container[container.Count() - 1]= this.Controls[i];
}
}
int j;
for (int i = 0; i < container.Count(); i++)
{
j = i + 1;
for (int k = 0; k < container.Count(); k++)
{
if (container[k].Tag.ToString() == j.ToString())
{
Array.Resize(ref sorted, sorted.Count() + 1);
sorted[sorted.Count() - 1] = container[k];
break;
}
}
}
container = sorted;
Array.Resize(ref sorted, 0);
}
private void CtrlKeyDown(object sender, KeyEventArgs e)
{
int i = 0;
Control c = (Control)sender;
if (e.KeyCode == Keys.Enter)
{
if (c.Text.Length > 0)
{
int.TryParse(c.Tag.ToString(), out i);
container[i].Focus();
}
}
}
}
}
Upendra Pratap ShahiPosted Jun 8, 2015, 5:20 AM
san sanPosted Jun 8, 2015, 5:08 AM