Results 1 to 5 of 5

Thread: [RESOLVED] problem, my usercontrol is rendering outside the object visible rectangle area, why?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    864

    Resolved [RESOLVED] problem, my usercontrol is rendering outside the object visible rectangle area, why?

    The problem happens only when the control is rendered from the Form_Load, that is the normal in a full APP.

    So, the task is to convert the normal opaque usercontrol objects to translucent capable, using thw usercontrol.windowsless=true plus backstyle = 0, etc.

    But when does that, results what is happening in the video.

    any clue?


  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    864

    Re: problem, my usercontrol is rendering outside the object visible rectangle area, w

    When the code do translucency = true, this is executed inside the usercontrol.

    Code:
    Property Let Translucency(ByVal NewValue As Boolean)
    
    VarTranslucency = NewValue
    
    On Error GoTo Err
    
    If NewValue Then
        UserControl.AutoRedraw = False
        UserControl.ClipBehavior = 0 ' None.
        UserControl.BackStyle = 0 ' Transparent.
    Else
        UserControl.BackStyle = 1 ' Opaque.
        UserControl.ClipBehavior = 1 ' Use Region.
        UserControl.AutoRedraw = True
    End If
    
    If VarAutoRedraw Then
        If UserControl.AutoRedraw Then
            Call Redraw
        Else
            UserControl.Refresh
        End If
    End If
    
    Exit Property
    
    
    
    Err:
    Resume Err2
    Err2:
    
    VarTranslucency = False
    
    End Property
    I figured out that when is set ClipBehaviour = 0 ' None, maybe that has to do. But, if not set to zero, the control never shows. But why it work if setup from a command button, and not from the form_load?.

    I understand that ClipBehaviour must be zero for transparent objects. But don't understand the inners of what it does.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    864

    Re: problem, my usercontrol is rendering outside the object visible rectangle area, w

    Okkk this is interesting, If I don't load the images, the .ico and the .png, it never renders outside the rectangle area.

    by example the background image in the user control is rendered this way.

    Code:
    If VarTranslucency Then
        If mhToken = 0 Then Exit Sub
        If GdipCreateFromHDC(UserControl.hdc, hGr) Then Exit Sub ' No viene de evento Paint.
    End If
    
    If VarBackGroundPicture Is Nothing And VarBackGroundPicturehBitmap = 0 Then
        ' No tiene imagen de fondo.
        ' Aplica color de fondo.
        If UserControl.BackColor = VarBackColor Then
            Cls
        Else
            UserControl.BackColor = VarBackColor
        End If
    Else
        ' Tiene imagen de fondo.
        If VarTranslucency = False Then
            VarBackGroundPicture.Render UserControl.hdc, --0, --CY, --CX, -CY, --0, --0, --VarBackGroundPicture.Width, --VarBackGroundPicture.Height, --0
        Else
            If VarBackGroundPicturehBitmap Then
                GdipDrawImageRectRectI hGr, VarBackGroundPicturehBitmap, 0, 0, UserControl.ScaleWidth, UserControl.ScaleHeight, 0, 0, UserControl.ScaleWidth, UserControl.ScaleHeight, UnitPixel, 0&, 0&, 0&
            End If
        End If
    End If
    So, when it executes GdipDrawImageRectRectI , then, ALL normal usercontrol.LINE, usercontrol. PRINT, wich is executed after is rendered outside the object area, at Form area x0,y0, and not inside the area.

    how to fix that? and how comes it makes a difference if loaded from Form_Load vs Command_Click() ?

    PD: Yes, I am mixing normal opaque drawing methods with translucency image rendering.
    Last edited by flyguille; Jan 20th, 2022 at 07:03 PM.

  4. #4
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    367

    Re: problem, my usercontrol is rendering outside the object visible rectangle area, w

    when you call GdipCreateFromHDC don't use usercontrol.hdc until you call GdipDeleteGraphics

    Code:
    If VarTranslucency Then
        If mhToken = 0 Then Exit Sub
    End If
    
    If VarBackGroundPicture Is Nothing And VarBackGroundPicturehBitmap = 0 Then
        ' No tiene imagen de fondo.
        ' Aplica color de fondo.
        If UserControl.BackColor = VarBackColor Then
            Cls
        Else
            UserControl.BackColor = VarBackColor
        End If
    Else
        ' Tiene imagen de fondo.
        If VarTranslucency = False Then
            VarBackGroundPicture.Render UserControl.hdc, --0, --CY, --CX, -CY, --0, --0, --VarBackGroundPicture.Width, --VarBackGroundPicture.Height, --0
        Else
            If VarBackGroundPicturehBitmap Then
                If GdipCreateFromHDC(UserControl.hdc, hGr) Then Exit Sub ' No viene de evento Paint.
                GdipDrawImageRectRectI hGr, VarBackGroundPicturehBitmap, 0, 0, UserControl.ScaleWidth, UserControl.ScaleHeight, 0, 0, UserControl.ScaleWidth, UserControl.ScaleHeight, UnitPixel, 0&, 0&, 0&
                GdipDeleteGraphics hGr
            End If
        End If
    End If
    leandroascierto.com Visual Basic 6 projects

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    864

    Re: problem, my usercontrol is rendering outside the object visible rectangle area, w

    Quote Originally Posted by LeandroA View Post
    when you call GdipCreateFromHDC don't use usercontrol.hdc until you call GdipDeleteGraphics

    Code:
    If VarTranslucency Then
        If mhToken = 0 Then Exit Sub
    End If
    
    If VarBackGroundPicture Is Nothing And VarBackGroundPicturehBitmap = 0 Then
        ' No tiene imagen de fondo.
        ' Aplica color de fondo.
        If UserControl.BackColor = VarBackColor Then
            Cls
        Else
            UserControl.BackColor = VarBackColor
        End If
    Else
        ' Tiene imagen de fondo.
        If VarTranslucency = False Then
            VarBackGroundPicture.Render UserControl.hdc, --0, --CY, --CX, -CY, --0, --0, --VarBackGroundPicture.Width, --VarBackGroundPicture.Height, --0
        Else
            If VarBackGroundPicturehBitmap Then
                If GdipCreateFromHDC(UserControl.hdc, hGr) Then Exit Sub ' No viene de evento Paint.
                GdipDrawImageRectRectI hGr, VarBackGroundPicturehBitmap, 0, 0, UserControl.ScaleWidth, UserControl.ScaleHeight, 0, 0, UserControl.ScaleWidth, UserControl.ScaleHeight, UnitPixel, 0&, 0&, 0&
                GdipDeleteGraphics hGr
            End If
        End If
    End If
    ok, Thanks, closing the hGr each time it is used fixed the problem. So, where a Graphics context exist from UserControl.hDC, all normal drawing method of usercontrol fails ONLY IF is in the Form_Load stage. What a mess.

Tags for this Thread

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