הפיכת תוכן של RichTextBox לתמונה

מיקי256

New member
הפיכת תוכן של RichTextBox לתמונה

אני מנסה להפוך תוכן של פקד RichTextBox לתמונה, ולא מצליח. חשבתי על משהו עם הGetPixel\SetPixel אך אין לפקד hDC ואני לא מצליח לגשת אליו. תודה מראש לעוזרים..
 
אובייקט -> תמונה

כבר נתתי את הקוד הזה בהקשר דומה (הפיכת MSChart לתמונה), אבל זה מתאים גם הפעם, אחרי שינוי קטנטן. קיצר, תוסיף את הקוד הבא למודול, ותשתמש ב- Obj2Picture Me.RichTextBox1, Me.Picture1 או איכשלא קראת לפקדים שלך. ותהנה. (אגב, אולי הגיע הזמן שזה יהיה בשאלות נפוצות?)
Option Explicit Public Declare Function SendMessage Lib "USER32" Alias _ "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, ByVal lParam As Long) As Long Public Const WM_PAINT = &HF Public Const WM_PRINT = &H317 Public Const PRF_CLIENT = &H4& ' Draw the window's client area. Public Const PRF_CHILDREN = &H10& ' Draw all visible child windows. Public Const PRF_OWNED = &H20& ' Draw all owned windows. Public Sub Obj2Picture(Obj As Object, MyPictureBox As PictureBox, Optional bAutoResize As Boolean = True) Dim rv As Long ' Make sure picturebox is same size as the chart. If bAutoResize Then With MyPictureBox .Height = Obj.Height .Width = Obj.Width End With End If MyPictureBox.AutoRedraw = True rv = SendMessage(Obj.hWnd, WM_PAINT, MyPictureBox.hDC, 0) ' kind of a bug fix MyPictureBox.Picture = MyPictureBox.Image MyPictureBox.AutoRedraw = False ' Sent the picture to the clipboard. Clipboard.Clear Clipboard.SetData MyPictureBox.Picture End Sub​
 
למעלה