Thanks,
Sean Smith
When the CheckBox is actually clicked by the mouse or keyboard, it
sends it Parent the BN_CLICK notification in the form of a WM_COMMAND
message. You can derive a simple component from TCheckBox, look for
the CN_COMMAND message (WM_COMMAND's 'echo' that's sent to the CheckBox
itself), then fire a notify event (OnTrueClick) in response to the
BN_CLICK notification. From there, simply place all your OnClick code
in the OnTrueClick event handler, and you won't have to worry about it
firing when the Checked property is changed. The component will save
you time in the long run. Here's a simple example...
// in header...
class TMyCheckBox : public TCheckBox
{
private:
TNotifyEvent FOnTrueClick;
void __fastcall CNCommand(TMessage &Msg);
protected:
public:
__fastcall TMyCheckBox(TComponent* Owner);
__published:
__property TNotifyEvent OnTrueClick =
{read = FOnTrueClick, write = FOnTrueClick};
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(CN_COMMAND, TMessage, CNCommand)
END_MESSAGE_MAP(TCheckBox)
};
// in source...
void __fastcall TMyCheckBox::CNCommand(TMessage &Msg)
{
TCheckBox::Dispatch(&Msg);
if (HIWORD(Msg.WParam) == BN_CLICKED)
{
if (FOnTrueClick) FOnTrueClick(this);
}
}
Good luck!
Damon
>Is there anyway to change a TCheckBox state without having it firing the
>OnClick event?
No, but you can unwire the event:
CurrentOnClick = CheckBox->OnClick;
CheckBox->OnClick = 0;
...
CheckBox->OnClick = CurrentOnClick;
--
General information:
* Post to the right group - http://www.borland.com/newsgroups/
* Do not cross- or multipost
* Research at http://www.mers.com/searchsite.html
Stefan Hoffmeister - http://www.econos.de/
TeamB - http://www.teamb.com/
Thanks again,
Sean Smith