Board index » cppbuilder » No OnkeyDown event for TPageControl? Any alternatives?

No OnkeyDown event for TPageControl? Any alternatives?


2004-09-18 01:30:50 AM
cppbuilder22
Hi
I am making an application in which user can create new Buttons,
PageControls, Labels, Panels, GroupBoxes etc.
One of the features I want is allow the user to move the
controls up, down, left, and right by using respective keys on
on the keyboard.
I also want to allow user to change the size of the controls
using those keys when combined with the Shift key.
Here's my function. Please not that it is NOT complete. This
is just something simple I wrote. MyActiveControl is the ptr to
the Active control in my application among labels, panels,
buttons, groupboxes, and pagecontrols (and tabsheets).
The function works for labels, panels, gropboxes, and buttons,
it doesn't work for PageControl. When a PageControl is
"MyActiveControl" and up, down etc keys are pressed, my function
never gets called. the function is named FormKeyDown and it is
assigned to the Form's OnKeyDown event.
If labels, buttons, pagecontrols, groupboxes, etc all had
OnKeyDown event, then I would assign the function to all the
controls OnKeyDown event, but since that is not the case, I had
to use this route.
questions is: HOW can I get PageControl to act like the other
controls such as label, button, Panel etc.
Here's my simple function:
void __fastcall TChildForm::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if(!MyActiveControl || (MyActiveControl == this))
{
return;
}
if (Key == VK_UP)
{
if(MyActiveControl->Top>= 4)
{
MyActiveControl->Top -= 4;
}
}
if (Key == VK_DOWN)
{
if(Shift.Contains(ssShift))
{
if(MyActiveControl->ClassNameIs("TLabel") || MyActiveControl->ClassNameIs("TTabSheet") )
{
return;
}
MyActiveControl->Height += 4;
}
else if(MyActiveControl->Top + MyActiveControl->Height + 4 <= MyActiveControl->Parent->Height)
{
MyActiveControl->Top += 4;
}
}
if (Key == VK_LEFT)
{
if(MyActiveControl->Left>= 4)
{
MyActiveControl->Left -= 4;
}
}
if (Key == VK_RIGHT)
{
if(Shift.Contains(ssShift))
{
if(MyActiveControl->ClassNameIs("TLabel") || MyActiveControl->ClassNameIs("TTabSheet") )
{
return;
}
MyActiveControl->Width += 4;
}
else if(MyActiveControl->Left + MyActiveControl->Width + 4 <= MyActiveControl->Parent->Width)
{
MyActiveControl->Left += 4;
}
}
PutFrame(MyActiveControl);
}
//---------------------------------
any way to achieve my goal? Your help will be much appreciated
thanks,
Veebo
 
 

Re:No OnkeyDown event for TPageControl? Any alternatives?

give your form focus, put it's ActiveControl property to NULL. On top of my
head, TForm is the only TWinControl descendant
wich makes key and mouse wheel events accessable (so i would go for the form
also).
AinO
"Veebo" < XXXX@XXXXX.COM >wrote in message
Quote

Hi

I am making an application in which user can create new Buttons,
PageControls, Labels, Panels, GroupBoxes etc.

One of the features I want is allow the user to move the
controls up, down, left, and right by using respective keys on
on the keyboard.

I also want to allow user to change the size of the controls
using those keys when combined with the Shift key.

Here's my function. Please not that it is NOT complete. This
is just something simple I wrote. MyActiveControl is the ptr to
the Active control in my application among labels, panels,
buttons, groupboxes, and pagecontrols (and tabsheets).

The function works for labels, panels, gropboxes, and buttons,
it doesn't work for PageControl. When a PageControl is
"MyActiveControl" and up, down etc keys are pressed, my function
never gets called. the function is named FormKeyDown and it is
assigned to the Form's OnKeyDown event.

If labels, buttons, pagecontrols, groupboxes, etc all had
OnKeyDown event, then I would assign the function to all the
controls OnKeyDown event, but since that is not the case, I had
to use this route.

questions is: HOW can I get PageControl to act like the other
controls such as label, button, Panel etc.

Here's my simple function:

void __fastcall TChildForm::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if(!MyActiveControl || (MyActiveControl == this))
{
return;
}

if (Key == VK_UP)
{
if(MyActiveControl->Top>= 4)
{
MyActiveControl->Top -= 4;
}
}

if (Key == VK_DOWN)
{
if(Shift.Contains(ssShift))
{
if(MyActiveControl->ClassNameIs("TLabel") ||
MyActiveControl->ClassNameIs("TTabSheet") )
{
return;
}
MyActiveControl->Height += 4;
}
else if(MyActiveControl->Top + MyActiveControl->Height + 4 <=
MyActiveControl->Parent->Height)
{
MyActiveControl->Top += 4;
}
}

if (Key == VK_LEFT)
{
if(MyActiveControl->Left>= 4)
{
MyActiveControl->Left -= 4;
}
}

if (Key == VK_RIGHT)
{
if(Shift.Contains(ssShift))
{
if(MyActiveControl->ClassNameIs("TLabel") ||
MyActiveControl->ClassNameIs("TTabSheet") )
{
return;
}
MyActiveControl->Width += 4;
}
else if(MyActiveControl->Left + MyActiveControl->Width + 4 <=
MyActiveControl->Parent->Width)
{
MyActiveControl->Left += 4;
}
}

PutFrame(MyActiveControl);

}
//---------------------------------

any way to achieve my goal? Your help will be much appreciated

thanks,
Veebo
 

Re:No OnkeyDown event for TPageControl? Any alternatives?

Hi Aino
I'm sorry, but I really don't understand what your suggestion
is.
can you please be more clear. I'll appreciate it.
thanks,
Veebo
Quote
give your form focus, put it's ActiveControl property to NULL. On top of my
head, TForm is the only TWinControl descendant
wich makes key and mouse wheel events accessable (so i would go for the form
also).

AinO
 

{smallsort}

Re:No OnkeyDown event for TPageControl? Any alternatives?

Veebo,
Take a look at this link about subclassing TPageControl. May be
helpful...
groups.google.com/groups&lr=&ie=UTF-8&selm=3788ED00.EFE24E34%40cornell.edu
Regards,
Bruce