How can I save contents of a TEXT BOX to a BITMAP?

I am having a user enter text into a TEXTBOX control.
I then want to have them press a button and the contents will be saved to a BITMAP'd version of the contents, same dimentions as the text box.
Can someone show me code that will do that?
yyuubum2Asked:
Who is Participating?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Just change "Text1.hwnd" to "RichTextBox1.hWnd":

    Dim myDC As Long
    myDC = GetWindowDC(RichTextBox1.hwnd)
    BitBlt Picture1.hdc, 0, 0, Picture1.Width, Picture1.Height, myDC, 0, 0, vbSrcCopy
    ReleaseDC RichTextBox1.hwnd, myDC

(or whatever the name or your richtextbox is...)
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Project has a Textbox, CommandButton and a PictureBox:

Option Explicit

Private Declare Function GetWindowDC Lib "user32" _
    (ByVal hwnd As Long) As Long
   
Private Declare Function ReleaseDC Lib "user32" _
    (ByVal hwnd As Long, ByVal hdc As Long) As Long
   
Private Declare Function BitBlt Lib "gdi32" _
    (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, _
    ByVal nWidth As Long, ByVal nHeight As Long, _
    ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, _
    ByVal dwRop As Long) As Long

Private Sub Command1_Click()
    Me.ScaleMode = vbPixels
    Picture1.Width = Text1.Width
    Picture1.Height = Text1.Height
    Picture1.BorderStyle = 0 ' none
    Picture1.Appearance = 0 ' flat
    Picture1.AutoRedraw = True
    Dim textDC As Long
    textDC = GetWindowDC(Text1.hwnd)
    BitBlt Picture1.hdc, 0, 0, Picture1.Width, Picture1.Height, textDC, 0, 0, vbSrcCopy
    ReleaseDC Text1.hwnd, textDC
    SavePicture Picture1.Image, "c:\someImage.bmp"
End Sub
0
 
yyuubum2Author Commented:
that is sweet...very nice.
thanks !
0
 
yyuubum2Author Commented:
Just another question...would there be a lot for you to ammend it to work
with a Rich Text Box?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.