C# 在循环抛出数据库c时更改突出显示的文本#

C# 在循环抛出数据库c时更改突出显示的文本#,c#,textbox,highlight,windows-applications,selectall,C#,Textbox,Highlight,Windows Applications,Selectall,对不起,我的英语不好。 我的问题是(我根本没有在网上回答) 如何从文本框中高亮显示一些文本,将其用于某些操作,然后在“翻转”到下一个数据时,将新选定的文本用于相同的操作 我的WinApp中的示例: 我正在编写一个WinApp,读取一些数据库,获取所有信息并将其存储在“列表”中 然后,我通过按钮(下一步)开始翻页,每次我这样做时,我都希望应用程序突出显示Textbox3中的文本,并按sendkey“ALT+Q”触发一些我已经构建的操作 我已经做了这个程序,但我有一个问题,当“翻转”下一个“客户”信

对不起,我的英语不好。 我的问题是(我根本没有在网上回答)

如何从文本框中高亮显示一些文本,将其用于某些操作,然后在“翻转”到下一个数据时,将新选定的文本用于相同的操作

我的WinApp中的示例: 我正在编写一个WinApp,读取一些数据库,获取所有信息并将其存储在“列表”中 然后,我通过按钮(下一步)开始翻页,每次我这样做时,我都希望应用程序突出显示Textbox3中的文本,并按sendkey“ALT+Q”触发一些我已经构建的操作

我已经做了这个程序,但我有一个问题,当“翻转”下一个“客户”信息页面时,程序会突出显示其电话号码,并发送键“ALT+Q”。。。但是当它触发acction时,它会执行WinAPP在程序开始时选择的第一个数字的命令。一些帮助请求? 我将发布我的表单类(小编码)

表单加载:

private void Empcalls_Load(object sender, EventArgs e)
    {
        OpenFileDialog OpenFile = new OpenFileDialog();
        if (OpenFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            MainDB = new DataTable();
            Dbop = new Classes.DbConnection();
            rList = new List<int>();
            int num = 0;
            Random ran = new Random();
            string filepath = OpenFile.FileName;
             MainDB = Dbop.CustomerData(filepath);
             for (int i = 0; i < MainDB.Rows.Count-1; i++)
             {
                 do { num = ran.Next(0, (MainDB.Rows.Count-1)); } while (rList.Contains(num));
                 rList.Add(num);
             }
             textBox1.Text = MainDB.Rows[rList[mainindex]]["שם name"].ToString();
             textBox2.Text = MainDB.Rows[rList[mainindex]]["שם lastName"].ToString();
             if (MainDB.Rows[rList[mainindex]]["phone"].ToString().Replace("-", "")=="")
                 textBox3.Text = MainDB.Rows[rList[mainindex]]["phone2"].ToString().Replace("-", "");
             else
                textBox3.Text = MainDB.Rows[rList[mainindex]]["טלפון נייד"].ToString().Replace("-","");
             currNum = textBox3.Text;
             mainindex++;
             System.Threading.Thread.Sleep(1000);
             textBox3.SelectAll();
             SendKeys.Send("%(q)");


         }

    }
**每次我点击“下一步”,甚至程序都会突出显示新的textbox3值,当我发送“ALT+q”时,第一个突出显示的信息上的acctoine accure不会改变


thanx

这并不能完全回答您的问题,但指出“如果您的应用程序打算与各种键盘一起在国际上使用,那么使用Send可能会产生不可预测的结果,应该避免。”

也就是说,尝试使用Application.DoEvents()而不是Sleep

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;

namespace TestFormFieldCycle
{
    public partial class Form1 : Form
    {
        List<string> rList = new List<string>();
        int mainIndex = 0;

        public Form1()
        {
            InitializeComponent();
            for (int i = 0; i < 100; i++)
            {
                int areaCode = 0;
                int phone1 = 0;
                int phone2 = 0;
                String phoneNumber = String.Empty;
                do
                {
                    Random r = new Random();
                    areaCode = r.Next(0, 999);
                    phone1 = r.Next(0, 999);
                    phone2 = r.Next(0, 9999);
                    phoneNumber = String.Format("({0:000}) {1:000}-{2:0000}", areaCode, phone1, phone2);
                } while (rList.Contains(phoneNumber));
                rList.Add(phoneNumber);
            }
        }

