Ajout d'un propriété à une Class ! Aider-moi :( je crack

scottmat Messages postés 438 Date d'inscription samedi 24 mai 2003 Statut Membre Dernière intervention 23 janvier 2011 - 26 juin 2006 à 03:30
scottmat Messages postés 438 Date d'inscription samedi 24 mai 2003 Statut Membre Dernière intervention 23 janvier 2011 - 28 juil. 2006 à 14:58
Bonsoir à tous
je me permet de REposter mon message une deuxième fois parceque la je passe mes nuits à bosser et essayer de faire sa. Pour moi ce que je fais me parait logique, mais bon cela marche vraiment pas, donc sa doit pas être si logique que sa lol ! je ne vois pas du tout l'erreur franchement



Voici mon petit problème :



Je voudrais insérer une image dans un Richtextbox tout simplement



J’ai récupérer le code sur vbfrance mais je voudrais rajouter une propriété : Emplacement (qui enregistrerai l’emplacement de l’image insérer)





D’abord une classe générale : <?xml:namespace prefix o ns "urn:schemas-microsoft-com:office:office" /?>









 






Public

Interface Element






   
Property Emplacement() AsString





End

Interface







 







Puis propre à l’objet image :








 






Imports
System.ComponentModel






 






<Serializable()> PublicMustInheritClass IMGElement






   
Implements Element






 







   
Dim _sEmplacementImG AsString = ""






   
Dim ImG AsNew System.Drawing.Rectangle






 







   
Public
Property EmplacementImG() AsStringImplements Element.EmplacementImG






       
Get







           
Return _sEmplacementImG






       
End
Get







       
Set(ByVal value AsString)






            _sEmplacementImG = value






       
End
Set







   
End
Property







 






End

Class







 







Ensuite la class qui définit l’ajout dans le Richtextbox de l’élément :







 






Public

Class InsertionImage






   
Inherits IMGElement






   
Public
Sub add_pictures_to_rtb(ByVal pic As Image, ByVal rtb As RichTextBox, ByVal index AsInteger)






       
Dim a AsInteger






       
Dim b AsInteger






       
Dim tmpobj AsObject






        tmpobj = Clipboard.GetDataObject






        Clipboard.SetDataObject(pic)






        a = rtb.SelectionStart






        b = rtb.SelectionLength






        rtb.SelectionLength = 0






        rtb.SelectionStart = index






        rtb.Paste()






        Clipboard.SetDataObject(tmpobj)






       
If index >= a Then a += 1






        rtb.SelectionStart = a






        rtb.SelectionLength = b






   
End
Sub






End

Class








 







Et pour terminer le code qui insérera l’élément à l’aide d’une boite de dialogue :







   
Private
Sub BtnInsertImg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnInsertImg.Click






       
Try







           
Dim a AsNew InsertionImage ()






           
Dim OpenFiles AsNew OpenFileDialog






 







            OpenFiles.Filter = "Tous les Fichiers (*.*)|*.*"






 







            OpenFiles.FilterIndex = 2






            OpenFiles.RestoreDirectory = True






            OpenFiles.Title = "Inserer une image"






 







           
If OpenFiles.ShowDialog = Windows.Forms.DialogResult.OK Then







                a.EmplacementImG = OpenFiles.FileName







   
            a.add_pictures_to_rtb(New Bitmap(OpenFiles.FileName), Richtextbox, Richtextbox.SelectionStart)






           
End
If







 







       
Catch ex As Exception






            MessageBox.Show("Impossible d'inserer cette image !", MessageBoxButtons.OK, MessageBoxIcon.Warning)






       
End
Try







   
End
Sub








 







Donc j’ai créé ma propriété EmplacementImG. Quand je veux affecter la propriété,c’est avant l’insertion de l’image (voir plus en Gras).








Normalement pas de souci ! Arréter moi si je me trompe svp.









Puis je souhaiterai au doubleclick sur l’image récupérer cette information








 







   
Private
Sub Richtextbox_DoubleClick(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Richtextbox.DoubleClick






 
Dim a AsNew RectangleSimple






        MsgBox(a.EmplacementImG)   





End

Sub








La MsgBox s’affiche correctement mais vide :( d’où vient mon erreur d’après vous ?








Merci

5 réponses

mortalino Messages postés 6786 Date d'inscription vendredi 16 décembre 2005 Statut Membre Dernière intervention 21 décembre 2011 18
26 juin 2006 à 08:15
Question déjà posée...

@++
<?xml:namespace prefix v ns "urn:schemas-microsoft-com:vml" /?><v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><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:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></v:path><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?><o:lock v:ext="edit" aspectratio="t"></o:lock></v:shapetype>  Mortalino 

Le Mystérieux Chevalier "Provençal, le Gaulois"
N'oubliez pas de lire le règlement
0
michel120147 Messages postés 17 Date d'inscription vendredi 8 octobre 2004 Statut Membre Dernière intervention 9 août 2006
26 juin 2006 à 12:02
Salut,

je ne sais pas si ce bout de code pourra d'aider mais voila comment j'affiche des images dans un picturebox

            Try
                Photo.Image = Image.FromFile(My.Application.Info.DirectoryPath + "\photo-timbre" + enreg.photo)
                If Image.FromFile(My.Application.Info.DirectoryPath + "\photo-timbre" + enreg.photo).Width > 210 Or Image.FromFile(My.Application.Info.DirectoryPath + "\photo-timbre" + enreg.photo).Height > 236 Then
                    Dim pho As System.Drawing.Image
                    pho = Photo.Image
                    larg = Image.FromFile(My.Application.Info.DirectoryPath + "\photo-timbre" + enreg.photo).Width
                    haut = Image.FromFile(My.Application.Info.DirectoryPath + "\photo-timbre" + enreg.photo).Height

                    'calcul du ratio largeur hauteur
                    If larg > haut Then
                        rat = (larg / 210)                        haut (haut / rat) : larg 210
                    End If
                    If larg < haut Then
                        rat = (haut / 236)                        larg (larg / rat) : haut 236

                    End If
                    Photo.Image = pho.GetThumbnailImage(CInt(larg), CInt(haut), Nothing, Nothing)

                End If
            Catch ex As ArgumentException
                enreg.photo = "0000.gif"
                Photo.Image = Image.FromFile(My.Application.Info.DirectoryPath + "\photo-timbre" + enreg.photo)

            Catch ex As IO.FileNotFoundException
                enreg.photo = "0000.gif"
                Photo.Image = Image.FromFile(My.Application.Info.DirectoryPath + "\photo-timbre" + enreg.photo)
            End Try
 
0
cs_Amazing Messages postés 35 Date d'inscription lundi 23 juin 2003 Statut Membre Dernière intervention 17 avril 2010 2
26 juin 2006 à 17:16
je ne vois pas pas d'ou vient ta class:'RectangleSimple' ?
mais si tu as ecrit ca:
 Dim a AsNew RectangleSimple
        MsgBox(a.EmplacementImG) 

il est clair la propriété 'EmplacementImG' sera vide puisque tu viens de crée l'objet 'a'
Amazing
0
scottmat Messages postés 438 Date d'inscription samedi 24 mai 2003 Statut Membre Dernière intervention 23 janvier 2011 1
27 juin 2006 à 12:31
tous d'abord merci à tous d'avoir répondu ;)

michel120147 ton merci pour ton code mais moi c'est pour afficher une image dans un richtextbox et non dans un objet picturebox.

mince dsl la class qui définit l’ajout dans le Richtextbox n'est pas InsertionImage pcq je l'ai renommer entre temps par
RectangleSimple.

mon l'obet à été crée + haut à l'insertion de l'image !
donc Dim a As New RectangleSimple est invalide il recréer un objet c'est sa ? 

Est-ce que je n'ai pas fait d'erreur ici : 
    If OpenFiles.ShowDialog Windows.Forms.DialogResult.OK Then<?xml:namespace prefix o ns = "urn:schemas-microsoft-com:office:office" /?>

                a.EmplacementImG = OpenFiles.FileName

                a.add_pictures_to_rtb(New Bitmap(OpenFiles.FileName), Richtextbox, Richtextbox.SelectionStart)

            EndIf

L'emplacement a devrait avoir l'emplacement du fichier image ?
comment récupère t-on une propriété d'un objet déjà créer dans un objet (comme c'est mon cas) alors ?
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
scottmat Messages postés 438 Date d'inscription samedi 24 mai 2003 Statut Membre Dernière intervention 23 janvier 2011 1
28 juil. 2006 à 14:58
y'a personne pour m'aider :( ? j'ai toujours pas trouver de mon coter en tou cas :s
I am Cracking
0
Rejoignez-nous