Meilleur auteur de réponses
Passer de VB6 à VB2010

Question
-
Bonjour,
Je suis contraint de faire migrer appliquation de VB6 à VB2010 et je me plante sur quelques détails qui étaient évidents dans VB6 mais qui ne le sont plus dans VB2010.
Mon problème est le suivant :
J'ai tracé un graphique dans un control PictureBox et je voudrais en faire une copie en .BMP (ou .JPG peu importe d'ailleurs) mais je me plante à chaque fois. Avec VB6, l'instruction correspondante dans un item de menu était "SavePicture Graph.Image, FREPER + FI(1) + ".BMP"", avec, dans mon cas, "Graph", le nom du PictureBox ; "FREPER", celui du répertoire ; FI(1), le nom du fichier sans extension et ".BMP", l'extension correspondante.
Cela va faire une semaine que je sèche sur ce problème.
Vous avez peut-être la réponse.
Bien cordialement
Réponses
-
Ok, le mieux est de supprimer toute information que vous ne souhaitez pas rendre publique. Comme je disais il n'est pas utile de tout montrer mais juste le minimum.
La partie qui manquait est donc que l'on utilise le contrôle PictureBox comme un emplacement pour effectuer nous même le rendu de ce contrôle sans utiliser ses particularités. Le graphique lui-même n'a pas réellement d'importance. Dans ce cas on peut faire qq chose comme :
Private Sub PictureBox1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint ' Dessiner le contrôle e.Graphics.FillEllipse(Brushes.Blue, 0, 0, PictureBox1.Width, PictureBox1.Height) End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click ' Dessiner le contrôle vers une image Dim b As New Bitmap(PictureBox1.Width, PictureBox1.Height) PictureBox1.DrawToBitmap(b, New Rectangle(0, 0, PictureBox1.Width, PictureBox1.Height)) ' Sauver vers un fichier b.Save(System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\Test.png") ' Copier vers le presse-papiers Clipboard.SetData(DataFormats.Bitmap, b) End Sub
Le point clé est donc l'utilisation de DrawToBitmap pour effectuer le rendu de ce contrôle vers une image que l'on peut alors sauver ou copier dans le presse-papier.
Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".- Proposé comme réponse Ciprian Duduiala mercredi 30 novembre 2011 08:56
- Marqué comme réponse Milléquant mercredi 30 novembre 2011 10:35
Toutes les réponses
-
Bonjour,
Donc cela devient Graph.Image.Save (http://msdn.microsoft.com/fr-fr/library/ktx83wah.aspx) qui sauvera une image au format PNG.
Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".- Proposé comme réponse Ciprian Duduiala mardi 29 novembre 2011 07:39
-
Merci pour votre réponse
Ca ne résoud pas mon problème mais en tout cas cela n'en crée pas un autre. C'est déjà ça. Je vais approfondir la question cet après-midi mais attendez-vous à ce que je vous sollicite de nouveau à ce sujet.
Voyez-vous, je ne suis pas informaticien, mais économiste. Si je fais du développement (depuis plus de 40 ans déjà - Fortran, Basic pour TRS80, Basic pour IBM PC, VB4 et VB6), c'est plus par obligation de mon métier que par vocation. Et, ayant désormais passé la soixantaine, il devient de plus en plus en plus difficile de repartir à zéro comme un musicien dont on n'aurait non pas changé la musique mais le manière de noter les partitions.
Bien cordialement
Dr. François Milléquant CR1 CNRS, détaché IR1 CNRS
-
Ca ne résoud pas mon problème...
Merci dans ce cas de préciser ce que cela donne exactement. L'autre possibilité serait par exemple que "tracé un graphique dans un control PictureBox" soit que vous affichiez des données à l'emplacement de ce contrôle et non pas que vous demandiez à ce contrôle d'afficher un bitmap comme je le suppose (c'est l'usage normal d'un contrôle picturebox).Eventuellement, montrez le code le plus court possible permettant de reproduire votre situation exacte.
Le code auquel je pensais est par exemple qq chose comme :
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load ' Générer une image Dim b As New Bitmap(PictureBox1.Width, PictureBox1.Height) Dim g As Graphics = Graphics.FromImage(b) g.FillEllipse(Brushes.Blue, 0, 0, PictureBox1.Width, PictureBox1.Height) g.Dispose() ' Afficher l'image via un contrôle PictureBox PictureBox1.Image = b ' Sauver l'image b.Save(System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\Test.png") End Sub
qui suffit pour montrer comment l'image est générée puis affichée dans un PictureBox et ensuite sauvée sur le bureau.
Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".- Modifié Patrice ScribeMVP, Moderator mardi 29 novembre 2011 12:10 Le code auquel je pensais...
-
Merci de vous intéresser à mon problème. Je vous envoie le listing du code de la partie du programme en question. Certes, il est un peu long (358 lignes, autrefois, lorsque je ne disposais que de 64 ko de mémoire, je faisais nettement plus "serré") mais vous trouverez facilement le problème que se situe à la fin de celui-ci (lignes 346 à 357) en gras. Notez que je rencontre la même difficulté pour copier le contenu du picturebox dans le presse-papier (337-345), en gras également.Je me permets aussi de vous faire parvenir deux copies d’écran du contenu du picturebox, effectuées manuellement pour vous montrer que le tout reste fonctionne.J’espère que mon problème ne tient pas à grand chose, mais c’est justement ce “pas grand chose” qui fait toute la différence.(dans les documents que je vous fais parvenir, il y a la référence à mon “sponsor”, merci de rester discret à ce sujet)Bien cordialement
Public Class FrmIndyTrace ' INDY2012 - version 4.0. pour XXXX ' Module/Feuille : INDY2012 Tracé de graphiques : réalisation manuelle de graphiques ' Auteur : François MILLÉQUANT - Industries & Services Iéseg - Lille ' Date de création : 12 septembre 2011 - dernière révision : ' Déclarations Dim Début(5) As Integer Dim Affiche As Integer Dim ANNEE As Integer 'ex AA Dim AC As Integer Dim BC As Integer Dim MOIS As Integer 'ex BB Dim GF As Integer Dim C1 As Integer 'Type de graphique Dim C2 As Integer 'Échelle du graphique Dim C3 As Integer 'Titre spécifique Dim IY As Integer Dim ESPACED As Integer Dim ESPACER As Integer Dim OM As Integer 'mois minimum de départ d'une série demandée Dim Freper As Integer 'ex MB Dim Durée As Integer Dim Lentitre As Integer Dim NS As Integer Dim NDATA(5) As Integer Dim NMDATA As Integer 'longueur maximale d'une série Dim YEAR1(5) As Integer Dim IYEAR(5) As Integer Dim MOIS1(5) As Integer Dim P As Single Dim PASX As Integer 'pas horizontal Dim PASY As Integer 'pas vertical Dim POSX As Integer Dim POSY As Integer Dim REPONSE As Integer Dim ST As Integer Dim EC As Single Dim STYLE As Integer Dim Valmini As Single Dim Valmaxi As Single Dim Xfin As Integer Dim Yfin As Integer Dim X(5, 2400) As Single Dim Y(5, 2400) As Single Dim YQ(5) As Single Dim YZ As Single Dim YA As Double Dim Y1 As Double Dim Y2 As Double Dim BARRE As String Dim DECIMALES(5) As String Dim DECI As String Dim ECHELLE As String Dim FDI As String Dim FANNEE As String Dim FANNE2 As String Dim FANNE4 As String Dim FREQ As String Dim FREQUENCE(5) As String Dim MISEAJOUR As String Dim MSG As String Dim TITREGRAPH As String Dim TITRESERIE(5) As String Dim Série(5) As String Dim Couleur1 As New Pen(Color.Blue, 1) Dim Couleur2 As New Pen(Color.Red, 1) Dim Couleur3 As New Pen(Color.Green, 1) Dim Couleur4 As New Pen(Color.Black, 1) Dim Couleur5 As New Pen(Color.Orange, 1) Dim CARAC As Font = New Font("Courier New", 9) Dim PEN As New Pen(Color.Black, 1) Dim BROSSE As New SolidBrush(Color.Black) Dim CurrentX As Single Dim CurrentY As Single Private Sub frmIndyTrace_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim Itemp As Integer Dim Jtemp As Integer Dim Ktemp As Integer Dim STEMP As String Dim TEMPORAIRE As String TEMPORAIRE = "Variable alphanumérique temporaire" STEMP = "XXXXXX" Affiche = 0 ' Lecture du fichier de demande Try FileOpen(1, "C:/SERIES/GRAPHIQUE.FI4", OpenMode.Input) 'caractéristiques générales Input(1, ANNEE) Input(1, MOIS) Input(1, C1) Input(1, C2) Input(1, Valmini) Input(1, Valmaxi) Input(1, C3) Input(1, "," + TITREGRAPH + ",") 'nom de chaque série For itemp = 1 To 5 Input(1, STEMP) : Série(Itemp) = STEMP Next Itemp Catch Finally FileClose(1) End Try NS = 0 For Itemp = 1 To 5 If Série(Itemp) <> "VIDE" Then NS = NS + 1 Next Itemp 'Lecture des séries For Itemp = 1 To NS Try FileOpen(1, "C:\SERIES\" + Série(Itemp) + ".TSC", OpenMode.Input) Input(1, Ktemp) : NDATA(Itemp) = Ktemp Input(1, Ktemp) : YEAR1(Itemp) = Ktemp : iyear(Itemp) = Ktemp Input(1, Ktemp) : MOIS1(Itemp) = Ktemp Input(1, STEMP) : FREQUENCE(Itemp) = STEMP Input(1, STEMP) : TITRESERIE(Itemp) = STEMP Input(1, STEMP) : MISEAJOUR = STEMP Input(1, STEMP) : DECIMALES(Itemp) = STEMP For Jtemp = 1 To NDATA(Itemp) Input(1, TEMPORAIRE) : X(Itemp, Jtemp) = Val(TEMPORAIRE) Next Jtemp Catch Finally FileClose(1) End Try Next Itemp 'Vérification de l'homogénéité de la demande 'Étape 1 : Contrôle des fréquences FREQ = FREQUENCE(1) DECI = DECIMALES(1) GF = 0 For Itemp = 1 To NS If FREQ <> FREQUENCE(Itemp) Then GF = 1 Next Itemp If GF <> 0 Then Call ERREUR() : Exit Sub If FREQ = "A" Then Freper = 1 If FREQ = "T" Then Freper = 4 If FREQ = "M" Then Freper = 12 'Étape 2 : Conformité des périodes YA = 1000000000.0# : YZ = 0 For Itemp = 1 To NS YEAR1(Itemp) = (YEAR1(Itemp) * Freper) + MOIS1(Itemp) : YQ(Itemp) = YEAR1(Itemp) + NDATA(Itemp) If YEAR1(Itemp) < YA Then YA = YEAR1(Itemp) : IY = IYEAR(Itemp) : OM = MOIS1(Itemp) If YQ(Itemp) > YZ Then YZ = YQ(Itemp) Next Itemp Durée = YZ - YA : If Durée > 2400 Then GF = 2 : Call ERREUR() : Exit Sub For Itemp = 1 To NS Début(Itemp) = YEAR1(Itemp) - YA For Jtemp = 1 To NDATA(Itemp) Y(Itemp, Jtemp + Début(Itemp)) = X(Itemp, Jtemp) Next Jtemp Début(Itemp) = Début(Itemp) + 1 Next Itemp For Itemp = 1 To NS For Jtemp = 1 To Durée X(Itemp, Jtemp) = 1000000000.0# Next Jtemp Next Itemp If ANNEE < IY Then GF = 3 : Call ERREUR() : Exit Sub If Freper = 1 Then MOIS = 0 Else If MOIS > Freper Or MOIS = 0 Then GF = 3 : Call ERREUR() : Exit Sub If ANNEE = IY - 1 And MOIS < OM Then GF = 3 : Call ERREUR() : Exit Sub If C3 = 1 Then TITREGRAPH = TITRESERIE(1) ST = (ANNEE * Freper) + MOIS : ST = ST - YA + 1 For Itemp = 1 To NS If ST < 1 Then GF = 3 : Call ERREUR() : Exit For Next Itemp If GF <> 0 Then Exit Sub If C2 = 2 And Valmaxi <= Valmini Then GF = 4 : Call ERREUR() : Exit Sub Else Y1 = Valmini : Y2 = Valmaxi 'Étape 3 : Détermination des coordonnées If C1 = 1 Then ECHELLE = "Arithmétique" Else ECHELLE = "Semi-log." If C1 = 2 Then For Itemp = 1 To NS For Jtemp = ST To NDATA(Itemp) + Début(Itemp) - 1 If Y(Itemp, Jtemp) <= 0 Then GF = 5 : Call ERREUR() : Exit For Else Y(Itemp, Jtemp) = Math.Log(Y(Itemp, Jtemp)) Next Jtemp Next Itemp End If If GF <> 0 Then Exit Sub 'Étape 4 : Détermination du maximum et du minimum If C2 = 1 Then Y1 = 1000000000.0# : Y2 = -1000000000.0# : NMDATA = 0 For Itemp = 1 To NS For Jtemp = ST To NDATA(Itemp) + Début(Itemp) - 1 If Y(Itemp, Jtemp) < Y1 Then Y1 = Y(Itemp, Jtemp) If Y(Itemp, Jtemp) > Y2 Then Y2 = Y(Itemp, Jtemp) Next Jtemp Next Itemp End If 'Étape 5 : Détermination de la longueur maximale d'une série For Itemp = 1 To NS If NMDATA < NDATA(Itemp) - ST Then NMDATA = NDATA(Itemp) - ST + 1 Next Itemp Affiche = 1 End Sub Private Sub ERREUR() Select Case GF Case 1 MSG = "Fréquences incompatibles" Case 2 MSG = "La durée totale est trop importante" Case 3 MSG = "Coordonnées de départ incorrectes" Case 4 MSG = "Le minimum dépasse le maximum" Case 5 MSG = "Graphique impossible en semi-log" End Select BARRE = "EXECUTER" : MSG = "Erreur : " & MSG : STYLE = vbExclamation & vbOKOnly REPONSE = MsgBox(MSG, STYLE, BARRE) End Sub Private Sub RetourToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RetourToolStripMenuItem.Click FrmIndyMenup.Show() Me.Close() End Sub Private Sub ModifierToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ModifierToolStripMenuItem.Click FrmIndyGraf.Show() Me.Close() End Sub Private Sub PicBox_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PicBox.Paint If Affiche = 0 Then Exit Sub Dim JTEMP As Integer Dim Itemp As Integer e.Graphics.Clear(Color.White) 'définitions initales Xfin = 1100 Yfin = 650 BC = MOIS AC = ANNEE PASY = Yfin - 20 EC = Y2 - Y1 P = EC / PASY 'Dessin du cadre PASX = Int((((Xfin - 20) / NMDATA)) - 0.5) If C1 = 1 Then FDI = Format(Y2, DECI) Else FDI = Format(Math.Exp(Y2), DECI) e.Graphics.DrawString(FDI, CARAC, BROSSE, 40, 49) If C1 = 1 Then FDI = Format(Y1, DECI) Else FDI = Format(Math.Exp(Y1), DECI) e.Graphics.DrawString(FDI, CARAC, BROSSE, 40, Yfin - 47) e.Graphics.DrawLine(PEN, 80, 60, 80, Yfin - 40) e.Graphics.DrawLine(PEN, 80, Yfin - 40, Xfin, Yfin - 40) e.Graphics.DrawLine(PEN, 80, 60, Xfin, 60) e.Graphics.DrawLine(PEN, Xfin, 60, Xfin, Yfin - 40) CurrentY = 10 Lentitre = Len(TITREGRAPH) * 8 CurrentX = ((Xfin - Lentitre) / 2) e.Graphics.DrawString(TITREGRAPH, New Font("Courier New", 12), BROSSE, CurrentX, CurrentY) CurrentX = Xfin - 325 CurrentY = 42 e.Graphics.DrawString("I&S-XXXXXXXXXXXXXXX", CARAC, BROSSE, CurrentX, CurrentY) FDI = "Échelle " + ECHELLE CurrentX = 80 e.Graphics.DrawString(FDI, CARAC, BROSSE, CurrentX, CurrentY) 'Dessin des courbes DES1: POSX = 80 : JTEMP = ST DES2: If BC = 1 Then e.Graphics.DrawLine(PEN, POSX, 60, POSX, Yfin - 40) e.Graphics.DrawLine(PEN, POSX + 1, 60, POSX + 1, Yfin - 40) CurrentX = POSX : CurrentY = Yfin - 39 If Freper = 12 Then e.Graphics.DrawString("j", CARAC, BROSSE, CurrentX - 4, CurrentY) Else e.Graphics.DrawString("1", CARAC, BROSSE, CurrentX - 4, CurrentY) End If If BC > 1 Or JTEMP > NDATA(1) + Début(1) - 1 Then GoTo DES3 FANNE2 = " " FANNE4 = " " FANNEE = CStr(AC) ESPACED = (PASX * Freper) ESPACER = 30 If ESPACER >= ESPACED Then ESPACER = 15 Else FANNE4 = FANNEE CurrentX = POSX + (ESPACED - ESPACER) / 2 : If CurrentX > Xfin Then GoTo DES3 If FANNE2 = " " Then e.Graphics.DrawString(FANNE4, CARAC, BROSSE, CurrentX, CurrentY) Else e.Graphics.DrawString(FANNE2, CARAC, BROSSE, CurrentX, CurrentY) DES3: e.Graphics.DrawLine(PEN, POSX, Yfin - 42, POSX, Yfin - 38) BC = BC + 1 : POSX = POSX + PASX : JTEMP = JTEMP + 1 : If BC > Freper Then BC = 1 : AC = AC + 1 If POSX < Xfin Then GoTo DES2 For Itemp = 1 To NS Select Case Itemp Case 1 JTEMP = ST : POSX = 80 : POSY = 60 + Int(((Y2 - Y(Itemp, JTEMP)) / P) + 0.5) : If POSY < 60 Then POSY = 60 Else If POSY > Yfin - 40 Then POSY = Yfin - 40 e.Graphics.DrawLine(Couleur1, POSX, POSY, POSX, POSY) For JTEMP = ST + 1 To NDATA(Itemp) + Début(Itemp) - 1 CurrentX = POSX CurrentY = POSY POSX = POSX + PASX POSY = 60 + Int(((Y2 - Y(Itemp, JTEMP)) / P) + 0.5) If POSY < 60 Then POSY = 60 Else If POSY > Yfin - 40 Then POSY = Yfin - 40 e.Graphics.DrawLine(Couleur1, CurrentX, CurrentY, POSX, POSY) Next JTEMP Case 2 JTEMP = ST : POSX = 80 : POSY = 60 + Int(((Y2 - Y(Itemp, JTEMP)) / P) + 0.5) : If POSY < 60 Then POSY = 60 Else If POSY > Yfin - 40 Then POSY = Yfin - 40 e.Graphics.DrawLine(Couleur2, POSX, POSY, POSX, POSY) For JTEMP = ST + 1 To NDATA(Itemp) + Début(Itemp) - 1 CurrentX = POSX CurrentY = POSY POSX = POSX + PASX POSY = 60 + Int(((Y2 - Y(Itemp, JTEMP)) / P) + 0.5) If POSY < 60 Then POSY = 60 Else If POSY > Yfin - 40 Then POSY = Yfin - 40 e.Graphics.DrawLine(Couleur2, CurrentX, CurrentY, POSX, POSY) Next JTEMP Case 3 JTEMP = ST : POSX = 80 : POSY = 60 + Int(((Y2 - Y(Itemp, JTEMP)) / P) + 0.5) : If POSY < 60 Then POSY = 60 Else If POSY > Yfin - 40 Then POSY = Yfin - 40 e.Graphics.DrawLine(Couleur3, POSX, POSY, POSX, POSY) For JTEMP = ST + 1 To NDATA(Itemp) + Début(Itemp) - 1 CurrentX = POSX CurrentY = POSY POSX = POSX + PASX POSY = 60 + Int(((Y2 - Y(Itemp, JTEMP)) / P) + 0.5) If POSY < 60 Then POSY = 60 Else If POSY > Yfin - 40 Then POSY = Yfin - 40 e.Graphics.DrawLine(Couleur3, CurrentX, CurrentY, POSX, POSY) Next JTEMP Case 4 JTEMP = ST : POSX = 80 : POSY = 60 + Int(((Y2 - Y(Itemp, JTEMP)) / P) + 0.5) : If POSY < 60 Then POSY = 60 Else If POSY > Yfin - 40 Then POSY = Yfin - 40 e.Graphics.DrawLine(Couleur4, POSX, POSY, POSX, POSY) For JTEMP = ST + 1 To NDATA(Itemp) + Début(Itemp) - 1 CurrentX = POSX CurrentY = POSY POSX = POSX + PASX POSY = 60 + Int(((Y2 - Y(Itemp, JTEMP)) / P) + 0.5) If POSY < 60 Then POSY = 60 Else If POSY > Yfin - 40 Then POSY = Yfin - 40 e.Graphics.DrawLine(Couleur4, CurrentX, CurrentY, POSX, POSY) Next JTEMP Case 5 JTEMP = ST : POSX = 80 : POSY = 60 + Int(((Y2 - Y(Itemp, JTEMP)) / P) + 0.5) : If POSY < 60 Then POSY = 60 Else If POSY > Yfin - 40 Then POSY = Yfin - 40 e.Graphics.DrawLine(Couleur5, POSX, POSY, POSX, POSY) For JTEMP = ST + 1 To NDATA(Itemp) + Début(Itemp) - 1 CurrentX = POSX CurrentY = POSY POSX = POSX + PASX POSY = 60 + Int(((Y2 - Y(Itemp, JTEMP)) / P) + 0.5) If POSY < 60 Then POSY = 60 Else If POSY > Yfin - 40 Then POSY = Yfin - 40 e.Graphics.DrawLine(Couleur5, CurrentX, CurrentY, POSX, POSY) Next JTEMP End Select Next Itemp End Sub
<strong>Private Sub CopierToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CopierToolStripMenuItem.Click Clipboard.Clear() Dim Image As New Bitmap(PicBox.Width, PicBox.Height) PicBox.Image = Image 'Problème : PicBox.image a une valeur "null" Clipboard.SetImage(IMAGE) BARRE = "COPIER" : MSG = "Le graphique " & Série(1) & "a été copié dans le presse-papier" : STYLE = vbExclamation & vbOKOnly REPONSE = MsgBox(MSG, STYLE, BARRE) End Sub </strong>
<strong>Private Sub SauverToolStripMenuItem_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles SauverToolStripMenuItem.Click 'même problème que pour copier : Picbox.image a une valeur "null" ' Générer une image Dim Image As New Bitmap(PicBox.Width, PicBox.Height) ' Afficher l'image via un contrôle PictureBox PicBox.Image = Image ' Sauver l'image 'Image.Save(System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\Test.png") Image.Save("C:\SERIES\" + Série(1) + ".PNG") 'ou extension BMP BARRE = "SAUVER" : MSG = "Le graphique " & Série(1) & ".PNG a été sauvegardé" : STYLE = vbExclamation & vbOKOnly 'ou extension BMP REPONSE = MsgBox(MSG, STYLE, BARRE) End Sub </strong>
End Class
<img src="http://social.microsoft.com/Forums/getfile/38847/" alt="">
-
Ok, le mieux est de supprimer toute information que vous ne souhaitez pas rendre publique. Comme je disais il n'est pas utile de tout montrer mais juste le minimum.
La partie qui manquait est donc que l'on utilise le contrôle PictureBox comme un emplacement pour effectuer nous même le rendu de ce contrôle sans utiliser ses particularités. Le graphique lui-même n'a pas réellement d'importance. Dans ce cas on peut faire qq chose comme :
Private Sub PictureBox1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint ' Dessiner le contrôle e.Graphics.FillEllipse(Brushes.Blue, 0, 0, PictureBox1.Width, PictureBox1.Height) End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click ' Dessiner le contrôle vers une image Dim b As New Bitmap(PictureBox1.Width, PictureBox1.Height) PictureBox1.DrawToBitmap(b, New Rectangle(0, 0, PictureBox1.Width, PictureBox1.Height)) ' Sauver vers un fichier b.Save(System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\Test.png") ' Copier vers le presse-papiers Clipboard.SetData(DataFormats.Bitmap, b) End Sub
Le point clé est donc l'utilisation de DrawToBitmap pour effectuer le rendu de ce contrôle vers une image que l'on peut alors sauver ou copier dans le presse-papier.
Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".- Proposé comme réponse Ciprian Duduiala mercredi 30 novembre 2011 08:56
- Marqué comme réponse Milléquant mercredi 30 novembre 2011 10:35
-
Et ça fonctionne !... (dans les deux cas, du reste) alors que je n'y croyais plus guère après avoir "écumé", en vain, toute la doc proposée en ligne. Un grand merci pour ce coup de main.
J'en aurai d'ailleurs besoin d'un autre dans pas longtemps, mais je vais auparavant peaufiner cette partie du programme.