• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 162
  • Last Modified:

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?
0
yyuubum2
Asked:
yyuubum2
  • 2
  • 2
1 Solution
 
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
 
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now