Message d'erreur sous vb 2008

haythamonni Messages postés 17 Date d'inscription mercredi 1 avril 2009 Statut Membre Dernière intervention 22 mai 2011 - 16 mai 2011 à 20:31
cs_casy Messages postés 7741 Date d'inscription mercredi 1 septembre 2004 Statut Membre Dernière intervention 24 septembre 2014 - 17 mai 2011 à 22:51
je travaille un pfe sous vb.net 2008 il m'affiche les erreurs suivant:

La classe Form1 peut être conçue, mais il ne s'agit pas de la première classe du fichier. Visual Studio requiert que les concepteurs utilisent la première classe du fichier. Déplacez le code de
la classe afin qu'il s'agisse de la première classe du fichier et essayez de recharger le concepteur.
 
à System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)
à System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
à Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
à   System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)

ya t'il quelqun qui peu me donné une solution


pour les corriger????
merci

9 réponses

cs_casy Messages postés 7741 Date d'inscription mercredi 1 septembre 2004 Statut Membre Dernière intervention 24 septembre 2014 40
16 mai 2011 à 21:26
dans le(s) fichier(s) spécifique à une de tes forms (le form.vb, ou éventuellement le form.designer.vb, tu as rajouter une classe, mais tu l'as mise en début du fichier.

Outre le fait, que l'on devrait éviter de mettre plusieurs classes par fichier, dans le cas du fichier d'une form, les classe ajoutées doivent l'être à la fin du fichier.


[i][b]---- Sevyc64 (alias Casy) ----
[hr]# LE PARTAGE EST NOTRE FORCE #/b/i
0
haythamonni Messages postés 17 Date d'inscription mercredi 1 avril 2009 Statut Membre Dernière intervention 22 mai 2011
16 mai 2011 à 22:45
voici le code:
alr je doit faire 2 form????


' Quote from Book
' Visual Basic.net Programming
' Publisher Water Publisher
' China, Beijing


Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.IO
Imports System.Threading

Imports System.Windows.Forms

public class Pop3Receive
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class

Public Class Form1 : Inherits System.Windows.Forms.Form

Public Sub New()
MyBase.New()

InitializeComponent()
End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

Private components As System.ComponentModel.IContainer

Friend WithEvents txtMailContent As System.Windows.Forms.TextBox
Friend WithEvents btnMailReceive As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents txtID As System.Windows.Forms.TextBox
Friend WithEvents txtPassWord As System.Windows.Forms.TextBox
Friend WithEvents txtServer As System.Windows.Forms.TextBox
Friend WithEvents txtPort As System.Windows.Forms.TextBox
Friend WithEvents lstMailList As System.Windows.Forms.ListBox
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents txtNumber As System.Windows.Forms.TextBox
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents txtSize As System.Windows.Forms.TextBox
Friend WithEvents btnDelete As System.Windows.Forms.Button
Friend WithEvents btnQUIT As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.lstMailList = New System.Windows.Forms.ListBox()
Me.txtMailContent = New System.Windows.Forms.TextBox()
Me.txtID = New System.Windows.Forms.TextBox()
Me.txtServer = New System.Windows.Forms.TextBox()
Me.txtPort = New System.Windows.Forms.TextBox()
Me.txtPassWord = New System.Windows.Forms.TextBox()
Me.btnMailReceive = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.Label4 = New System.Windows.Forms.Label()
Me.Label5 = New System.Windows.Forms.Label()
Me.txtNumber = New System.Windows.Forms.TextBox()
Me.txtSize = New System.Windows.Forms.TextBox()
Me.Label6 = New System.Windows.Forms.Label()
Me.btnDelete = New System.Windows.Forms.Button()
Me.btnQUIT = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'lstMailList
'
Me.lstMailList.ItemHeight = 12
Me.lstMailList.Location = New System.Drawing.Point(20, 48)
Me.lstMailList.Name = "lstMailList"
Me.lstMailList.Size = New System.Drawing.Size(666, 112)
Me.lstMailList.TabIndex = 8
'
'txtMailContent
'
Me.txtMailContent.Location = New System.Drawing.Point(20, 176)
Me.txtMailContent.Multiline = True
Me.txtMailContent.Name = "txtMailContent"
Me.txtMailContent.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.txtMailContent.Size = New System.Drawing.Size(666, 344)
Me.txtMailContent.TabIndex = 9
Me.txtMailContent.Text = ""
'
'txtID
'
Me.txtID.Location = New System.Drawing.Point(727, 40)
Me.txtID.Name = "txtID"
Me.txtID.Size = New System.Drawing.Size(164, 21)
Me.txtID.TabIndex = 0
Me.txtID.Text = ""
'
'txtServer
'
Me.txtServer.Location = New System.Drawing.Point(727, 200)
Me.txtServer.Name = "txtServer"
Me.txtServer.Size = New System.Drawing.Size(164, 21)
Me.txtServer.TabIndex = 3
Me.txtServer.Text = ""
'
'txtPort
'
Me.txtPort.Location = New System.Drawing.Point(727, 144)
Me.txtPort.Name = "txtPort"
Me.txtPort.Size = New System.Drawing.Size(164, 21)
Me.txtPort.TabIndex = 2
Me.txtPort.Text = "110"
'
'txtPassWord
'
Me.txtPassWord.Location = New System.Drawing.Point(727, 93)
Me.txtPassWord.Name = "txtPassWord"
Me.txtPassWord.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.txtPassWord.Size = New System.Drawing.Size(164, 21)
Me.txtPassWord.TabIndex = 1
Me.txtPassWord.Text = ""
'
'btnMailReceive
'
Me.btnMailReceive.Location = New System.Drawing.Point(727, 240)
Me.btnMailReceive.Name = "btnMailReceive"
Me.btnMailReceive.Size = New System.Drawing.Size(164, 24)
Me.btnMailReceive.TabIndex = 6
Me.btnMailReceive.Text = "Check Mail"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(727, 16)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(143, 16)
Me.Label1.TabIndex = 7
Me.Label1.Text = "Account"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(727, 176)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(143, 16)
Me.Label2.TabIndex = 8
Me.Label2.Text = "Server"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(727, 128)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(143, 16)
Me.Label3.TabIndex = 9
Me.Label3.Text = "port"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(727, 72)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(143, 16)
Me.Label4.TabIndex = 10
Me.Label4.Text = "Password"
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(730, 275)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(153, 13)
Me.Label5.TabIndex = 11
Me.Label5.Text = "Total"
'
'txtNumber
'
Me.txtNumber.Location = New System.Drawing.Point(730, 299)
Me.txtNumber.Name = "txtNumber"
Me.txtNumber.Size = New System.Drawing.Size(153, 21)
Me.txtNumber.TabIndex = 4
Me.txtNumber.Text = ""
'
'txtSize
'
Me.txtSize.Location = New System.Drawing.Point(731, 355)
Me.txtSize.Name = "txtSize"
Me.txtSize.Size = New System.Drawing.Size(153, 21)
Me.txtSize.TabIndex = 5
Me.txtSize.Text = ""
'
'Label6
'
Me.Label6.Location = New System.Drawing.Point(731, 331)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(153, 13)
Me.Label6.TabIndex = 13
Me.Label6.Text = "Size(k)"
'
'btnDelete
'
Me.btnDelete.Location = New System.Drawing.Point(492, 8)
Me.btnDelete.Name = "btnDelete"
Me.btnDelete.Size = New System.Drawing.Size(194, 24)
Me.btnDelete.TabIndex = 7
Me.btnDelete.Text = "Delete"
'
'btnQUIT
'
Me.btnQUIT.Location = New System.Drawing.Point(732, 395)
Me.btnQUIT.Name = "btnQUIT"
Me.btnQUIT.Size = New System.Drawing.Size(164, 24)
Me.btnQUIT.TabIndex = 6
Me.btnQUIT.Text = "Quit"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(911, 533)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnQUIT, Me.btnDelete, Me.txtSize, Me.Label6, Me.txtNumber, Me.Label5, Me.Label4, Me.Label3, Me.Label2, Me.Label1, Me.btnMailReceive, Me.txtPassWord, Me.txtPort, Me.txtServer, Me.txtID, Me.txtMailContent, Me.lstMailList})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

