PB 5.2 Dialog

Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
Andreas21
Beiträge: 390
Registriert: 30.08.2004 09:05
Computerausstattung: Desktop
Windows 10 Pro x64
CPU: AMD Ryzen 5 2600 3.40 GHz
Ram: 16GB RAM
Grafik: NVIDA Geforce 1060
PB: 5.72 X86/X64
Wohnort: Heidelberg

PB 5.2 Dialog

Beitrag von Andreas21 »

Code: Alles auswählen

Define Dialog, Xml, Button

;<option text="option 1" .... onevent="CheckBoxEvent()"/>
Runtime Procedure CheckBoxEvent() 
  Debug "Option 1 clicked!"
EndProcedure

Xml = LoadXML(#PB_Any, "ui.xml")
If IsXML(Xml)
  If XMLStatus(Xml) = #PB_XML_Success
    Dialog = CreateDialog(#PB_Any)
    
    ;<window .... name="hello"
    If OpenXMLDialog(Dialog, Xml, "hello") 
      
      ;<window id="0"
      HideWindow(0, #False)
      
      ;<button text="Ole 2" name="button"/>
      Button = DialogGadget(Dialog,"button") 
      If IsGadget(Button)
        Repeat
          Event = WaitWindowEvent()
          Select Event
              
            Case #PB_Event_Gadget
              Select EventGadget()
                Case Button
                  Debug "Button Ole 2 clicked!"
              EndSelect
          EndSelect
          
        Until Event = #PB_Event_CloseWindow
      EndIf
    Else
      Debug "Dialog creation error: " + DialogError(Dialog)
    EndIf
  Else
    Debug "XML error on line " + XMLErrorLine(Xml) + ": " + XMLError(Xml)
  EndIf
EndIf
ui.xml

Code: Alles auswählen

<?xml version="1.0"?>

<!-- Window -->
<window id="0" name="hello" text="Window" label="TestDialog" width="320" height="10" flags="#PB_Window_SizeGadget|#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget">
   <splitter width="300" height="500">
     <hbox>
      <checkbox name="checkbox1" text="Run only one Instance" disabled="yes" Flags=""/>
      <progressbar text="Vrey vreyv rye"/>
      <trackbar text="Ole" invisible="no" Flags="#PB_TrackBar_Ticks" width="150"/>
      <option text="option 1" name="option1" onevent="CheckBoxEvent()"/>
      <option text="option 2"/>
     </hbox>
     <vbox>
      <listview text="option 3" height="50"/>
      <button text="Ole 2" name="button"/>
      <listicon text="option 4" height="50"/>
      <string text="string content"/>
      <editor text="editorgadget" height="50"/>
      <text text="Text gadget"/>
     </vbox>     
   </splitter>
</window>
Vorlage von Fred http://www.purebasic.fr/english/viewtop ... 14&t=54999
Windows 10 x64 Pro - PB 5.61 X64 / x32 - PB 4.6 x32
Benutzeravatar
Kiffi
Beiträge: 10715
Registriert: 08.09.2004 08:21
Wohnort: Amphibios 9

Re: PB 5.2 Dialog

Beitrag von Kiffi »

hier mit BindGadgetEvent():

Code: Alles auswählen

Define Dialog, Xml, Button

;<option text="option 1" .... onevent="CheckBoxEvent()"/>
Runtime Procedure CheckBoxEvent() 
  Debug "Option 1 clicked!"
EndProcedure

;<button text="Ole 2" name="button"/>
Procedure Button_LeftClick()
  Debug "Button Ole 2 clicked!"
EndProcedure

Xml = LoadXML(#PB_Any, "ui.xml")

If IsXML(Xml)
  If XMLStatus(Xml) = #PB_XML_Success
    
    Dialog = CreateDialog(#PB_Any)
    
    ;<window .... name="hello"
    If OpenXMLDialog(Dialog, Xml, "hello") 
      
      ;<window id="0"
      HideWindow(0, #False)
      
      ;<button text="Ole 2" name="button"/>
      Button = DialogGadget(Dialog,"button") 
      
      BindGadgetEvent(Button, @Button_LeftClick(), #PB_EventType_LeftClick)
      
      Repeat
      Until WaitWindowEvent() = #PB_Event_CloseWindow
      
    Else
      Debug "Dialog creation error: " + DialogError(Dialog)
    EndIf
    
  Else
    Debug "XML error on line " + XMLErrorLine(Xml) + ": " + XMLError(Xml)
  EndIf
  
EndIf
Grüße ... Kiffi
a²+b²=mc²
Andreas21
Beiträge: 390
Registriert: 30.08.2004 09:05
Computerausstattung: Desktop
Windows 10 Pro x64
CPU: AMD Ryzen 5 2600 3.40 GHz
Ram: 16GB RAM
Grafik: NVIDA Geforce 1060
PB: 5.72 X86/X64
Wohnort: Heidelberg

Re: PB 5.2 Dialog

Beitrag von Andreas21 »

Wie man bei der Fenster ID, #PB_Any nutzen kann habe ich noch nicht raus gefunden.

Feste IDs wie z.b. 0 mag ich normal nicht.
Ist unflexibel.

Könnte interessant sein wenn der Form Designer auch in xml speichern könnte.
So könnte man Forms auch nachträglich bearbeiten.
Windows 10 x64 Pro - PB 5.61 X64 / x32 - PB 4.6 x32
Benutzeravatar
Kiffi
Beiträge: 10715
Registriert: 08.09.2004 08:21
Wohnort: Amphibios 9

Re: PB 5.2 Dialog

Beitrag von Kiffi »

Andreas21 hat geschrieben:Wie man bei der Fenster ID, #PB_Any nutzen kann habe ich noch nicht raus gefunden.
Wenn Du id weglässt, wird #PB_Any verwendet:
Fred hat geschrieben:- "id" is the purebasic #Window id of the created dialog (if missing, it will be #PB_Any). "name" is the name you need to put in OpenXMLDialog().
Andreas21 hat geschrieben:Könnte interessant sein wenn der Form Designer auch in xml speichern könnte.
So könnte man Forms auch nachträglich bearbeiten.
so ist zumindest der Plan. Wenn Polo mal in die Puschen kommen würde...

Grüße ... Kiffi
a²+b²=mc²
Andreas21
Beiträge: 390
Registriert: 30.08.2004 09:05
Computerausstattung: Desktop
Windows 10 Pro x64
CPU: AMD Ryzen 5 2600 3.40 GHz
Ram: 16GB RAM
Grafik: NVIDA Geforce 1060
PB: 5.72 X86/X64
Wohnort: Heidelberg

Re: PB 5.2 Dialog

Beitrag von Andreas21 »

Code: Alles auswählen

Define Dialog, Xml, Button, Window

;<option text="option 1" .... onevent="CheckBoxEvent()"/>
Runtime Procedure CheckBoxEvent() 
  Debug "Option 1 clicked!"
EndProcedure

Xml = LoadXML(#PB_Any, "ui.xml")
If IsXML(Xml)
  If XMLStatus(Xml) = #PB_XML_Success
    Dialog = CreateDialog(#PB_Any)
    
    ;<window .... name="hello"
    OpenXMLDialog(Dialog, Xml, "hello")
    Window = DialogWindow(Dialog)
    If IsWindow(Window)
      
      ;<window id="0"
      HideWindow(Window, #False)
      
      ;<button text="Ole 2" name="button"/>
      Button = DialogGadget(Dialog,"button") 
      If IsGadget(Button)
        Repeat
          Event = WaitWindowEvent()
          Select Event
              
            Case #PB_Event_Gadget
              Select EventGadget()
                Case Button
                  Debug "Button Ole 2 clicked!"
              EndSelect
          EndSelect
          
        Until Event = #PB_Event_CloseWindow
      EndIf
    Else
      Debug "Dialog creation error: " + DialogError(Dialog)
    EndIf
  Else
    Debug "XML error on line " + XMLErrorLine(Xml) + ": " + XMLError(Xml)
  EndIf
EndIf
Windows 10 x64 Pro - PB 5.61 X64 / x32 - PB 4.6 x32
Antworten