Results 1 to 22 of 22

Thread: [RESOLVED] Listview clear/adding items blinking, best approach to stop the blink

Threaded View

  1. #10
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: [RESOLVED] Listview clear/adding items blinking, best approach to stop the blink

    Quote Originally Posted by Max187Boucher View Post
    ... now a new question can you add widgets to normal vb forms?
    Yes, there's an older, still supported mode - which involves the definition and usage
    of a generic (Std-Exe-Project-Private) UserControl (Code for that "ucPanel" further below).

    In conjunction with that ucPanel-Control you can then host Widgets (in the ucPanel)
    together with normal VB-Controls on normal VB-Forms (including proper Tabbing-
    and Focus-delegation then).

    Below I'll post an example for that.

    Quote Originally Posted by Max187Boucher View Post
    ...or do I have to work with the new form that contains the widget...
    Why not, working directly with the new Form-Engine is recommended - and vbWidgets.dll
    contains enough Widget-Encapsulations to replace nearly anything you use on your old VB-Forms.

    The example below shows (in addition to the two cwVList-Widgets) also a cwButton-
    as well as a cwTextBox-Widget (just to demonstrate that it's not that hard to work with that).

    Quote Originally Posted by Max187Boucher View Post
    ...or perhaps can I move the whole tool form/widget into a normal form (SetParent api) what would you suggest.
    No, wouldn't recommend that - the ucPanel-Mode which I describe now in an example -
    is thought for that:

    ucPanel-Mode:
    In case you want to mix normal VB-Controls on a normal VB-Form with Widgets,
    it works best (with regards to tabbing and focus-stuff), when you introduce a small,
    normal VB-UserControl which then acts as a ContainerHost for an RC5-cWidgetRoot -
    and can be used in a generic way (allowing any amount of cwWidget-Classes to be
    added over the Widgets-Collection it exposes in a Property).

    One can place multiple ucPanels on the same normal VB-Form (each hosting different Widgets) -
    but I'd recommend to "bundle as many Widgets in the same ucPanel-Container as possible"
    (to save some resources - using an ucPanel for each and every small single cwTextbox or cwLabel
    would be overkill resource-wise).

    So the below example avoids that (hosting two cwVlist-Widgets, a cwButton and a cwTextBox,
    on a single ucPanel).

    Here's a ScreenShot how that looks like on a normal VB-Form (I've set the BackColor of the
    ucPanel-WidgetRoot to vbWhite, so that one can better see, which range it covers on the VB-Form).



    To test the following Demo-Code one would again need to put references into
    a normal, fresh VB6-Std-Project (to vbRichClient5 and vbWidgets as well).

    Now we need (in addition to the normal VB-Form, Form1) only one additional
    Code-Module: a UserControl-Module, which should be named ucPanel.

    The following code needs to be pasted into it:
    Code:
    Option Explicit
     
    Event BubblingEvent(Sender As Object, EventName As String, P1, P2, P3, P4, P5, P6, P7)
    Event ResizeWithDimensions(ByVal NewWidth As Long, ByVal NewHeight As Long)
    Event DragOverDst(Data As vbRichClient5.cDataObject, ByVal AllowedEffects As vbRichClient5.WidgetDropEffects, Effect As vbRichClient5.WidgetDropEffects, Button As Integer, Shift As Integer, x As Single, y As Single)
    Event DragDropDst(Data As vbRichClient5.cDataObject, ByVal AllowedEffects As vbRichClient5.WidgetDropEffects, Effect As vbRichClient5.WidgetDropEffects, Button As Integer, Shift As Integer, x As Single, y As Single)
    Event NewWidgetCreateDimensions(ParentWidget As cWidgetBase, ByVal x As Single, ByVal y As Single, ByVal dx As Single, ByVal dy As Single)
    
    Private WithEvents mWidgetRoot As cWidgetRoot
    
    Private Sub UserControl_Initialize()
      ScaleMode = vbPixels
    End Sub
    
    Public Property Get WidgetRoot() As cWidgetRoot
      If mWidgetRoot Is Nothing Then 'let's create the Root-Object and hold it in mWidgetRoot
        Set mWidgetRoot = Cairo.WidgetRoot
            mWidgetRoot.RenderContentIn Me
      End If
      Set WidgetRoot = mWidgetRoot
    End Property
    
    Public Property Get Widgets() As cWidgets 'this hands out the WidgetRoots-Widgets-Collection directly, to spare an indirection
      Set Widgets = WidgetRoot.Widgets
    End Property
    
    Public Property Get ScaleWidth() As Single
      ScaleWidth = UserControl.ScaleWidth
    End Property
    Public Property Get ScaleHeight() As Single
      ScaleHeight = UserControl.ScaleHeight
    End Property
    
    'what remains is event-redirection/reraising to be compatible here as well (to the cWidgetForms)
    Private Sub mWidgetRoot_ResizeWithDimensions(ByVal NewWidth As Long, ByVal NewHeight As Long)
      RaiseEvent ResizeWithDimensions(NewWidth, NewHeight)
    End Sub
    Private Sub mWidgetRoot_BubblingEvent(Sender As Object, EventName As String, P1, P2, P3, P4, P5, P6, P7)
      RaiseEvent BubblingEvent(Sender, EventName, P1, P2, P3, P4, P5, P6, P7)
    End Sub
    Private Sub mWidgetRoot_DragDropDst(Data As vbRichClient5.cDataObject, ByVal AllowedEffects As vbRichClient5.WidgetDropEffects, Effect As vbRichClient5.WidgetDropEffects, Button As Integer, Shift As Integer, x As Single, y As Single)
      RaiseEvent DragDropDst(Data, AllowedEffects, Effect, Button, Shift, x, y)
    End Sub
    Private Sub mWidgetRoot_DragOverDst(Data As vbRichClient5.cDataObject, ByVal AllowedEffects As vbRichClient5.WidgetDropEffects, Effect As vbRichClient5.WidgetDropEffects, Button As Integer, Shift As Integer, x As Single, y As Single)
      RaiseEvent DragOverDst(Data, AllowedEffects, Effect, Button, Shift, x, y)
    End Sub
    Private Sub mWidgetRoot_NewWidgetCreateDimensions(ParentWidget As vbRichClient5.cWidgetBase, ByVal x As Single, ByVal y As Single, ByVal dx As Single, ByVal dy As Single)
      RaiseEvent NewWidgetCreateDimensions(ParentWidget, x, y, dx, dy)
    End Sub
    Now, close the ucPanel-Code-Module (as well as its visual representation) - and
    drag a new instance of it up in an appropriate size (as seen on the ScreenShot above)
    onto your Form1 (leave the Default-Name it gets - ucPanel1 - as it is).

    Now the following code needs to be pasted into Form1, before running the project:
    Code:
    Option Explicit
      
    Private MemDB As cMemDB
    Private WithEvents tmrUpdates As cTimer, WithEvents tmrRefresh As cTimer
    Private RsBids As cRecordset, lstBids As cwVList
    Private RsAsks As cRecordset, lstAsks As cwVList
    Private btnTest As cwButton, txtTest As cwTextBox 'just to introduce some other Widgets, also shown on the Panel
    
    Private Sub Form_Load()
      Cairo.ImageList.AddIconFromResourceFile "LstIco", "shell32.dll", 322, 32, 32 'add an image-resource
      Cairo.ImageList.AddIconFromResourceFile "BtnIco", "shell32.dll", 167, 32, 32 'add an image-resource
    
      Set MemDB = New_c.MemDB 'create a Demo-Instance of the global MemDB
          MemDB.Exec "Create Table SomeBids(Amount Text, Price Text)" 'and add a simple table to it
          MemDB.Exec "Create Table SomeAsks(Amount Text, Price Text)" 'and add a simple table to it
      
      Dim i As Long
      For i = 1 To 20 'add a few Demo-Records
        MemDB.ExecCmd "Insert Into SomeBids Values(?,?)", Str(i), Str(i + 0.01)
        MemDB.ExecCmd "Insert Into SomeAsks Values(?,?)", Str(-i), Str(-i - 0.01)
      Next i
      
      Set tmrUpdates = New_c.Timer(2000, True)
      Set tmrRefresh = New_c.Timer(1000, True)
      
      Me.Show 'it's good to show the Form, before adding the Widgets to the ucPanel
      Set lstBids = ucPanel1.Widgets.Add(New cwVList, "lstBids", 4, 4, 200, 300)
      Set lstAsks = ucPanel1.Widgets.Add(New cwVList, "lstAsks", 208, 4, 200, 300)
      Set btnTest = ucPanel1.Widgets.Add(New cwButton, "btnTest", 430, 4, 120, 22)
          btnTest.Widget.ImageKey = "BtnIco"
          btnTest.Caption = "&Button-Widget"
      Set txtTest = ucPanel1.Widgets.Add(New cwTextBox, "txtTest", 430, 30, 120, 22)
          txtTest.CueBannerText = "Type something..."
      ucPanel1.WidgetRoot.BackColor = vbWhite '<- just to make the area of the ucPanel more obvious on the VB-Form here
      ucPanel1.WidgetRoot.Refresh
    End Sub
    
    Private Sub tmrUpdates_Timer()
      SimulateChangesInTable MemDB.GetRs("Select * From SomeBids")
      SimulateChangesInTable MemDB.GetRs("Select * From SomeAsks")
    End Sub
    
    Private Sub SimulateChangesInTable(Rs As cRecordset)
      Rs!Price = Str(Val(Rs!Price.Value) + 0.01)  'change the Price of the first record
      Rs.MoveNext
      Rs!Price = Str(Val(Rs!Price.Value) + 0.01) 'change the Price of the second record
    
      Rs.AddNew 'and add a new Record to expand the MemDB-Tables content a bit
        Rs!Amount = Str(Rs.RecordCount)
        Rs!Price = Str(Rs.RecordCount + 0.01)
      Rs.UpdateBatch 'just to update the MemDB-Table in each round with some new Data
    End Sub
    
    Private Sub tmrRefresh_Timer()
      RefreshListData lstBids, RsBids, "Select * From SomeBids"
      RefreshListData lstAsks, RsAsks, "Select * From SomeAsks"
    End Sub
    
    Private Sub RefreshListData(Lst As cwVList, Rs As cRecordset, SQL As String)
      Set Rs = MemDB.GetRs(SQL)  'get the latest Data-Snapshot from the MemDB
      Lst.HeaderHeight = 44
      Lst.RowHeight = 21
      Lst.ListCount = Rs.RecordCount 'that's all what's needed to enforce a Refresh on the lstBids
    End Sub
    
    Private Sub ucPanel1_BubblingEvent(Sender As Object, EventName As String, P1, P2, P3, P4, P5, P6, P7)
      Select Case EventName
        Case "OwnerDrawHeader": DrawListHeader IIf(Sender Is lstBids, RsBids, RsAsks), P1, P2, P3
        Case "OwnerDrawItem":   DrawListItem IIf(Sender Is lstBids, RsBids, RsAsks), P1, P2, P3, P4
        Case "Click":           If Sender Is btnTest Then MsgBox "Hello from Widget-Button"
        Case "Change":          If Sender Is txtTest Then Caption = txtTest.Text 'just reflect it in the Form-Caption
      End Select
    End Sub
    
    Private Sub DrawListItem(Rs As cRecordset, ByVal Index As Long, ByVal CC As cCairoContext, ByVal dx As Single, ByVal dy As Single)
      CC.RenderSurfaceContent "LstIco", 6, 2, 16, 16
      
      CC.DrawText 24, 0, dx \ 2 - 24, dy, Rs.ValueMatrix(Index, 0), True, vbLeftJustify, 2, True
      CC.DrawText dx \ 2, 0, dx \ 2, dy, Rs.ValueMatrix(Index, 1), True, vbRightJustify, 2, True
         
      CC.DrawLine dx \ 2, 0, dx \ 2, dy, True, 1, vbBlack, 0.1 'draw a vertical Col-Separator (if wanted)
    End Sub
    
    Private Sub DrawListHeader(Rs As cRecordset, ByVal CC As cCairoContext, ByVal dx As Single, ByVal dy As Single)
      Cairo.Theme.DrawTo CC, lstBids.Widget, thmTypeButtonFace, 0, 0, 0, dx, dy
    
      CC.SelectFont "Tahoma", 10, &H444444, True 'text-rendering again (this time with a somewhat larger font)
      CC.DrawText 0, 0, dx, dy \ 2, IIf(Rs Is RsBids, "Bids", "Asks"), True, vbCenter, 2, True
      
      CC.DrawText 0, dy \ 2, dx \ 2, dy \ 2, Rs(0).Name, True, vbCenter, 2, True
      CC.DrawText dx \ 2, dy \ 2, dx \ 2, dy \ 2, Rs(1).Name, True, vbCenter, 2, True
      
      CC.DrawLine dx \ 2, dy \ 2, dx \ 2, dy, True, 1, vbBlack, 0.1   'draw a vertical Col-Separator (if wanted)
    End Sub
    
    Private Sub Form_Terminate()
      If Forms.Count = 0 Then New_c.CleanupRichClientDll
    End Sub
    In case you want more IDE-stability in this mode (allowing Stop-Button-presses for example) -
    I'd recommend to download the latest RC5-version 5.0.29 which contains better protection in such cases.


    HTH

    Olaf
    Last edited by Schmidt; May 15th, 2015 at 05:44 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width