简体   繁体   English

如何在C ++ Builder中通过单个函数更改10 Edit控件的颜色

[英]How Can Change color of 10 Edit control by single function in c++ builder

我想在进入编辑时以及从编辑退出时更改编辑控件的颜色,我想通过单个功能做到这一点,我不想在输入事件或退出事件中为每次编辑添加代码

yes like David and kobik said you just need to create event handlers for OnEnter and OnExit and assign the controls you wish to use them 是的,就像David和kobik所说的那样,您只需要为OnEnter和OnExit创建事件处理程序并分配要使用的控件即可

for example 例如

Add two TEdit's to your form and in the constructor of the form do the following 在窗体中添加两个TEdit,并在窗体的构造函数中执行以下操作

__fastcall TTestForm::TTestForm(TComponent* Owner)
    : TForm(Owner)
{
    Edit1->OnEnter = EditEnter;
    Edit2->OnEnter = EditEnter;

    Edit1->OnExit = EditExit;
    Edit2->OnExit = EditExit;
}

Now Create the Enter and Exit event handlers like so 现在像这样创建Enter和Exit事件处理程序

void __fastcall TTestForm::EditEnter(TObject *Sender)
{
    TEdit *Temp = (TEdit*)Sender;
    Temp->Color = clRed;
}

void __fastcall TTestForm::EditExit(TObject *Sender)
{
    TEdit *Temp = (TEdit*)Sender;
    Temp->Color = clGreen;
}

Thats it. 而已。

Write OnEnter and OnExit event handlers and assign them to each control. 编写OnEnter和OnExit事件处理程序,并将它们分配给每个控件。 Use the Sender parameter to the event to identify which control the event applies to. 对事件使用Sender参数来标识事件应用于哪个控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM