Imprimer avec Visual Basic 2005

DEN GILLES Messages postés 10 Date d'inscription mardi 18 avril 2006 Statut Membre Dernière intervention 7 mai 2006 - 6 mai 2006 à 16:42
DEN GILLES Messages postés 10 Date d'inscription mardi 18 avril 2006 Statut Membre Dernière intervention 7 mai 2006 - 7 mai 2006 à 13:28
Bonjour,

Etant Débutant je ne trouve pas de renseignements pour Imprimer la form1 avec tous ses "Label et BoxText..." pour obtenir sur mon imprimante la même chose ou similaire à mon écran et avec mes résultats; avec une mise en page ou autre????? par un Click sur IMPRIMER . Je commence à travailler sur des formulaires et des résulutions mathématiques.

Avez-vous une solution en Visual Basic 2005 a me proposer .

Ou un document simple traitant ces codes......

Je vous remercie et cela servira peut être à d'autre...

Abientot
<?xml:namespace prefix v ns "urn:schemas-microsoft-com:vml" /><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></v:path><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:lock aspectratio="t" v:ext="edit"></o:lock><v:shape id=_x0000_s1027 style="MARGIN-TOP: -7.65pt; Z-INDEX: 1; MARGIN-LEFT: 63.35pt; WIDTH: 405.1pt; POSITION: absolute; HEIGHT: 259.65pt; mso-position-horizontal-relative: text; mso-position-vertical-relative: text" type="#_x0000_t75"><v:imagedata o:title="~AUT0000" src="file:///C:\windows\TEMP\msohtml1\01\clip_image001.png"></v:imagedata><?xml:namespace prefix = w ns = "urn:schemas-microsoft-com:office:word" /><w:wrap side="left"></w:wrap></v:shape>

4 réponses

cs_Willi Messages postés 2375 Date d'inscription jeudi 12 juillet 2001 Statut Modérateur Dernière intervention 15 décembre 2018 22
6 mai 2006 à 18:19
0
Utilisateur anonyme
6 mai 2006 à 20:23
Salut

Utiliser des api en .net n'est pas très conseiller.

Dim
FormImg As New System.Drawing.Bitmap(MyBase.Size.Width, MyBase.Size.Height)MyBase
.DrawToBitmap(FormImg, New System.Drawing.Rectangle(0, 0, MyBase.Size.Width, MyBase.Size.Height))

Ca c'est juste pour la récupération de l'image de ta form, après pour imprimer vois le bout de code que t'as donné willi ou regarde dans la msdn.

Kenji

<HR width="100%" SIZE=2>



Merci de cliquer sur "Réponse acceptée" si une réponse vous convient.
0
cs_Willi Messages postés 2375 Date d'inscription jeudi 12 juillet 2001 Statut Modérateur Dernière intervention 15 décembre 2018 22
6 mai 2006 à 20:33
C'est vrai que j'ai pas regardé le code. Ce n'est pas que c'est déconseillé d'utiliser certaines fonctions de l'api en .net mais à 90% on peut s'en passer grace à la richesse du framework.

Créer un bitmap de ta form comme te montre Kenji et après oui tu peux utiliser le lien que je t'ai fournis.
0
DEN GILLES Messages postés 10 Date d'inscription mardi 18 avril 2006 Statut Membre Dernière intervention 7 mai 2006
7 mai 2006 à 13:28
Bonjour,
je vous remercie de votre aide.

J'obtiens une page blanche. Mes codes sont ci-dessous, quelle erreur ou manque (c'est dure d'être débutant) merci d'avance .


End
Sub





Private
Sub Timer1_Tick(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles Timer1.Tick


Label60.Text = System.DateTime.Now



End
Sub



Private
Declare
Auto
Function BitBlt
Lib
"gdi32.dll" (
ByVal hdcDest
As IntPtr,
ByVal nXDest
As
Integer,
ByVal nWidth
As
Integer,
ByVal nHeight
As
Integer,
ByVal hdcScr
As IntPtr,
ByVal nXSrc
As
Integer,
ByVal nYScr
As
Integer,
ByVal dwRop
As System.Int32)
As
Boolean



Private
Const SRCCOPY
As
Integer = &HCC0020



Private
Declare
Auto
Function GetWindowDC
Lib
"user32"
Alias
"GetWindowDC" (
ByVal hwnd
As System.IntPtr)
As System.IntPtr



Private
Function GetDecoratedFormImage()
As Bitmap



Dim FormImg
As
New System.Drawing.Bitmap(
MyBase.Size.Width,
MyBase.Size.Height)



MyBase.DrawToBitmap(FormImg,
New System.Drawing.Rectangle(0, 0,
MyBase.Size.Width,
MyBase.Size.Height))



End
Function

'Variable utilisé en imprimé
Private m_PrintBitmap
As Bitmap

Private
WithEvents m_PrintDocument
As PrintDocument



'Imprime l'image
Private
Sub PrintDocument1_PrintPage(
ByVal sender
As System.Object,
ByVal e
As System.Drawing.Printing.PrintPageEventArgs)
Handles PrintDocument1.PrintPage

'Dessiner l'image centrée
Dim x
As
Integer = e.MarginBounds.X + (e.MarginBounds.Width - m_PrintBitmap.Width) \ 2

Dim y
As
Integer = e.MarginBounds.Y + (e.MarginBounds.Height - m_PrintBitmap.Height) \ 2e.Graphics.DrawImage(m_PrintBitmap, x, y)



' Seulement sur une page
e.HasMorePages =
False


End
Sub



Private
Sub Button7_Click(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles Button7.Click



Dim m
As PrintDocument =
New PrintDocument



'copier la forme de l'image dans Bitmap


m_PrintBitmap = GetDecoratedFormImage()
m_PrintDocument =
New PrintDocument
m_PrintDocument.Print()



End
Sub
0
Rejoignez-nous