Dim myTcpClient As New TcpClient()
Dim myNetworkStream As NetworkStream
Dim blnDelete As Boolean = False

Private Sub btnMailReceive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMailReceive.Click

Dim strMessage
ConnectToMailServer()
Dim t As New Thread(AddressOf GetMailNumber)
t.Start()
End Sub

Public Sub ConnectToMailServer()
Try
Dim strReturnMessage As String

myTcpClient.Connect(txtServer.Text, Integer.Parse(txtPort.Text))
myNetworkStream = myTcpClient.GetStream()
Dim myStreamReader As New StreamReader(myNetworkStream)

strReturnMessage = myStreamReader.ReadLine() + vbCrLf
strReturnMessage += SendCommand(myNetworkStream, "USER " + txtID.Text) + vbCrLf
strReturnMessage += SendCommand(myNetworkStream, "PASS " + txtPassWord.Text) + vbCrLf
MessageBox.Show(strReturnMessage)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Private Sub GetMailNumber()
Dim strMessage(2) As String
Dim strMessageLine As String

strMessageLine = SendCommand(myNetworkStream, "STAT")
strMessage = strMessageLine.Split(" ")

txtNumber.Text = strMessage(1)
txtSize.Text = (Long.Parse(strMessage(2)) / 1000).ToString
GetMailList(Long.Parse(strMessage(1)))

