How to disable a panel?
How to disable a panel?
Hi,
I create a PanelGadget with 5 panels. In some cases, the panel 1 and 5 should get completely deactivated or (better) hidden. Is there a way to hide or deactivate a panel? HideGadget() does not work for this case.
Kukulkan
I create a PanelGadget with 5 panels. In some cases, the panel 1 and 5 should get completely deactivated or (better) hidden. Is there a way to hide or deactivate a panel? HideGadget() does not work for this case.
Kukulkan
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
Re: How to disable a panel?
Here a quick example how to disable a panelgadget tab :It prevents the tab from being selected.
Code: Select all
Global OldCallback
;
Procedure PanelCallback(hwnd, msg, wparam, lparam)
Protected *pNMHDR.NMHDR
Static OldTab
Result = CallWindowProc_(OldCallback, hwnd, msg, wparam, lparam)
Select msg
Case #WM_NOTIFY
*pNMHDR = lparam
Select *pNMHDR\code
Case #TCN_SELCHANGING
OldTab = GetGadgetState(0) ; Tab index before change
Case #TCN_SELCHANGE
If GetGadgetState(0) = 1 ; Disabled tab index
SetGadgetState(0, OldTab)
EndIf
EndSelect
EndSelect
ProcedureReturn Result
EndProcedure
;
If OpenWindow(0, 0, 0, 300, 200, "Disable PanelGadget Tab", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
PanelGadget(0, 10, 10, 280, 180)
AddGadgetItem (0, -1, "Panel 1")
AddGadgetItem (0, -1, "Disabled")
AddGadgetItem (0, -1, "Panel 2")
CloseGadgetList()
OldCallback = SetWindowLong_(GetParent_(GadgetID(0)), #GWL_WNDPROC, @PanelCallback())
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Re: How to disable a panel?
I wish this sort of functionality could be native.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re: How to disable a panel?
I am seconding PB.
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Re: How to disable a panel?
Hi gnozal,
thank you, but is there no way without using a callback? This really should be a native PB function...
Kukulkan
thank you, but is there no way without using a callback? This really should be a native PB function...
Kukulkan
Re: How to disable a panel?
I was also wondering how to re-enable the tab?...
Creating a procedure DisablePanel(#Panel, TabNo, State) should be possible, I believe.
Creating a procedure DisablePanel(#Panel, TabNo, State) should be possible, I believe.
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Re: How to disable a panel?
Hi
Code: Select all
Global Num,OldNum,It_Flag
Procedure En_Dis_Pan(Item,It_Flag)
If Num = Item And It_Flag = 1
SetGadgetState(1,OldNum)
It_Flag = 0
Num = 0
EndIf
EndProcedure
OpenWindow(0, 0, 0, 400, 300, "A screen in a window...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
PanelGadget(1,5,5,390,290)
AddGadgetItem(1, -1, "1")
AddGadgetItem(1, -1, "2")
ButtonGadget(2, 10, 15, 80, 24,"Button 1")
ButtonGadget(3, 95, 15, 80, 24,"Button 2")
AddGadgetItem(1, -1, "3")
CloseGadgetList()
Repeat
Event = WaitWindowEvent()
If Event=#PB_Event_Gadget
Num =GetGadgetState(1)
En_Dis_Pan(1,1) ;En_Dis_Pan(Item,It_Flag(1 = Disable 2 = Enable)
Result$ = GetGadgetItemText(1, Num,0)
If Result$ = "2"
EndIf
OldNum =GetGadgetState(1)
EndIf
Until Event = #PB_Event_CloseWindow
Egypt my love
Re: How to disable a panel?
Hi RASHAD,
thank you, but your solution disallows only the selecting of the pane. This is not transparent to the user, as the pane caption is not greyed out or the complete pane is hidden. I'm shure, that some people are thinking that the program is buggy in this case...
Kukulkan
thank you, but your solution disallows only the selecting of the pane. This is not transparent to the user, as the pane caption is not greyed out or the complete pane is hidden. I'm shure, that some people are thinking that the program is buggy in this case...
Kukulkan
Re: How to disable a panel?
Excellent Rashad! I understood your idea .... and I tried to make a native PureBasic version - so far it can.
The only problem now is to make it gray so the tab is visibly disabled... but that's another step.
To enable/disable a tab dynamically, simply change the value of the array Tabs(n), and eventually activate another one.
Hope this helps.......
Code: Select all
Win=OpenWindow(#PB_Any, 0, 0, 300, 200, "Enabled and Disabled Tabs", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Panel=PanelGadget(#PB_Any, 10, 10, 280, 180)
MaxTabs=5; the number of tabs we want to create
For i=1 To MaxTabs
AddGadgetItem(Panel,-1,"Tab "+Str(i-1))
Next
CloseGadgetList()
; Create an array with the enabled or disabled tabs !At least one tab should be enabled!
Dim Tabs(4); we have 5 tabs
; and we will disable the tabs 0 and 4 as Kukulkan asked
Tabs(0)=0; disabled
Tabs(1)=1; enabled
Tabs(2)=1; enabled
Tabs(3)=1; enabled
Tabs(4)=0; disabled
; we activate the tab 1 at startup and keep it in a variable
For i=0 To MaxTabs-1
If Tabs(i)=1
ActiveTab=1
SetGadgetState(Panel,ActiveTab)
Break
EndIf
Next
Repeat
Event=WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
ExitEventLoop = #True
Case #PB_Event_Gadget
Select EventGadget()
Case Panel
Tab=GetGadgetState(Panel); Get the tab the user wants to activate
If Tabs(Tab)=0; if disabled
SetGadgetState(Panel,ActiveTab); go back to the active gadget where he was on
Else
ActiveTab=Tab; otherwise we make this one the active
EndIf
EndSelect
EndSelect
Until ExitEventLoop
End
To enable/disable a tab dynamically, simply change the value of the array Tabs(n), and eventually activate another one.
Hope this helps.......
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Re: How to disable a panel?
Update. The disabled tabs do not have a header... I have no idea how to gray them. If someone has an idea......
Code: Select all
Win=OpenWindow(#PB_Any, 0, 0, 300, 200, "Enabled and Disabled Tabs", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Panel=PanelGadget(#PB_Any, 10, 10, 280, 180)
MaxTabs=5; the number of tabs we want to create
For i=1 To MaxTabs
AddGadgetItem(Panel,-1,"Tab "+Str(i-1))
Next
CloseGadgetList()
; Create an array with the enabled or disabled tabs !At least one tab should be enabled!
Dim Tabs(MaxTabs-1); we have 5 tabs
; and we will disable the tabs 0 and 4 as Kukulkan asked
Tabs(0)=0; disabled
Tabs(1)=1; enabled
Tabs(2)=1; enabled
Tabs(3)=1; enabled
Tabs(4)=0; disabled
; we will clear the header of the disabled tabs (visual aid to the user)
For i=0 To MaxTabs-1
If Tabs(i)=0
SetGadgetItemText(Panel,i,"")
EndIf
Next
; we activate the tab 1 at startup and keep it in a variable
For i=0 To MaxTabs-1
If Tabs(i)=1
ActiveTab=1
SetGadgetState(Panel,ActiveTab)
Break
EndIf
Next
Repeat
Event=WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
ExitEventLoop = #True
Case #PB_Event_Gadget
Select EventGadget()
Case Panel
Tab=GetGadgetState(Panel); Get the tab the user wants to activate
If Tabs(Tab)=0; if disabled
SetGadgetState(Panel,ActiveTab); go back to the previous active gadget
Else
ActiveTab=Tab; otherwise we make this one the active
EndIf
EndSelect
EndSelect
Until ExitEventLoop
End
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Re: How to disable a panel?
> I have no idea how to gray them. If someone has an idea
There's already a tip on this in the forums. Just do a search.
Actually, this whole thread has been done before.
There's already a tip on this in the forums. Just do a search.
Actually, this whole thread has been done before.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re: How to disable a panel?
Revised ver
Code: Select all
Global Num,OldNum,It_Flag
Procedure En_Dis_Pan(Item,It_Flag)
If Num = Item And It_Flag = 1
SetGadgetState(1,OldNum)
It_Flag = 0
Num = 0
EndIf
EndProcedure
OpenWindow(0, 0, 0, 400, 300, "Disable Panel Tab", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
PanelGadget(1,5,5,390,250)
AddGadgetItem(1, -1, "1")
AddGadgetItem(1, -1, "2")
ButtonGadget(2, 10, 15, 80, 24,"Button 1")
ButtonGadget(3, 95, 15, 80, 24,"Button 2")
AddGadgetItem(1, -1, "3")
CloseGadgetList()
CatchImage(0, ?disable)
ImageGadget(4,44,2,42,20,ImageID(0))
SetParent_(GadgetID(4),GadgetID(1))
ButtonGadget(5, 10, 260, 80, 24,"En\Dis",#PB_Button_Toggle)
It_Flag = 1
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Q = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Num =GetGadgetState(1)
En_Dis_Pan(1,It_Flag)
OldNum =GetGadgetState(1)
Case 5
If GetGadgetState(1) = 1
SetGadgetState(1,0)
EndIf
If GetGadgetState(5) = 1
HideGadget(4,1)
It_Flag = 0
SetGadgetState(5,1)
Else
HideGadget(4,0)
It_Flag = 1
SetGadgetState(5,0)
EndIf
EndSelect
EndSelect
Until Q = 1
DataSection
disable:
Data.b 66, 77, 166, 4, 0, 0, 0, 0, 0, 0, 54, 1, 0, 0, 40, 0, 0, 0, 42, 0, 0, 0, 20, 0, 0, 0, 1, 0, 8, 0, 0, 0, 0, 0, 112, 3, 0, 0, 0, 0
Data.b 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 64, 0, 0, 0, 120, 192, 255, 255, 117, 188, 255, 255, 113, 180, 255, 255, 110, 176, 255, 255, 107, 172, 255, 255, 104, 167, 255, 255, 102, 163
Data.b 255, 255, 97, 155, 255, 255, 95, 152, 255, 255, 92, 148, 255, 255, 88, 141, 255, 255, 86, 138, 255, 255, 83, 133, 255, 255, 77, 123, 255, 255, 73, 116, 255, 255, 68, 109, 255, 255, 64, 102
Data.b 255, 255, 60, 97, 255, 255, 58, 94, 255, 255, 55, 88, 255, 255, 53, 84, 255, 255, 49, 78, 255, 255, 43, 69, 255, 255, 36, 57, 255, 255, 34, 54, 255, 255, 30, 49, 255, 255, 27, 43
Data.b 255, 255, 22, 37, 255, 255, 17, 28, 255, 255, 15, 25, 255, 255, 13, 22, 255, 255, 9, 14, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Data.b 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Data.b 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Data.b 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Data.b 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 27, 1, 27, 0, 0, 22, 6, 27, 0, 27, 1, 1, 4, 3, 25, 2, 0, 15, 12, 0, 0, 0, 0, 0, 0, 0, 0, 12, 17, 0, 0, 0, 27, 4, 23, 4, 14, 30
Data.b 24, 9, 0, 13, 22, 24, 26, 0, 26, 1, 0, 21, 7, 27, 0, 29, 23, 23, 26, 13, 27, 0, 0, 14, 12, 0, 0, 0, 0, 0, 0, 0, 0, 12, 17, 0, 0, 0, 27, 4
Data.b 23, 4, 26, 3, 1, 14, 2, 17, 0, 1, 24, 0, 30, 4, 1, 26, 4, 27, 0, 25, 4, 0, 20, 9, 21, 9, 0, 22, 12, 0, 0, 0, 0, 0, 0, 0, 0, 12, 17, 0
Data.b 0, 0, 28, 2, 23, 4, 17, 24, 26, 14, 0, 21, 25, 27, 18, 0, 28, 23, 26, 17, 0, 27, 0, 8, 26, 24, 21, 0, 7, 27, 24, 27, 12, 0, 0, 0, 0, 0, 0, 0
Data.b 0, 12, 18, 0, 0, 14, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 12, 0, 0, 0
Data.b 0, 0, 0, 0, 0, 12, 30, 27, 31, 26, 4, 0, 23, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17
Data.b 12, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 4, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0
Data.b 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Data.b 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Data.b 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Data.b 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Data.b 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Data.b 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
disableend:
EndDataSection
Egypt my love
Re: How to disable a panel?
Hehe, you've got to love Rashad's solutions. More hacks per line of code than... lines of code!
I may look like a mule, but I'm not a complete ass.
Re: How to disable a panel?
Yes native would be great to not only disable/enable but also hide/unhide ...
Re: How to disable a panel?
100% native
Code: Select all
Global Run,String$
Procedure Tab_1(Flag)
If Flag = 1
OpenGadgetList(1)
AddGadgetItem(1, 0, "1")
CloseGadgetList()
ElseIf Flag = 0
RemoveGadgetItem(1,0)
EndIf
EndProcedure
Procedure Tab_2(Flag)
If Flag = 1
OpenGadgetList(1)
AddGadgetItem(1, 1, "2")
ButtonGadget(2, 10, 15, 80, 24,"Button 1")
ButtonGadget(3, 95, 15, 80, 24,"Button 2")
StringGadget(4, 10, 55,190,24,"It is a Test")
CloseGadgetList()
If Run = 1
SetGadgetText(4,String$)
EndIf
ElseIf Flag = 0
String$ = GetGadgetText(4)
RemoveGadgetItem(1,1)
EndIf
Run = 1
EndProcedure
Procedure Tab_3(Flag)
If Flag = 1
OpenGadgetList(1)
AddGadgetItem(1, 2, "3")
CloseGadgetList()
ElseIf Flag = 0
RemoveGadgetItem(1,2)
EndIf
EndProcedure
; Procedure Tab_4(Flag)
;
; EndProcedure
OpenWindow(0, 0, 0, 400, 300, "Disable Panel Tab", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
PanelGadget(1,5,5,390,250)
Tab_1(1)
Tab_3(1)
CloseGadgetList()
UseGadgetList(WindowID(0))
ButtonGadget(5, 10, 260, 80, 24,"En\Dis",#PB_Button_Toggle)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Q = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Case 2
Debug "Gadget 2"
Case 3
Debug "Gadget 3"
Case 5
If CountGadgetItems(1) = 2 And Text$ = ""
Text$ = InputRequester("Password","Please Enter Password :","")
EndIf
If GetGadgetState(5) = 1 And Text$ ="123"
Tab_2(1)
SetGadgetState(5,1)
Else
Tab_2(0)
SetGadgetState(5,0)
EndIf
EndSelect
EndSelect
Until Q = 1
Egypt my love