PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2010 Double Buffered Panel & Transparent RichTextBox / Link VScrollBar to RichTextBox?-VBForums
Results 1 to 13 of 13

Thread: Double Buffered Panel & Transparent RichTextBox / Link VScrollBar to RichTextBox?

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    7

    Question Double Buffered Panel & Transparent RichTextBox / Link VScrollBar to RichTextBox?

    Hello!

    I found this site recently and it has been a big help, lots of good information here. In the last day or so I've run in to two problems, so sadly my first post here is going to be a request for help.

    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:
    vb.net Code:
    1. Public Class DoubleBufferedPanel
    2.         Inherits Panel
    3.         Public Sub New()
    4.             Me.DoubleBuffered = True
    5.         End Sub
    6.     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:
    vb.net Code:
    1. Imports System.Runtime.InteropServices
    2.  
    3.     Public Class TransparentRichTextBox
    4.         Inherits RichTextBox
    5.  
    6.         <DllImport("kernel32.dll", CharSet:=CharSet.Auto)> _
    7.         Private Shared Function LoadLibrary(ByVal lpFileName As String) As IntPtr
    8.         End Function
    9.  
    10.         Protected Overrides ReadOnly Property CreateParams() As CreateParams
    11.             Get
    12.                 Dim params As CreateParams = MyBase.CreateParams
    13.                 If LoadLibrary("msftedit.dll") <> IntPtr.Zero Then
    14.                     params.ExStyle = params.ExStyle Or &H20
    15.                     params.ClassName = "RICHEDIT50W"
    16.                 End If
    17.                 Return params
    18.             End Get
    19.         End Property
    20.  
    21.     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:

    vb.net Code:
    1. Option Strict On
    2. Option Explicit On
    3.  
    4. Imports System.Runtime.InteropServices
    5.  
    6. Public Class Form1
    7.  
    8.     Public Class DoubleBufferedPanel
    9.         Inherits Panel
    10.         Public Sub New()
    11.             Me.DoubleBuffered = True
    12.         End Sub
    13.     End Class
    14.  
    15.     Public Class TransparentRichTextBox
    16.         Inherits RichTextBox
    17.  
    18.         <DllImport("kernel32.dll", CharSet:=CharSet.Auto)> _
    19.         Private Shared Function LoadLibrary(ByVal lpFileName As String) As IntPtr
    20.         End Function
    21.  
    22.         Protected Overrides ReadOnly Property CreateParams() As CreateParams
    23.             Get
    24.                 Dim params As CreateParams = MyBase.CreateParams
    25.                 If LoadLibrary("msftedit.dll") <> IntPtr.Zero Then
    26.                     params.ExStyle = params.ExStyle Or &H20
    27.                     params.ClassName = "RICHEDIT50W"
    28.                 End If
    29.                 Return params
    30.             End Get
    31.         End Property
    32.  
    33.     End Class
    34.  
    35.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    36.  
    37.         ' Form stuff
    38.         Me.DoubleBuffered = True
    39.         Me.Size = New Size(675, 535)
    40.         Me.BackColor = Color.LightGreen
    41.  
    42.         ' Create DoubleBufferedPanel
    43.         Dim DoubleBufferedPanel1 As New DoubleBufferedPanel
    44.  
    45.         With DoubleBufferedPanel1
    46.             .Name = "DoubleBufferedPanel1"
    47.             .BackColor = Color.LightBlue
    48.             .Width = 640
    49.             .Height = 480
    50.             .Top = 10
    51.             .Left = 10
    52.             .BackgroundImage = System.Drawing.Image.FromFile("C:\Windows\Web\Wallpaper\Windows\img0.jpg")
    53.             .BackgroundImageLayout = ImageLayout.Stretch
    54.         End With
    55.  
    56.         Me.Controls.Add(DoubleBufferedPanel1)
    57.  
    58.         ' Create TransparentRichTextBox, fill with text & return to top
    59.         Dim TransparentRichTextBox1 As New TransparentRichTextBox
    60.  
    61.         With TransparentRichTextBox1
    62.             .Name = "TransparentRichTextBox1"
    63.             .Width = 620
    64.             .Height = 460
    65.             .Top = 10
    66.             .Left = 10
    67.             .ReadOnly = True
    68.             .WordWrap = False
    69.             .ScrollBars = RichTextBoxScrollBars.ForcedVertical
    70.         End With
    71.  
    72.         For Line As Integer = 1 To 1000
    73.             TransparentRichTextBox1.AppendText(String.Format("{0} {1}{2}", "Test Text", Line, vbCrLf))
    74.         Next
    75.  
    76.         TransparentRichTextBox1.Select(0, 0)
    77.  
    78.         ' Add TransparentRichTextBox1 to DoubleBufferedPanel1
    79.         DoubleBufferedPanel1.Controls.Add(TransparentRichTextBox1)
    80.  
    81.     End Sub
    82. 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.

    If anyone can point out where I am going wrong I would appreciate it.

    Thanks
    Last edited by JackBrig; Sep 1st, 2019 at 06:45 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
  •  



Featured


Click Here to Expand Forum to Full Width