TPageControl inactive/locked TTabSheet lazarus / 31-LCL ---------------------------------------------------------------------- chrnobel · 2013-10-26 17:13 Is it possible to make a TTabSheet inactive, but still having it visible, so that it is not possible to click on the TabSheet, and having the TabSheets caption grayed out to clearly show that it is not accessible. The only way to make the tab active/unlock it is could then for instance be by pushing a button. /Christian ---------------------------------------------------------------------- Avishai · 2013-10-26 17:42 TPageControl.Enabled:= False But it does not show it grayed out.  It look the same but can't be used.  You might be able to play around with the OnPaint event to change it's looks. ---------------------------------------------------------------------- chrnobel · 2013-10-26 18:04 Quote from: Avishai on October 26, 2013, 07:42:21 pmTPageControl.Enabled:= FalseThis just disables the entire PageControl, it wasn't exactly that I wanted. What I want is to be able to edit etc. in one page (tabsheet), but making it impossible to leave that particular page until I have finished editing - so until I press ok it is not possible to select any other tab. The graying out is a minor issue, but more to illustrate the similarity. /Christian ---------------------------------------------------------------------- Avishai · 2013-10-26 18:12 I see.  Well, each TabSheet has an Enabled property but it doesn't keep you from moving to that TabSheet.  There is an OnExit event for each sheet so you might be able to set PageControl.ActivePage back to the one you want, but I haven't tried it. ---------------------------------------------------------------------- Avishai · 2013-10-26 18:23 It looks like the TabSheet.OnExit is not fired.  But I tried TPageControl.OnChange and was able to lock it to the TabSheet I wanted. ---------------------------------------------------------------------- wp · 2013-10-26 18:28 Use "OnChanging" instead of "OnExit", it has a parameter "AllowChange". ---------------------------------------------------------------------- chrnobel · 2013-10-27 16:46 Quote from: wp on October 26, 2013, 08:28:32 pmUse "OnChanging" instead of "OnExit", it has a parameter "AllowChange". Thank you, it does exactly what I want. Now I can lock, so it is not possible to leave the tab, and I can then change the font color of the inactive tab like this: TabSheet1.Font.Color:=clGray; ---------------------------------------------------------------------- flaza · 2013-11-27 18:14 I had the same problem and I like the TPageControl.OnChange. But changing the font.color of the tabsheet doesn't change the color of the caption. How about you. Did you solve that problem? ---------------------------------------------------------------------- chrnobel · 2013-11-28 09:01 Quote from: flaza on November 27, 2013, 07:14:35 pmI had the same problem and I like the TPageControl.OnChange. But changing the font.color of the tabsheet doesn't change the color of the caption. How about you. Did you solve that problem? To me it seems like a Windows problem, as it is possible under Linux - I am also looking for a solution to this problem: http://forum.lazarus.freepascal.org/index.php/topic,22518.msg133021.ht ml#msg133021 ---------------------------------------------------------------------- asdf · 2014-08-12 08:02 Can you please teach me to lock TabSheet1, TabSheet3 and only TabSheet2 is enabled using OnChanging? ---------------------------------------------------------------------- howardpc · 2014-08-12 08:35 This does what you want, though it is rather inflexible as written. Code: [Select]procedure TForm1.PageControl1Changing(Sender: TObject; var AllowChange: Boolean); var   pc: TPageControl;   i: Integer; begin   if not (Sender is TPageControl) then     Exit;   pc:=TPageControl(Sender);   for i:=0 to pc.PageCount-1 do     if (i=1) then // this hard codes 1 as the unlocked tabsheet - not very flexible       pc.Pages[i].Enabled:=True     else pc.Pages[i].Enabled:=False; end; ---------------------------------------------------------------------- asdf · 2014-08-12 09:20 Dear chrnobel, Below codes is OK, Code: [Select]PageControl1.Pages[1].Enabled:=True; PageControl1.Pages[0].Enabled:=False; // TabSheet0 PageControl1.Pages[2].Enabled:=False; // TabSheet2 But PageControl1.Pages[0] and PageControl1.Pages[2] can be selected. What is the best codes to lock and do not let the user to leave PageControl1.Pages[1] and cannot select neither PageControl1.Pages[0] nor PageControl1.Pages[2] ? ---------------------------------------------------------------------- howardpc · 2014-08-12 12:38 You could add an OnEnter event handler, as well as an OnChanging handler as follows. However, I see no point myself in having tabsheets whose contents cannot be seen and which cannot be moved to. Code: [Select]procedure TForm1.PageControl1Changing(Sender: TObject; var AllowChange: Boolean); var   pc: TPageControl;   i: Integer; begin   if not (Sender is TPageControl) then     Exit;   pc:=TPageControl(Sender);   AllowChange:=pc.ActivePageIndex<>1;   for i:=0 to pc.PageCount-1 do     if (i=1) then       pc.Pages[i].Enabled:=True     else       pc.Pages[i].Enabled:=False; end; procedure TForm1.PageControl1Enter(Sender: TObject); var   pc: TPageControl; begin   if not (Sender is TPageControl) then     Exit;   pc:=TPageControl(Sender);   if (pc.ActivePageIndex<>1) then     pc.ActivePageIndex:=1; end; ---------------------------------------------------------------------- asdf · 2014-08-13 03:45 OMG !!! That is absolutely great. And can you please help find the way to fade the font color of the inactive TabSheet(s) in order to make user concentrate on only the active TabSheet ? ---------------------------------------------------------------------- howardpc · 2014-08-13 08:28 The only part of an inactive tabsheet that is visible is the tab (actually part of the pagecontrol). Here you are at the mercy of your current widgetset/platform. I don't know any cross-platform way to redraw the tabs in different colours, which is not to say there isn't a way - just that I can't help you with that. A custom-drawn pagecontrol could offer that. ---------------------------------------------------------------------- asdf · 2014-08-13 08:33 ---------------------------------------------------------------------- Blaazen · 2014-08-13 08:46 QuoteA custom-drawn pagecontrol could offer that.Recently here was one. I don't know if it do what you need, I myself didn't try. http://forum.lazarus.freepascal.org/index.php/topic,24666.msg148964.ht ml#msg148964