3 Replies - 979 Views - Last Post: 02 September 2019 - 05:15 AM Rate Topic: -----

#1 JackBrig1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-September 19

Double Buffered Panel & Transparent RichTextBox...

Posted 02 September 2019 - 05:00 AM

Hello!

In the last few days I've run in to two problems, separately they have been solve but when I put the two solutions together I create a new problem I have been unable to resolve,

My first issue was a panel flashing when it was made visible, thanks to info found on this site this was solved by using this:
    Public Class DoubleBufferedPanel
        Inherits Panel
        Public Sub New()
            Me.DoubleBuffered = True
        End Sub
    End Class


The second issue is that I needed a RichTextBox that would show the background image of then panel it was located on, again thanks to this site this solved the issue:
Imports System.Runtime.InteropServices

    Public Class TransparentRichTextBox
        Inherits RichTextBox

        <DllImport("kernel32.dll", CharSet:=CharSet.Auto)> _
        Private Shared Function LoadLibrary(ByVal lpFileName As String) As IntPtr
        End Function

        Protected Overrides ReadOnly Property CreateParams() As CreateParams
            Get
                Dim params As CreateParams = MyBase.CreateParams
                If LoadLibrary("msftedit.dll") <> IntPtr.Zero Then
                    params.ExStyle = params.ExStyle Or &H20
                    params.ClassName = "RICHEDIT50W"
                End If
                Return params
            End Get
        End Property

    End Class


This all seemed good until I noticed a small issue, for some reason when using TransparentRichTextBox on a DoubleBufferedPanel, the scrollbars vanish and will not show up until the mouse hovers over where they should be and they then seem to gracefully fade into view. To rule out anything else in my project I created the small test below:

Option Strict On
Option Explicit On

Imports System.Runtime.InteropServices

Public Class Form1

    Public Class DoubleBufferedPanel
        Inherits Panel
        Public Sub New()
            Me.DoubleBuffered = True
        End Sub
    End Class

    Public Class TransparentRichTextBox
        Inherits RichTextBox

        <DllImport("kernel32.dll", CharSet:=CharSet.Auto)> _
        Private Shared Function LoadLibrary(ByVal lpFileName As String) As IntPtr
        End Function

        Protected Overrides ReadOnly Property CreateParams() As CreateParams
            Get
                Dim params As CreateParams = MyBase.CreateParams
                If LoadLibrary("msftedit.dll") <> IntPtr.Zero Then
                    params.ExStyle = params.ExStyle Or &H20
                    params.ClassName = "RICHEDIT50W"
                End If
                Return params
            End Get
        End Property

    End Class

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        ' Form stuff
        Me.DoubleBuffered = True
        Me.Size = New Size(675, 535)
        Me.BackColor = Color.LightGreen

        ' Create DoubleBufferedPanel
        Dim DoubleBufferedPanel1 As New DoubleBufferedPanel

        With DoubleBufferedPanel1
            .Name = "DoubleBufferedPanel1"
            .BackColor = Color.LightBlue
            .Width = 640
            .Height = 480
            .Top = 10
            .Left = 10
            .BackgroundImage = System.Drawing.Image.FromFile("C:\Windows\Web\Wallpaper\Windows\img0.jpg")
            .BackgroundImageLayout = ImageLayout.Stretch
        End With

        Me.Controls.Add(DoubleBufferedPanel1)

        ' Create TransparentRichTextBox, fill with text & return to top
        Dim TransparentRichTextBox1 As New TransparentRichTextBox

        With TransparentRichTextBox1
            .Name = "TransparentRichTextBox1"
            .Width = 620
            .Height = 460
            .Top = 10
            .Left = 10
            .ReadOnly = True
            .WordWrap = False
            .ScrollBars = RichTextBoxScrollBars.ForcedVertical
        End With

        For Line As Integer = 1 To 1000
            TransparentRichTextBox1.AppendText(String.Format("{0} {1}{2}", "Test Text", Line, vbCrLf))
        Next

        TransparentRichTextBox1.Select(0, 0)

        ' Add TransparentRichTextBox1 to DoubleBufferedPanel1
        DoubleBufferedPanel1.Controls.Add(TransparentRichTextBox1)

    End Sub
End Class


This displays the same behaviour as my main project did even when just using a background colour instead of an image. What I've noticed so far in addition to the what I described above is that if you click in the TransparentRichTextBox and use your mouse wheel to scroll down then the middle portion of the scrollbars appear but the up and down arrows do not.

I'm trying to modify an old project so moving away from WinForms is not an option at the moment, if anyone can point out where I am going wrong I would appreciate it. I don't have much knowledge of any programming language but I can usually find my way with Google, in this case though I am finding nothing. I have tried various versions of Transparant RichTextBox and DoubleBuffered Panel but they are just variations on a theme which give the same results.

Instead of fixing this issue I was wondering if it is possible to link/sync a VScrollBar to a RichTextBox in a way that works well? There are some examples on other sites but every one I've found is easily confused depending on the text file in question, some confused by blank lines, word wrap etc and losing the ability to scroll with the mouse. If I can bypass the need to use the built in scrollbar of a RichTextBox then that would also solve the problem.

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Double Buffered Panel & Transparent RichTextBox...

#2 maceysoftware   User is offline

  • Member Title
  • member icon

Reputation: 383
  • View blog
  • Posts: 1,630
  • Joined: 07-September 13

Re: Double Buffered Panel & Transparent RichTextBox...

Posted 02 September 2019 - 05:05 AM

Weird, I copy and paste your code and the bars are there straight away.
Was This Post Helpful? 0
  • +
  • -

#3 JackBrig1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-September 19

Re: Double Buffered Panel & Transparent RichTextBox...

Posted 02 September 2019 - 05:10 AM

View Postmaceysoftware, on 02 September 2019 - 05:05 AM, said:

Weird, I copy and paste your code and the bars are there straight away.


That only happens for me when the mouse happens to be in the general area of where the scrollbars would normally be, I've just been trying another OS and the same thing happens on Windows 7 and 10 for me.

Thanks!
Was This Post Helpful? 0
  • +
  • -

#4 JackBrig1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-September 19

Re: Double Buffered Panel & Transparent RichTextBox...

Posted 02 September 2019 - 05:15 AM

I've attached some pictures.

Start.png shows what happens when running program but not having the mouse near the window.
Attached Image

MouseonscrollBar.png shows what happens when the mouse is moved over the area where the scrollbars should be.
Attached Image

MouseScroll.png shows what happens when using the mouse to scroll (missing arrows).
Attached Image

Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1