        void renderAndCaptureText1()
        {
            textBox1.Text = rList[mainIndex].ToString();
            string currentPhoneNumber = textBox1.Text;
            mainIndex++;
            textBox1.Focus();
            textBox1.SelectAll();
            SendKeys.Send("^(c)");
            Application.DoEvents();
            textBox2.Focus();
            textBox2.Clear();
            SendKeys.Send("^(v)");
            Application.DoEvents();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            renderAndCaptureText1();
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
使用系统线程;
命名空间TestFormFieldCycle
{
公共部分类Form1:Form
{
List rList=新列表();
int main index=0;
公共表格1()
{
初始化组件();
对于(int i=0;i<100;i++)
{
国际区号=0;
int phone1=0;
int phone2=0;
String phoneNumber=String.Empty;
做
{
随机r=新随机();
区号=r.Next(0999);
phone1=r.Next(0999);
phone2=r.Next(099999);
phoneNumber=String.Format(({0:000}){1:000}-{2:0000}),区域码,phone1,phone2);
}while(rList.Contains(phoneNumber));
rList.Add(电话号码);
}
}
无效renderAndCaptureText1()
{
textBox1.Text=rList[main index].ToString();
字符串currentPhoneNumber=textBox1.Text;
mainIndex++;
textBox1.Focus();
textBox1.SelectAll();
SendKeys.Send(“^(c)”);
Application.DoEvents();
textBox2.Focus();
textBox2.Clear();
SendKeys.Send(“^(v)”);
Application.DoEvents();
}
私有无效按钮1\u单击(对象发送者,事件参数e)
{
renderAndCaptureText1();
}
}
}

我做了更改,删除了加载和按钮代码中的所有选择键和发送键,并创建了一个函数“Call()”——哦,别忘了Focus()。没有工作,我已经调试了问题,我看到了一件奇怪的事情。如果我通过键盘上的“CTRL+A”选择文本,选择不起作用,我必须使用鼠标选择数字/文本,然后它就起作用了,就像鼠标一样,现在我在搜索如何通过“crouser”选择文本而不真正使用我的鼠标在文本框中确认CTRL+A,你会想注册这样的按键处理程序(在设计器文件中或通过texbox1属性):textbox1.KeyDown+=new System.Windows.Forms.KeyEventHandler(this.textbox1_KeyDown);…然后将代码添加到类文件:private void textbox1_KeyDown(object sender,KeyEventArgs e){if(e.Control&e.KeyCode==Keys.A)textbox1.SelectAll()}……但我们偏离主题了。我想知道控件的属性是否会冲突。请从designer.cs文件中粘贴textbox1、textbox2和textbox3的代码段,好吗?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;

namespace TestFormFieldCycle
{
    public partial class Form1 : Form
    {
        List<string> rList = new List<string>();
        int mainIndex = 0;

        public Form1()
        {
            InitializeComponent();
            for (int i = 0; i < 100; i++)
            {
                int areaCode = 0;
                int phone1 = 0;
                int phone2 = 0;
                String phoneNumber = String.Empty;
                do
                {
                    Random r = new Random();
                    areaCode = r.Next(0, 999);
                    phone1 = r.Next(0, 999);
                    phone2 = r.Next(0, 9999);
                    phoneNumber = String.Format("({0:000}) {1:000}-{2:0000}", areaCode, phone1, phone2);
                } while (rList.Contains(phoneNumber));
                rList.Add(phoneNumber);
            }
        }

        void renderAndCaptureText1()
        {
            textBox1.Text = rList[mainIndex].ToString();
            string currentPhoneNumber = textBox1.Text;
            mainIndex++;
            textBox1.Focus();
            textBox1.SelectAll();
            SendKeys.Send("^(c)");
            Application.DoEvents();
            textBox2.Focus();
            textBox2.Clear();
            SendKeys.Send("^(v)");
            Application.DoEvents();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            renderAndCaptureText1();
        }
    }
}