End Sub

Private Sub GetMailList(ByVal lngNumber As Long)
Dim strReturnMessage As String
Dim lngLoop As Long
Dim lngIndex As Long
Try
For lngLoop = 0 To lngNumber - 1
lngIndex = lngLoop + 1
strReturnMessage = "[" + lngIndex.ToString + "]" + SendCommand(myNetworkStream, "LIST " + lngIndex.ToString)

lstMailList.Items.Add(strReturnMessage)
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Private Function SendCommand(ByRef pNetStream As NetworkStream, ByVal pstrCommand As String) As String
Try
Dim strCommand = pstrCommand + vbCrLf
Dim bteCommand() As Byte = Encoding.ASCII.GetBytes(strCommand)

Dim myStreamReader As StreamReader
Dim sstrLine As String
Dim strLine As String

pNetStream.Write(bteCommand, 0, bteCommand.Length)
myStreamReader = New StreamReader(pNetStream)
strLine = myStreamReader.ReadLine()
Return strLine

Catch ex As Exception
Return ex.Message
End Try
End Function

Private Sub lstMailList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstMailList.SelectedIndexChanged
If blnDelete = False Then
Dim t As New Thread(AddressOf GetMessage)
t.Start()
End If
End Sub

Private Sub GetMessage()
Dim strMessageContent As String = ""

Dim intRead As Integer

Dim strCommand = "RETR " + (lstMailList.SelectedIndex + 1).ToString + vbCrLf
Dim bteCommand() As Byte = Encoding.ASCII.GetBytes(strCommand)
Dim myStreamReader As StreamReader


txtMailContent.Text = ""
Try
myNetworkStream.Write(bteCommand, 0, bteCommand.Length)
myStreamReader = New StreamReader(myNetworkStream)
AnalyMessage(myStreamReader)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try


End Sub

Private Sub AnalyMessage(ByVal pStreamReader As StreamReader)
Dim strReadLine As String = ""
Dim sstrReadLine As String = ""

Do While (sstrReadLine Nothing Or sstrReadLine.Length 0)
sstrReadLine = pStreamReader.ReadLine
Loop

txtMailContent.Text += vbCrLf + "--- Header --" + vbCrLf

