Results 1 to 4 of 4

Thread: Draw VB6-Form with RC6.Cairo

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,500

    Draw VB6-Form with RC6.Cairo

    Hi Olaf,

    I'm trying to use RC6.Cairo to draw VB6-Forms, including TitleBar(MinButon, MaxButton, CloseButton) and Form-Borders.

    Could you provide some code in RC6.cWidgetForm that does the above? Thanks!

  2. #2
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,325

    Re: Draw VB6-Form with RC6.Cairo

    The following thread should contain sufficient inspiration, I guess... (including resize at the borders)
    https://www.vbforums.com/showthread....gets-cwMDIMock

    Olaf

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,500

    Re: Draw VB6-Form with RC6.Cairo

    Quote Originally Posted by Schmidt View Post
    The following thread should contain sufficient inspiration, I guess... (including resize at the borders)
    https://www.vbforums.com/showthread....gets-cwMDIMock

    Olaf
    Excellent material. Much appreciated.

    Still have a few questions that need your help with:

    (1) In cMDIChild, you use the three letters in the Webdings font to represent the three control-buttons of the Form. This is not the case in cWidgetForm, which seems to display the three control-buttons in a ownerdrawn manner. I'd like to get the algorithm that draws these three control-buttons.

    (2) I used cwMDIMock in ucPanel, but when I reduce the form size with the mouse, the form refresh doesn't seem to work properly.
    When using cWidgetBase in ucPanel, I often encounter a situation where the refresh is not normal, I hope to get your help this time and solve this problem once and for all.

    (3) In my old version of FormDesigner, I used 16 PictureBoxes as Resizers for Form or Controls. Now I'm ready to rewrite my FormDesigner with RC6 and I'm wondering if there's a better way to implement the Resizer for Form or Controls? Or how does RC6-Widgets implement the resizer(control-pointers) in Design-Mode? Thanks.
    Attached Images Attached Images   
    Attached Files Attached Files
    Last edited by SearchingDataOnly; Jun 22nd, 2024 at 10:01 AM.

  4. #4
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,325

    Re: Draw VB6-Form with RC6.Cairo

    1) If you don't want Font-Symbols (for Minimize, Normal, Close), then the DrawingAlgos are:
    - Minimize: CC.DrawLine
    - Normalize: CC.Rectangle
    - Close: two CC.DrawLine-calls (for the "X")

    The x, y Offsets for these Cairo-Drawing-calls can be derived via simple Algebra -
    relative to the "greyish ButtonArea" which is already drawn...

    2) The Problem here is your misunderstanding of the Widget-Engines Refresh-mechanism.
    (a W.Refresh only refreshes its own area, including only its own children - not its "surroundings")
    W.Parent.Refresh is the better call, after you changed a Widgets size on its hosting (Parent)Container-Widget or -Root)

    3) For a "mocked Form-Host" (which is fixed anyways with its TopLeft-corner) -
    the "8 Mini-Rect-Knobs" are overkill IMO - why not just use the normal Form-Borders (at the right and bottom-edge) for resizing...

    Points 2 and 3 are fixed with the following new code for your Form1:
    Code:
    Option Explicit
    
    Private WithEvents MockW As cWidgetBase
    
    Private Sub Form_Initialize()
        Me.ScaleMode = vbPixels
    End Sub
    
    Private Sub Form_Load()
        Set MockW = ucPanel1.Widgets.Add(New cwMDIMock, "MyForm", 0, 0, 300, 240).Widget
            MockW.Moveable = False
            MockW.Object.Caption = "Hello World"
        MockW.Parent.Refresh
    End Sub
    
    Private Sub MockW_MouseDown(Button As Integer, Shift As Integer, ByVal x As Single, ByVal y As Single)
      MockW.Moveable = False
    End Sub
    
    Private Sub MockW_MouseMove(Button As Integer, Shift As Integer, ByVal x As Single, ByVal y As Single)
      Static lastX!, lastL!, lastW!, fx!
      Static lastY!, lastT!, lastH!, fy!
      Dim nWidth!, nHeight!, dx!, dy!
        
      If Button = 0 Then
         MockW.Root.GetMouseCursorPos lastX, lastY
         lastL = 0: lastW = MockW.Width:  fx = 1
         lastT = 0: lastH = MockW.Height: fy = 1
         MockW.MousePointer = IDC_ARROW
      
         Const r = 8 'catch-distance to borders
            If x > MockW.Width - r Then MockW.MousePointer = IDC_SIZEWE:  fx = 0
            If y > MockW.Height - r Then MockW.MousePointer = IDC_SIZENS: fy = 0
            If x > MockW.Width - r And y > MockW.Height - r Then MockW.MousePointer = IDC_SIZENWSE
         MockW.Root.MousePointer = MockW.MousePointer 'this final "take-over"-call into the root, will cause an immediate cursor refresh
         
      ElseIf Button = vbLeftButton And MockW.MousePointer <> IDC_ARROW Then
         MockW.Root.GetMouseCursorPos dx, dy
         dx = dx - lastX: nWidth = lastW + dx - 2 * fx * dx: If nWidth < 96 * MockW.Zoom Then nWidth = 96 * MockW.Zoom
         dy = dy - lastY: nHeight = lastH + dy - 2 * fy * dy: If nHeight < 32 * MockW.Zoom Then nHeight = 32 * MockW.Zoom
         
         Select Case MockW.Root.MousePointer 'Resize-Handling (dependent on the current MousePointer)
            Case IDC_SIZEWE:   MockW.Move lastL + fx * dx, lastT, nWidth, lastH
            Case IDC_SIZENS:   MockW.Move lastL, lastT + fy * dy, lastW, nHeight
            Case IDC_SIZENWSE: MockW.Move lastL + fx * dx, lastT + fy * dy, nWidth, nHeight
         End Select
         
         MockW.Parent.Refresh  'when the size of a widget-changes, the refresh is needed on the Parent!
      End If
    End Sub
    As for Point 1) ...(the Drawings for your Min, Norm, Close-Buttons) ...
    I leave to you as an exercise...

    Hint: It needs to be implemented via the W_Paint-Event of cwMDIMock -
    via the usual "State-Machine"-like mechanism -
    where you set an external Prop, as e.g. MinButton = True -
    followed by a W.Refresh -
    which in turn triggers W_Paint (calling the re-Draw-routine) -
    which in turn renders something into the area of the MinButton, when the internal m_MinButton-State = True)

    Olaf

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