Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Création d'une propriété et récupération de la Value

2 réponses
Avatar
Mathias
Bonsoir à tous
pour info j'utilise VB.NET 2005

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 :



Public Interface Element

Property Emplacement() As String

End Interface



Puis propre à l'objet image :



Imports System.ComponentModel



<Serializable()> Public MustInherit Class IMGElement

Implements Element



Dim _sEmplacementImG As String = ""

Dim ImG As New System.Drawing.Rectangle



Public Property EmplacementImG() As String Implements
Element.EmplacementImG

Get

Return _sEmplacementImG

End Get

Set(ByVal value As String)

_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 As Integer)

Dim a As Integer

Dim b As Integer

Dim tmpobj As Object

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 As New InsertionImage ()

Dim OpenFiles As New 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 !
Comment fait ?




Merci

2 réponses

Avatar
X
Bonjour, ce n'est pas le bon forum (DotNet)...

--
Merci beaucoup, au revoir et à bientôt :o)
------
Site logiciels
http://irolog.free.fr
Mail
http://irolog.free.fr/ecrire/index.htm
Site perso
http://irolog.free.fr/joe/index.htm
Principe d'utilisation des news Groups
http://support.microsoft.com/directory/worldwide/fr/newsgroup/regles.htm
------------------------------------------------------------------------------------
"Mathias" a écrit dans le message de news:

Bonsoir à tous
pour info j'utilise VB.NET 2005

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 :



Public Interface Element

Property Emplacement() As String

End Interface



Puis propre à l'objet image :



Imports System.ComponentModel



<Serializable()> Public MustInherit Class IMGElement

Implements Element



Dim _sEmplacementImG As String = ""

Dim ImG As New System.Drawing.Rectangle



Public Property EmplacementImG() As String Implements
Element.EmplacementImG

Get

Return _sEmplacementImG

End Get

Set(ByVal value As String)

_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 As Integer)

Dim a As Integer

Dim b As Integer

Dim tmpobj As Object

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 As New InsertionImage ()

Dim OpenFiles As New 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
! Comment fait ?




Merci




Avatar
Mathias
Oups' ! Dsl

"X" a écrit dans le message de news:

Bonjour, ce n'est pas le bon forum (DotNet)...

--
Merci beaucoup, au revoir et à bientôt :o)
------
Site logiciels
http://irolog.free.fr
Mail
http://irolog.free.fr/ecrire/index.htm
Site perso
http://irolog.free.fr/joe/index.htm
Principe d'utilisation des news Groups
http://support.microsoft.com/directory/worldwide/fr/newsgroup/regles.htm
------------------------------------------------------------------------------------
"Mathias" a écrit dans le message de news:

Bonsoir à tous
pour info j'utilise VB.NET 2005

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 :



Public Interface Element

Property Emplacement() As String

End Interface



Puis propre à l'objet image :



Imports System.ComponentModel



<Serializable()> Public MustInherit Class IMGElement

Implements Element



Dim _sEmplacementImG As String = ""

Dim ImG As New System.Drawing.Rectangle



Public Property EmplacementImG() As String Implements
Element.EmplacementImG

Get

Return _sEmplacementImG

End Get

Set(ByVal value As String)

_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 As Integer)

Dim a As Integer

Dim b As Integer

Dim tmpobj As Object

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 As New InsertionImage ()

Dim OpenFiles As New 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 ! Comment fait ?




Merci