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

How can i make a picture exacly the same display as the textbox?

I want to save a picture as the textbox (text,font,fontsize, font colour)!
The user will input multi-line string in the textbox!

Can i put the text1 image into picture.image?????????????

So i can save the picture into the file as picture.picture = picture.image!

0
tonyleung
Asked:
tonyleung
1 Solution
 
Ryan ChongCommented:
Private Declare Function BitBlt Lib "gdi32" _
  (ByVal hDCDest As Long, ByVal XDest As Long, _
   ByVal YDest As Long, ByVal nWidth As Long, _
   ByVal nHeight As Long, ByVal hDCSrc As Long, _
   ByVal xSrc As Long, ByVal ySrc As Long, _
   ByVal dwRop As Long) As Long

Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long

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 Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Private Type POINTAPI
   X As Long
   Y As Long
End Type

Private Type WINDOWPLACEMENT
        Length As Long
        flags As Long
        showCmd As Long
        ptMinPosition As POINTAPI
        ptMaxPosition As POINTAPI
        rcNormalPosition As RECT
End Type

Private Sub PrintHwnd(ByRef hwnd As Long, ByRef pic As PictureBox)
    Dim hDCDesk As Long
    Dim LeftDesk As Long
    Dim TopDesk As Long
    Dim WidthDesk As Long
    Dim HeightDesk As Long
    Dim WinEst As WINDOWPLACEMENT
    Dim rtn As Long
    Dim Rectan As RECT
    Dim newWidth As Long, newHeight As Long
    Dim MyStr As String
   
    WinEst.Length = Len(WinEst)
    'get the current window placement
    rtn = GetWindowPlacement(hwnd, WinEst)
    Rectan = WinEst.rcNormalPosition
   
    LeftDesk = 0
    TopDesk = 0
    WidthDesk = Rectan.Right - Rectan.Left
    HeightDesk = Rectan.Bottom - Rectan.Top
   
    hDCDesk = GetWindowDC(hwnd)
   
    newWidth = WidthDesk * Screen.TwipsPerPixelX
    newHeight = HeightDesk * Screen.TwipsPerPixelY
    pic.Width = IIf(pic.Width < newWidth, newWidth, pic.Width)
    pic.Height = IIf(pic.Height < newHeight, newHeight, pic.Height)
   
    picW = pic.Width
    picH = pic.Height
   
    Debug.Print "WidthDesk:newWidth:pic.Width: " & WidthDesk & ": " & newWidth & ": " & pic.Width
    Debug.Print "HeightDesk:newHeight:pic.Height: " & HeightDesk & ": " & newHeight & ": " & pic.Height
   
    i = BitBlt(pic.hdc, 0, 0, WidthDesk, HeightDesk, hDCDesk, LeftDesk, TopDesk, vbSrcCopy)
    pic.Tag = "PrintHwnd"
   
    Call ReleaseDC(hwnd, hDCDesk)
End Sub

Try like:

PrintHwnd Text1.hwnd, Picture1
0
 
tonyleungAuthor Commented:
ryancys,
I found that it is work when the form scalemode set as 1-trip!
However, i must set the scalemode of form and the picturebox as 3-resolution!
Is there any method on it?
Or, is there any method for convert the scalemode value from 3 to 1 and 1 to 3?
 
0
 
CleanupPingCommented:
tonyleung:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
DanRollinsCommented:
tonyleung, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Refund points and save as a 0-pt PAQ.

DanRollins -- EE database cleanup volunteer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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