Mega Code Archive

 
Categories / Delphi / VCL
 

Preventing changing pages in a page control

Question: How do I prevent the change of a page in a TPageControl? Answer: uses CommCtrl; procedure TForm1.PageControl1Changing(Sender: TObject; var AllowChange: Boolean); var Info : TTCHitTestInfo; P : TPoint; idx : Integer; begin GetCursorPos(P); Info.pt := (Sender as TPageControl).ScreenToClient(P); Info.flags := TCHT_ONITEM; idx := SendMessage((Sender as TPageControl).Handle,TCM_HITTEST,0,Integer(@Info)); Caption := 'idx = '+IntToStr(idx); end; // Of course, you'd set AllowChange to False given certain // values of idx, instead of setting the Caption...