Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/132.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何自动跳转到下一个&x201C;TEdit&x201D;当我使用c++;建设者_C++_C++builder - Fatal编程技术网

C++ 如何自动跳转到下一个&x201C;TEdit&x201D;当我使用c++;建设者

C++ 如何自动跳转到下一个&x201C;TEdit&x201D;当我使用c++;建设者,c++,c++builder,C++,C++builder,我想实现一个许可证功能。我使用五个TEdit控件,以及如何在输入完成后自动跳转到下一个TEdit 试试这样的方法: class TMyForm : public TForm { __published: TEdit *Edit1; TEdit *Edit2; TEdit *Edit3; TEdit *Edit4; TEdit *Edit5; void __fastcall EditChange(TObject *Sender); private:

我想实现一个许可证功能。我使用五个
TEdit
控件,以及如何在输入完成后自动跳转到下一个
TEdit

试试这样的方法:

class TMyForm : public TForm
{
__published:
    TEdit *Edit1;
    TEdit *Edit2;
    TEdit *Edit3;
    TEdit *Edit4;
    TEdit *Edit5;
    void __fastcall EditChange(TObject *Sender);
private:
    TEdit *Edits[5];
    int __fastcall IndexOf(TEdit *Edit);
public:
    __fastcall TMyForm(TComponent *Owner);
}

\uu快速调用TMyForm::TMyForm(TComponent*Owner)
:t表格(所有者)
{
编辑[0]=Edit1;
编辑[1]=编辑2;
编辑[2]=Edit3;
编辑[3]=编辑4;
编辑[4]=编辑5;
}
int uu fastcall TMyForm::IndexOf(TEdit*编辑)
{
对于(int i=0;i<5;++i)
{
如果(编辑[i]==编辑)
返回i;
}
返回-1;
}
//将此单一OnChange事件处理程序分配给5个TEdit控件。。。
void\uu fastcall TMyForm::EditChange(TObject*Sender)
{
TEdit*ThisEdit=静态\u转换(发送方);
如果(ThisEdit->GetTextLen()>=ThisEdit->MaxLength)
{
int idx=IndexOf(此编辑);
如果(idx!=-1)
{
if(idx<4)
编辑[idx+1]->SetFocus();
其他的
OK按钮->SetFocus();//或在最后一次输入后要执行的任何操作。。。
}   
}
}
或者:

__fastcall TMyForm::TMyForm(TComponent *Owner)
    : TForm(Owner)
{
    Edit1->Tag = reinterpret_cast<NativeInt>(static_cast<TControl*>(Edit2));
    Edit2->Tag = reinterpret_cast<NativeInt>(static_cast<TControl*>(Edit3));
    Edit3->Tag = reinterpret_cast<NativeInt>(static_cast<TControl*>(Edit4));
    Edit4->Tag = reinterpret_cast<NativeInt>(static_cast<TControl*>(Edit5));
    Edit5->Tag = 0; // or whatever control you want focused after the last input...
}

// assign this single OnChange event handler to the 5 TEdit controls...
void __fastcall TMyForm::EditChange(TObject *Sender)
{
    TEdit *ThisEdit = static_cast<TEdit*>(Sender);
    if (ThisEdit->GetTextLen() >= ThisEdit->MaxLength)
    {
        TControl *NextControl = reinterpret_cast<TControl*>(ThisEdit->Tag);
        if (NextControl)
            NextControl->SetFocus();
        else
            // whatever you want to do after the last input...
    }
}
// configure the tab stops on the TEdit (and other controls) as desired,
// and assign this single OnChange event handler to the 5 TEdit controls...
void __fastcall TMyForm::EditChange(TObject *Sender)
{
    TEdit *ThisEdit = static_cast<TEdit*>(Sender);
    if (ThisEdit->GetTextLen() >= ThisEdit->MaxLength)
        SelectNext(ThisEdit, true, true);
}
\uu快速调用TMyForm::TMyForm(TComponent*Owner)
:t表格(所有者)
{
Edit1->Tag=reinterpret_cast(静态_cast(Edit2));
Edit2->Tag=reinterpret_cast(静态_cast(Edit3));
Edit3->Tag=reinterpret_cast(静态_cast(Edit4));
Edit4->Tag=reinterpret_cast(静态_cast(Edit5));
Edit5->Tag=0;//或在最后一次输入后要聚焦的任何控件。。。
}
//将此单一OnChange事件处理程序分配给5个TEdit控件。。。
void\uu fastcall TMyForm::EditChange(TObject*Sender)
{
TEdit*ThisEdit=静态\u转换(发送方);
如果(ThisEdit->GetTextLen()>=ThisEdit->MaxLength)
{
t控制*NextControl=reinterpret\u cast(此编辑->标记);
如果(NextControl)
NextControl->SetFocus();
其他的
//在最后一次输入后,无论您想做什么。。。
}
}
或者:

__fastcall TMyForm::TMyForm(TComponent *Owner)
    : TForm(Owner)
{
    Edit1->Tag = reinterpret_cast<NativeInt>(static_cast<TControl*>(Edit2));
    Edit2->Tag = reinterpret_cast<NativeInt>(static_cast<TControl*>(Edit3));
    Edit3->Tag = reinterpret_cast<NativeInt>(static_cast<TControl*>(Edit4));
    Edit4->Tag = reinterpret_cast<NativeInt>(static_cast<TControl*>(Edit5));
    Edit5->Tag = 0; // or whatever control you want focused after the last input...
}

// assign this single OnChange event handler to the 5 TEdit controls...
void __fastcall TMyForm::EditChange(TObject *Sender)
{
    TEdit *ThisEdit = static_cast<TEdit*>(Sender);
    if (ThisEdit->GetTextLen() >= ThisEdit->MaxLength)
    {
        TControl *NextControl = reinterpret_cast<TControl*>(ThisEdit->Tag);
        if (NextControl)
            NextControl->SetFocus();
        else
            // whatever you want to do after the last input...
    }
}
// configure the tab stops on the TEdit (and other controls) as desired,
// and assign this single OnChange event handler to the 5 TEdit controls...
void __fastcall TMyForm::EditChange(TObject *Sender)
{
    TEdit *ThisEdit = static_cast<TEdit*>(Sender);
    if (ThisEdit->GetTextLen() >= ThisEdit->MaxLength)
        SelectNext(ThisEdit, true, true);
}
//根据需要配置TEdit(和其他控件)上的制表位,
//并将这个OnChange事件处理程序分配给5个TEdit控件。。。
void\uu fastcall TMyForm::EditChange(TObject*Sender)
{
TEdit*ThisEdit=静态\u转换(发送方);
如果(ThisEdit->GetTextLen()>=ThisEdit->MaxLength)
选择下一步(ThisEdit,true,true);
}

分享你的研究成果对每个人都有帮助。告诉我们您尝试了什么,以及为什么它不能满足您的需求。这表明你花了时间来帮助自己,它使我们避免重复显而易见的答案,最重要的是,它帮助你得到一个更具体和相关的答案!另见: