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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
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
yyuubum2Author Commented:
that is sweet...very nice.
thanks !
yyuubum2Author Commented:
Just another question...would there be a lot for you to ammend it to work
with a Rich Text Box?
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
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...)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.