It is currently Thu Dec 12, 2019 5:29 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: ListViewGadget() with Dynamic Horizontal ScrollBar [Windows]
PostPosted: Mon Feb 25, 2019 3:18 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3476
Hi
The title say it all
Code:
   LoadFont(0,"Tahoma",12)
  If OpenWindow(0, 0, 0, 270, 200, "ListViewGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ListViewGadget(0, 10, 10, 250, 120,#WS_HSCROLL)
    For a = 1 To 12
      AddGadgetItem (0, -1, "Item " + Str(a) + " of the Listview")
    Next
   
    ButtonGadget(1,10,150,80,25,"Add item(s)")
    ButtonGadget(2,100,150,80,25,"Remove item")
   
    hdc = GetDC_(GadgetID(0))
    SetGadgetFont(0,FontID(0))
    fontid = GetGadgetFont(0)
    SelectObject_(hdc, fontid)
    size.SIZE
    sitem = -1
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
     
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          sitem = GetGadgetState(0)         
       
        Case 1         
          AddGadgetItem (0, -1, "Listview Listview  Listview  Listview  Listview Listview Listview")
          AddGadgetItem (0, -1, "Listview Listview  Listview  Listview  Listview Listview Listview Listview Listview")
          items = CountGadgetItems(0)
          SendMessage_(GadgetID(0),#LB_GETHORIZONTALEXTENT,0,0)
          For item = 0 To items
            text$ = GetGadgetItemText(0,item)           
            GetTextExtentPoint32_(hdc,@text$,Len(text$),size)
            If size\cx > oldcx
               oldcx = size\cx
            EndIf
          Next
          SendMessage_(GadgetID(0),#LB_SETHORIZONTALEXTENT,oldcx+10,0)
          oldcx = 0
         
        Case 2
          If sitem >= 0         
            RemoveGadgetItem (0,sitem)
            items = CountGadgetItems(0)
            SendMessage_(GadgetID(0),#LB_GETHORIZONTALEXTENT,0,0)
            For item = 0 To items
              text$ = GetGadgetItemText(0,item)           
              GetTextExtentPoint32_(hdc,@text$,Len(text$),size)
              If size\cx > oldcx
                 oldcx = size\cx
              EndIf
            Next
            SendMessage_(GadgetID(0),#LB_SETHORIZONTALEXTENT,oldcx+10,0)
            oldcx = 0 : sitem = -1
          Else
            MessageRequester("Info","No item selected ",#MB_OK|#MB_ICONINFORMATION)
          EndIf

      EndSelect             
  EndSelect
Until Quit = 1
EndIf


Edit : Update

_________________
Egypt my love


Last edited by RASHAD on Wed Feb 27, 2019 1:40 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: ListViewGadget() with Dynamic Horizontal ScrollBar [Wind
PostPosted: Tue Feb 26, 2019 8:24 am 
Offline
Addict
Addict
User avatar

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 2456
Well done :shock:

I was nervous for a second as the initial content does not get checked, but your code is great - I'd add a SetGadgetFont(0,FontID(0)) anyhow :wink:


Top
 Profile  
Reply with quote  
 Post subject: Re: ListViewGadget() with Dynamic Horizontal ScrollBar [Wind
PostPosted: Wed Feb 27, 2019 1:41 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3476
Previous post updated

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: ListViewGadget() with Dynamic Horizontal ScrollBar [Wind
PostPosted: Thu Feb 28, 2019 1:00 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4545
Location: Lyon - France
Works great here
Thanks a lot for sharing 8)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye