For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > August 2005 > Drawing TextBox borders around RichTextBox









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Drawing TextBox borders around RichTextBox
Sebastian Mares

2005-08-30, 6:55 pm

Hello!

Instead of using the Forms 2.0 components in my application, I would like to
use a RichTextBox for unicode input - not only because I don't need unicode
buttons, frames or other controls, but also because the Forms 2.0 components
cannot be redistributed.
Anyways, my problem is that the RichTextBox looks different than normal text
boxes when Windows XP styles are activated. While looking for some
information on the Internet, I came across the following article which covers
my issue: http://www.codeguru.com/article.php/c8729__1/ However, the article
is designed for C++ and my C++ knowledge is very limited.

I also tried messing around with OpenThemeData and DrawThemeBackground but I
can't seem to get it right:

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function DrawThemeBackground Lib "uxtheme.dll" (ByVal hTheme
As Long, ByVal lhDC As Long, ByVal iPartId As Long, ByVal iStateId As Long,
pRect As RECT, pClipRect As RECT) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long,
lpRect As RECT) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function OpenThemeData Lib "uxtheme.dll" (ByVal hWnd As
Long, ByVal pszClassList As Long) As Long

Private Sub ApplyVisualStyle(rtbRichTextBox As RichTextBox)
Dim lngControlDC As Long
Dim lngThemeHandle As Long
Dim udtRectangle As RECT

'Get RichTextBox DC
lngControlDC = GetDC(rtbRichTextBox.hWnd)
'Get RichTextBox rectangle
GetClientRect rtbRichTextBox.hWnd, udtRectangle
'Open TextBox theme data
lngThemeHandle = OpenThemeData(rtbRichTextBox.hWnd, StrPtr("Edit"))
'Draw theme
DrawThemeBackground lngThemeHandle, lngControlDC, 0, 0, udtRectangle,
udtRectangle
End Sub

The problem is that the code above will cover the text inside the
RichTextBox and also, once the RTB is repainted, the themed look is gone.

Does anyone have an idea how to make the RTB look like the default TextBox
in VB?

Regards,
Sebastian Mares
MikeD

2005-08-30, 6:55 pm


"Sebastian Mares" <SebastianMares@discussions.microsoft.com> wrote in
message news:9780934D-26AE-4D14-B399-75A0592A562D@microsoft.com...
> Hello!
>
> Instead of using the Forms 2.0 components in my application, I would like
> to
> use a RichTextBox for unicode input - not only because I don't need
> unicode
> buttons, frames or other controls, but also because the Forms 2.0
> components
> cannot be redistributed.


There are bigger problems with it than that. When used in VB, it usually
causes Out of Memory errors for no apparent reason (well, no reason other
than it wasn't designed or intended to be used in VB; Out of Memory errors
are the result of that).


--
Mike
Microsoft MVP Visual Basic


Sebastian Mares

2005-08-31, 3:55 am

OK, thanks for that. So one more reason for using the RichTextBox then.

Anyways, any idea how to solve my problem?

"MikeD" wrote:

>
> "Sebastian Mares" <SebastianMares@discussions.microsoft.com> wrote in
> message news:9780934D-26AE-4D14-B399-75A0592A562D@microsoft.com...
>
> There are bigger problems with it than that. When used in VB, it usually
> causes Out of Memory errors for no apparent reason (well, no reason other
> than it wasn't designed or intended to be used in VB; Out of Memory errors
> are the result of that).
>
>
> --
> Mike
> Microsoft MVP Visual Basic
>
>
>

Dave

2005-08-31, 7:55 am

Well yes you could do all that mucking about, or you could put a RTFbox with
no borders into a locked textbox with borders.

Make the RTFBox 4 pixels narrower and shorter and place 2 pixel in and down
from the normal text box and when the XP style is applied it will look
correct.

Dave


"Sebastian Mares" <SebastianMares@discussions.microsoft.com> wrote in
message news:9780934D-26AE-4D14-B399-75A0592A562D@microsoft.com...
> Hello!
>
> Instead of using the Forms 2.0 components in my application, I would like
> to
> use a RichTextBox for unicode input - not only because I don't need
> unicode
> buttons, frames or other controls, but also because the Forms 2.0
> components
> cannot be redistributed.
> Anyways, my problem is that the RichTextBox looks different than normal
> text
> boxes when Windows XP styles are activated. While looking for some
> information on the Internet, I came across the following article which
> covers
> my issue: http://www.codeguru.com/article.php/c8729__1/ However, the
> article
> is designed for C++ and my C++ knowledge is very limited.
>
> I also tried messing around with OpenThemeData and DrawThemeBackground but
> I
> can't seem to get it right:
>
> Private Type RECT
> Left As Long
> Top As Long
> Right As Long
> Bottom As Long
> End Type
>
> Private Declare Function DrawThemeBackground Lib "uxtheme.dll" (ByVal
> hTheme
> As Long, ByVal lhDC As Long, ByVal iPartId As Long, ByVal iStateId As
> Long,
> pRect As RECT, pClipRect As RECT) As Long
> Private Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long,
> lpRect As RECT) As Long
> Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
> Private Declare Function OpenThemeData Lib "uxtheme.dll" (ByVal hWnd As
> Long, ByVal pszClassList As Long) As Long
>
> Private Sub ApplyVisualStyle(rtbRichTextBox As RichTextBox)
> Dim lngControlDC As Long
> Dim lngThemeHandle As Long
> Dim udtRectangle As RECT
>
> 'Get RichTextBox DC
> lngControlDC = GetDC(rtbRichTextBox.hWnd)
> 'Get RichTextBox rectangle
> GetClientRect rtbRichTextBox.hWnd, udtRectangle
> 'Open TextBox theme data
> lngThemeHandle = OpenThemeData(rtbRichTextBox.hWnd, StrPtr("Edit"))
> 'Draw theme
> DrawThemeBackground lngThemeHandle, lngControlDC, 0, 0, udtRectangle,
> udtRectangle
> End Sub
>
> The problem is that the code above will cover the text inside the
> RichTextBox and also, once the RTB is repainted, the themed look is gone.
>
> Does anyone have an idea how to make the RTB look like the default TextBox
> in VB?
>
> Regards,
> Sebastian Mares



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com