Do While sstrReadLine.Trim.Length <> 0
sstrReadLine = pStreamReader.ReadLine
txtMailContent.Text += vbCrLf + sstrReadLine
Loop

txtMailContent.Text += vbCrLf + "--- Body --" + vbCrLf

Do
sstrReadLine = pStreamReader.ReadLine
If sstrReadLine.Trim() = "." Then Exit Do
If sstrReadLine <> Nothing Then txtMailContent.Text += vbCrLf + sstrReadLine
Loop

End Sub

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim strReturnMessage As String
Dim intDelete As Integer
intDelete = lstMailList.SelectedIndex + 1
Try
strReturnMessage = SendCommand(myNetworkStream, "DELE " + intDelete.ToString)
txtMailContent.Text = strReturnMessage
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
blnDelete = True
lstMailList.Items.RemoveAt(intDelete - 1)
blnDelete = False
End Sub

Private Sub btnQUIT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQUIT.Click
Dim strReturnMessage As String
Try
strReturnMessage = SendCommand(myNetworkStream, "QUIT")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try


End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
End Class
0
cs_casy Messages postés 7741 Date d'inscription mercredi 1 septembre 2004 Statut Membre Dernière intervention 24 septembre 2014 40
16 mai 2011 à 22:55
Ceci
public class Pop3Receive
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
n'a rien à faire dans ta form.

Tu doit le mettre dans un autre fichier.
Rajoute un module à ton projet et mets-y ce code dedans.



[i][b]---- Sevyc64 (alias Casy) ----
[hr]# LE PARTAGE EST NOTRE FORCE #/b/i
0
haythamonni Messages postés 17 Date d'inscription mercredi 1 avril 2009 Statut Membre Dernière intervention 22 mai 2011
17 mai 2011 à 00:29
bsr.
peut tu me detaillé en etape comment le consteruire ????
merci
voici le lien de tuto

http://www.java2s.com/Tutorial/VB/0400__Socket-Network/Pop3EmailClient.htm
0

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

Posez votre question
cs_casy Messages postés 7741 Date d'inscription mercredi 1 septembre 2004 Statut Membre Dernière intervention 24 septembre 2014 40
17 mai 2011 à 09:05
A vrai dire, je n'avais pas vraiment fait attention, mais cette classe Pop3Receive ne sert à rien. Tu peux directement supprimer ce code (ou le mettre en commentaire), ça ne devrait pas changer grand chose à ton application.

[i][b]---- Sevyc64 (alias Casy) ----
[hr]# LE PARTAGE EST NOTRE FORCE #/b/i
0
haythamonni Messages postés 17 Date d'inscription mercredi 1 avril 2009 Statut Membre Dernière intervention 22 mai 2011
17 mai 2011 à 20:43
merciiiiiiiiiiiiiiiiiiiiiiii cAZY ...mais toujours ca marche pas
0
cs_casy Messages postés 7741 Date d'inscription mercredi 1 septembre 2004 Statut Membre Dernière intervention 24 septembre 2014 40
17 mai 2011 à 20:51
c'est à dire ?


[i][b]---- Sevyc64 (alias Casy) ----
[hr]# LE PARTAGE EST NOTRE FORCE #/b/i
0
haythamonni Messages postés 17 Date d'inscription mercredi 1 avril 2009 Statut Membre Dernière intervention 22 mai 2011
17 mai 2011 à 21:14
j'ai modifier ce code complétement et il marche .mais il reste une seul problème.

le textbox ne lire pas les code html.autre chose.est ce que je peut modifier le listbox pour qu'il m'affiche les e-mail reçu en forme de tableau avec le date d’envoyé.le sujet.e-mail from....




' Quote from Book
' Visual Basic.net Programming
' Publisher Water Publisher
' China, Beijing
Imports System
Imports System.Net.Sockets
Imports System.Net.Security
Imports System.Security.Cryptography.X509Certificates
Imports System.Text
Imports System.IO
Imports System.Windows.Forms.WebBrowser
Imports System.Net
Imports System.Threading
Imports System.Windows.Forms



