Bonjour ,
Est-il possible d'imprimer des textbox's dans un pictureBox? J'ai vu pas mal de solutions sur le net mais qui ne marche pas.
http://sbz29.free.fr/PB.JPG
Merci d'avance pour vos solutions.
Version imprimable
Bonjour ,
Est-il possible d'imprimer des textbox's dans un pictureBox? J'ai vu pas mal de solutions sur le net mais qui ne marche pas.
http://sbz29.free.fr/PB.JPG
Merci d'avance pour vos solutions.
J'ai trouvé
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 Public Class Form1 Private Declare Auto Function BitBlt Lib "gdi32.dll" (ByVal _ hdcDest As IntPtr, ByVal nXDest As Integer, ByVal _ nYDest As Integer, ByVal nWidth As Integer, ByVal _ nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc _ As Integer, ByVal nYSrc As Integer, ByVal dwRop As _ System.Int32) As Boolean Private Const COPY As Integer = &HCC0020 Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Dim GR As Graphics = PictureBox1.CreateGraphics Dim bm As New Bitmap(PictureBox1.Width, PictureBox1.Height) Dim pbhdc As IntPtr = GR.GetHdc Dim bitmapgr As Graphics = Graphics.FromImage(bm) Dim bitmaphdc As IntPtr = bitmapgr.GetHdc BitBlt(bitmaphdc, 0, 0, Me.ClientSize.Width, Me.ClientSize.Height, pbhdc, 0, 0, COPY) GR.ReleaseHdc(pbhdc) bitmapgr.ReleaseHdc(bitmaphdc) bm.Save("c:\backup\test.jpg", Drawing.Imaging.ImageFormat.Jpeg) End Sub
bonjour sbz29
utilise l'api net c'est preferable avec la fonction CopyFromScreen de l'objet Graphics du PictureBox.
voici 2 exemples:
le premier dessine le controle TextBox dans un bitmap et l'affiche dans un PictureBox.
le deuxieme dessine le meme controle TextBox dans un bitmap et l'imprime le bmp .Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 Public Class Form1 Public Sub New() ' Cet appel est requis par le Concepteur Windows Form. InitializeComponent() ' Ajoutez une initialisation quelconque après l'appel InitializeComponent(). Me.TextBox1.Text = "Copy From Screen" Me.TextBox1.Multiline = True Me.TextBox1.Font = New Font("Arial", 18) 'ajuste PictureBox1 pour tenir l'image bitmap du Textbox1 Dim taillePic As Size taillePic.Width = Me.TextBox1.Size.Width + 20 taillePic.Height = Me.TextBox1.Size.Height + 20 Me.PictureBox1.Size = taillePic End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Copie vers bmp le TextBox1 If PictureBox1.Image IsNot Nothing Then PictureBox1.Image.Dispose() End If Dim bmp As New Bitmap(Me.TextBox1.Bounds.Width + 10, _ Me.TextBox1.Bounds.Height + 10) Dim gText As Graphics = Graphics.FromImage(bmp) gText.CopyFromScreen( _ Me.PointToScreen(New Point(Me.TextBox1.Left, Me.TextBox1.Top)), _ New Point(10, 10), bmp.Size) gText.Dispose() 'dessine le bmp dans le PictureBox1 PictureBox1.SizeMode = PictureBoxSizeMode.CenterImage PictureBox1.Image = bmp End Sub End Class
nb: la resolution maximale de l'image est egale à celle de l'ecran utilise....Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 Public Class Form2 Private bmpToPrint As Bitmap Public Sub New() ' Cet appel est requis par le Concepteur Windows Form. InitializeComponent() ' Ajoutez une initialisation quelconque après l'appel InitializeComponent(). Me.TextBox1.Text = "Copy From Screen" Me.TextBox1.Multiline = True Me.TextBox1.Font = New Font("Arial", 18) End Sub Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click 'Copie vers bmp le TextBox1 Me.bmpToPrint = New Bitmap(Me.TextBox1.Bounds.Width + 10, _ Me.TextBox1.Bounds.Height + 10) Dim gText As Graphics = Graphics.FromImage(Me.bmpToPrint) gText.CopyFromScreen( _ Me.PointToScreen(New Point(Me.TextBox1.Left, Me.TextBox1.Top)), _ New Point(10, 10), Me.bmpToPrint.Size) gText.Dispose() 'demarre impression Me.PrintDocument1.Print() End Sub 'Pour imprimer des graphismes 'Ajoutez le composant PrintDocument au formulaire. 'Dans le gestionnaire d'événements PrintPage, utilisez la propriété Graphics de la classe PrintPageEventArgs pour indiquer à l'imprimante le type de graphisme dont il s'agit. Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage 'imprime le bmp e.Graphics.DrawImage(Me.bmpToPrint, New Point(10.0, 10.0)) End Sub End Class
bon code..............