Board index » cppbuilder » Need help with TEdit

Need help with TEdit


2003-07-20 12:18:52 PM
cppbuilder72
I have a TEdit that is being used to modify a TLabel, so when the user
double-clicks on the TLabel the TEdit is shown to edit what the TLabel will
display. And when the enter key is pressed it will modify the TLabel and
hide, but the problem is that when the enter key is pressed I get a BEEP!
and I don't want that, so is there any way to prevent the beep sound?
Thanks!
 
 

Re:Need help with TEdit

Ok there does seem to also be a focus problem now, because when the TEdit is
shown after the TLabel has been double-clicked.
It does not have the focus, the focus remains on the previous control, I
have tried using the Focused() function with no luck.
Here is my code:
void __fastcall TEditProfile::ProfileDisplayDblClick(TObject *Sender)
{
// Show the 'EditProfileName' to allow the user to edit the name.
EditProfileName->Visible = true;
EditProfileName->Focused();
EditProfileName->SelectAll();
// The focus does not change to 'EditProfileName', Why?
}
Thanks!
 

Re:Need help with TEdit

"oLiVeS" < XXXX@XXXXX.COM >wrote:
Quote
[...] but the problem is that when the enter key is pressed
I get a BEEP! and I don't want that
You need to intercept the Key (VK_RETURN) before it gets
processed by the Edit and zero it out:
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
if( Key == VK_RETURN ) Key = 0;
}
Or, in the alternative, set the forms' KeyPreview property to
true and add an OnKeyDown event for the form:
void __fastcall TForm1::FormKeyPress(TObject *Sender, char &Key)
{
if( ActiveControl == Edit1 && Key == VK_RETURN ) Key = 0;
}
~ JD
 

{smallsort}

Re:Need help with TEdit

"oLiVeS" < XXXX@XXXXX.COM >wrote:
Quote
Ok there does seem to also be a focus problem now, [...]

EditProfileName->Focused();
Change it to:
EditProfileName->SetFocus();
~ JD
 

Re:Need help with TEdit

Thanks for your help JD.
Everything is working fine now.