Public Class Form1 : Inherits System.Windows.Forms.Form
    Dim Server As TcpClient
    Dim NetStrm As System.Net.Security.SslStream
    Dim RdStrm As StreamReader
    Public Sub New()
        MyBase.New()

        InitializeComponent()
    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub


    Friend WithEvents btnMailReceive As System.Windows.Forms.Button
    Friend WithEvents lstMailList As System.Windows.Forms.ListBox
    Friend WithEvents btnDelete As System.Windows.Forms.Button
    Friend WithEvents btnQUIT As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.lstMailList = New System.Windows.Forms.ListBox
        Me.btnMailReceive = New System.Windows.Forms.Button
        Me.btnDelete = New System.Windows.Forms.Button
        Me.btnQUIT = New System.Windows.Forms.Button
        Me.txtMailContent = New System.Windows.Forms.TextBox
        Me.SuspendLayout()
        '
        'lstMailList
        '
        Me.lstMailList.Location = New System.Drawing.Point(17, 45)
        Me.lstMailList.Name = "lstMailList"
        Me.lstMailList.Size = New System.Drawing.Size(555, 95)
        Me.lstMailList.TabIndex = 8
        '
        'btnMailReceive
        '
        Me.btnMailReceive.Location = New System.Drawing.Point(591, 8)
        Me.btnMailReceive.Name = "btnMailReceive"
        Me.btnMailReceive.Size = New System.Drawing.Size(136, 22)
        Me.btnMailReceive.TabIndex = 6
        Me.btnMailReceive.Text = "Check Mail"
        '
        'btnDelete
        '
        Me.btnDelete.Location = New System.Drawing.Point(410, 7)
        Me.btnDelete.Name = "btnDelete"
        Me.btnDelete.Size = New System.Drawing.Size(162, 23)
        Me.btnDelete.TabIndex = 7
        Me.btnDelete.Text = "Delete"
        '
        'btnQUIT
        '
        Me.btnQUIT.Location = New System.Drawing.Point(750, 7)
        Me.btnQUIT.Name = "btnQUIT"
        Me.btnQUIT.Size = New System.Drawing.Size(137, 22)
        Me.btnQUIT.TabIndex = 6
        Me.btnQUIT.Text = "Quit"
        '
        'txtMailContent
        '
        Me.txtMailContent.Location = New System.Drawing.Point(17, 163)
        Me.txtMailContent.Multiline = True
        Me.txtMailContent.Name = "txtMailContent"
        Me.txtMailContent.ScrollBars = System.Windows.Forms.ScrollBars.Both
        Me.txtMailContent.Size = New System.Drawing.Size(555, 320)
        Me.txtMailContent.TabIndex = 9
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(911, 533)
        Me.Controls.Add(Me.btnQUIT)
        Me.Controls.Add(Me.btnDelete)
        Me.Controls.Add(Me.btnMailReceive)
        Me.Controls.Add(Me.txtMailContent)
        Me.Controls.Add(Me.lstMailList)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

    Private Shared Function CertificateValidationCallback(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors__1 As SslPolicyErrors) As Boolean
        If sslPolicyErrors__1 <> SslPolicyErrors.None Then
            MessageBox.Show("SSL Certificate Validation Error!")
            Debug.Print(sslPolicyErrors__1.ToString())
            Return False
        Else
            Return True
        End If
    End Function

    Public Function connect() As Integer
        Dim POP3Account As String
        POP3Account = "pop3.live.com"
        If POP3Account.Trim = "" Then Exit Function
        Try
            Dim certName As String = "pop3.live.com"
            Server = New TcpClient()
            Server.Connect(POP3Account.Trim, 995)
            NetStrm = New SslStream(Server.GetStream(), False, New RemoteCertificateValidationCallback(AddressOf CertificateValidationCallback))
            NetStrm.AuthenticateAsClient(certName)
            RdStrm = New StreamReader(NetStrm)
        Catch exc As Exception
            MsgBox(exc.Message)
            Exit Function
        End Try

        Dim user As String
        user = "sts2012@hotmail.fr"
        Dim data As String = "USER " + user.Trim + vbCrLf
        Dim szData() As Byte = System.Text.Encoding.ASCII.GetBytes(data.ToCharArray())
        NetStrm.Write(szData, 0, szData.Length)
        Dim POPResponse As String
        POPResponse = RdStrm.ReadLine
        If POPResponse.Contains("-ERR") Then
            MsgBox("Invalid user Name")
            Return -1
        End If
        Dim password As String
        password = "sts123"
        data = "PASS " & password & vbCrLf
        szData = System.Text.Encoding.ASCII.GetBytes(data.ToCharArray())
        NetStrm.Write(szData, 0, szData.Length)
        POPResponse = RdStrm.ReadLine
        If POPResponse.Contains("-ERR") Then
            MsgBox("Invalid Password")
            Return (-1)
        End If
        data = "STAT" + vbCrLf
        szData = System.Text.Encoding.ASCII.GetBytes(data.ToCharArray())
        NetStrm.Write(szData, 0, szData.Length)
        POPResponse = RdStrm.ReadLine
        If POPResponse.Substring(0, 4) = "-ERR" Then
            MsgBox("could not log your in")
            Return -1
        End If
        data = "Stat" + vbCrLf
        szData = System.Text.Encoding.ASCII.GetBytes(data.ToCharArray())
        NetStrm.Write(szData, 0, szData.Length)
        POPResponse = RdStrm.ReadLine
        If POPResponse.Contains("-ERR") Then
            MsgBox("could not log your in")
            Return -1
        End If
        Dim parts() As String
        parts = POPResponse.Split(" ")
        Dim messages, totsize As Integer

        'messages = parts(3)
        messages = CInt(parts(1))
        Return messages

    End Function
    Public Function DeleteMessage(ByVal msgIndex As Integer)
        Dim data As String = "DELE " & msgIndex.ToString & vbCrLf
        Dim SzData() As Byte = System.Text.Encoding.ASCII.GetBytes(data.ToCharArray())
        NetStrm.Write(SzData, 0, SzData.Length)
        Dim tmpString As String = RdStrm.ReadLine()
        If tmpString.Substring(0, 4) = "-ERR" Then
            MsgBox("Could Not Delete Message")
            Return (-1)
        Else
            Return 11
        End If
    End Function

    Public Function Quit()
        Dim data As String = "Quit " & vbCrLf
        Dim szData() As Byte = System.Text.Encoding.ASCII.GetBytes(data.ToCharArray())
        NetStrm.Write(szData, 0, szData.Length)
        Dim tmpString As String = RdStrm.ReadLine()
    End Function

    Public Structure Message
        Dim _From As String
        Dim _To As String
        Dim _Date As String
        Dim _Subject As String
        Dim _CC As String
        Dim _BCC As String
        Dim _Body As String
        Dim _Received As String
    End Structure

    Public Function CreateFromText(ByVal strMessage As String) As Message
        Dim Mssg As New Message
        Dim brkPos As Integer
        Dim Header As String
        Dim Headers() As String
        Dim Body As String
        Dim vField As Object
        Dim strHeader As String
        Dim HeaderName As String
        Dim HeaderValue As String
        brkPos = InStr(1, strMessage, vbCrLf & vbCrLf)
        If brkPos Then
            Header = strMessage.Substring(0, brkPos - 1)
            Body = strMessage.Substring(brkPos + 1, _
            strMessage.Length - Header.Length - 3)
            Mssg._Body = Body
        Else
            Throw New Exception("Invalid Message Format")
            Exit Function
        End If
        Headers = Split(Header, vbCrLf)
        Dim _header As String
        For Each _header In Headers
            brkPos = _header.IndexOf(":")
            If brkPos >= 0 Then
                HeaderName = _header.Substring(0, brkPos)
            Else
                HeaderName = ""
            End If
            HeaderValue = _header.Substring(brkPos + 1)
            Select Case HeaderName.ToLower
                Case "received"
                    Mssg._Received = HeaderValue
                Case "from"
                    Mssg._From = HeaderValue
                Case "to"
                    Mssg._To = HeaderValue
                Case "cc"
                    Mssg._CC = HeaderValue
                Case "bcc"
                    Mssg._BCC = HeaderValue
                Case "subject"
                    Mssg._Subject = HeaderValue
                Case "date"
                    Mssg._Date = HeaderValue
            End Select
        Next
        Return Mssg
    End Function
    Function GetMessage(ByVal msgindex As Integer) As String
        Dim tmpString As String
        Dim Data As String
        Dim SzData() As Byte
        Dim msg As String
        Try
            Data = "RETR " & msgindex.ToString & vbCrLf
            SzData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())
            NetStrm.Write(SzData, 0, SzData.Length)
            tmpString = RdStrm.ReadLine()
            If tmpString.Substring(0, 4) <> "-ERR" Then
                While (tmpString <> ".")
                    msg = msg & tmpString & vbCrLf
                    tmpString = RdStrm.ReadLine
                End While
            End If
        Catch exc As InvalidOperationException
            MsgBox("Message Retrival Failed: " & vbCrLf & Err.ToString())
        End Try
        Return msg
    End Function

    Private Sub btnMailReceive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMailReceive.Click
        Dim i As Integer
        Dim msg As Form1.Message
        Dim msgstring As String
        Dim messages1 As Integer
        Me.Cursor = Cursors.WaitCursor
        messages1 = connect()
        If messages1 = -1 Then
            Me.Cursor = Cursors.Default
            Exit Sub
        End If
        Dim originalCaption As String = Me.Text
        For i = 1 To messages1
            Me.Text = "Downloading Message " & i.ToString & "/" & _
            messages1.ToString
            Dim msgitem As New ListViewItem
            msgstring = GetMessage(i)
            msg = CreateFromText(msgstring)
            msgitem.Text = msg._From
            msgitem.SubItems.Add(msg._Subject)
            msgitem.SubItems.Add(msg._Date)
            lstMailList.Items.Add(msgitem)
            RichTextBox1.AppendText(msg._Body & vbCrLf)
        Next
        Me.Text = originalCaption
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub lstMailList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim messages As Integer
        'Dim objPOP3 As POP3Message
        RichTextBox1.Text = GetMessage(lstMailList.SelectedIndices(0) + 1)
    End Sub

    Private Sub lstMailList_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lstMailList.KeyUp
        If e.KeyCode = Keys.Delete Then
            If DeleteMessage(lstMailList.SelectedIndices(0) + 1) >= 0 Then
                lstMailList.Items(lstMailList.SelectedIndices(0)).Text = "DELETED"
                lstMailList.Items(lstMailList.SelectedIndices(0)).SubItems.Clear()
                MsgBox("Your Email Message is Deleted", MsgBoxStyle.Information, "Delete Message")
            End If
        End If
    End Sub

    Private Sub btnQUIT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQUIT.Click
        Call Quit()
        lstMailList.Items.Clear()
    End Sub

    Private Sub lstMailList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstMailList.SelectedIndexChanged

    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub txtMailContent_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMailContent.TextChanged

    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click

    End Sub
End Class
0
cs_casy Messages postés 7741 Date d'inscription mercredi 1 septembre 2004 Statut Membre Dernière intervention 24 septembre 2014 40
17 mai 2011 à 22:51
Je ne pense pas qu'un textbox puisse afficher du html. Peut-être devrais tu essayer un contrôle webbrowser pour voir, en mettant le contenu dans la propriété DocumentText.

Pour la listbox, tu as essayer en mettent la propriété MultiColumn à True ?
Sinon essaye avec une listview à la place.

[i][b]---- Sevyc64 (alias Casy) ----
[hr]# LE PARTAGE EST NOTRE FORCE #/b/i
0
Rejoignez-nous