IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Smiley animé et richtextbox


Sujet :

VB.NET

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2014
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2014
    Messages : 11
    Points : 8
    Points
    8
    Par défaut Smiley animé et richtextbox
    Bonjour, à vous
    Est-il possible de mettre enfin insérer un smiley animé dans une richtextbox ?
    Pour l'insertion d'un gif pas de problème j'ai le code il fonctionne, le problème se trouve juste sur la visualisation des gif animé dans la richtextbox.
    Après j'utilise pas la richtextbox de base j'utilise une autre basé sur la richtextbox avec les fonction d'impression formaté (RichtextboxCtrlPrint donné sur le forum de microsoft)
    Je suppose que pour les gif animé il faut passé par une nouvelle librairie de class ? Y a-t-il une autre possibilité, des piste ou un controler fini (dll) disponible
    Je code en vb.net, framework 3.5, c'est pour un logiciel de chat, les autre fonction ne pose pas de problème
    Merci d'avance
    Benoit

  2. #2
    Inactif  

    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2012
    Messages
    4 904
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2012
    Messages : 4 904
    Points : 10 168
    Points
    10 168
    Billets dans le blog
    36
    Par défaut
    Bonjour,

    Il y a bien cela, mais c'est supposé être pour WPF et non des Windows Forms:

    https://code.msdn.microsoft.com/VBWP...edGIF-93d061e5

    Et je ne l'ai jamais essayé.

    Ajout:

    Par curiosité je suis allé sur Nuget et j'ai trouvé cela:

    https://www.nuget.org/packages?q=gifplayer

    Sauf qu'ils disent que c'est pour Windows 8.1
    À ma connaissance, le seul personnage qui a été diagnostiqué comme étant allergique au mot effort. c'est Gaston Lagaffe.

    Ô Saint Excel, Grand Dieu de l'Inutile.

    Excel n'a jamais été, n'est pas et ne sera jamais un SGBD, c'est pour cela que Excel s'appelle Excel et ne s'appelle pas Access junior.

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2014
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2014
    Messages : 11
    Points : 8
    Points
    8
    Par défaut
    Merci de ta réponse même si ça ne ma pas beaucoup aider mais donner des pistes.

    Après je suis tomber sur ce site http://www.codeproject.com/Articles/...-which-can-dis

    Du coup j'ai réussi a en faire un controller en VB.net enfin presque petit problème avec une petit partie du code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    public TRichTextBox()
                : base()
            {
                this.VScroll += new EventHandler(TRichTextBox_VScroll);
                this.SizeChanged += new EventHandler(TRichTextBox_SizeChanged);
                this.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.TRichTextBox_LinkClicked);
            }
    que je n'arrive pas à tramposé

    le code de ma richtextbox est :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
     
    Option Explicit On
     
    Imports System
    Imports System.Windows.Forms
    Imports System.Drawing
    Imports System.Runtime.InteropServices
    Imports System.Drawing.Printing
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Text
     
    Namespace RichTextBoxPrintCtrl
        Public Class RichTextBoxPrintCtrl
            Inherits RichTextBox
            ' Convert the unit that is used by the .NET framework (1/100 inch) 
            ' and the unit that is used by Win32 API calls (twips 1/1440 inch)
            Private Const AnInch As Double = 14.4
            Const MaximumTextLength As Integer = 10000
            Const TextLengthToBeRemoved As Integer = 3000
            Const MaximumNoOfControl As Integer = 50
            Const NoOfControlToBeRemoved As Integer = 20
            Private KeepShort As Boolean = True
     
     
            <StructLayout(LayoutKind.Sequential)> _
            Private Structure RECT
                Public Left As Integer
                Public Top As Integer
                Public Right As Integer
                Public Bottom As Integer
            End Structure
     
            <StructLayout(LayoutKind.Sequential)> _
            Private Structure CHARRANGE
                Public cpMin As Integer          ' First character of range (0 for start of doc)
                Public cpMax As Integer          ' Last character of range (-1 for end of doc)
            End Structure
     
            <StructLayout(LayoutKind.Sequential)> _
            Private Structure FORMATRANGE
                Public hdc As IntPtr             ' Actual DC to draw on
                Public hdcTarget As IntPtr       ' Target DC for determining text formatting
                Public rc As Rect                ' Region of the DC to draw to (in twips)
                Public rcPage As Rect            ' Region of the whole DC (page size) (in twips)
                Public chrg As CHARRANGE         ' Range of text to draw (see above declaration)
            End Structure
     
            Private Const WM_USER As Integer = &H400
            Private Const EM_FORMATRANGE As Integer = WM_USER + 57
            <DllImport("user32.dll")> _
                  Private Shared Function SendMessage(hwnd As IntPtr, wMsg As Int32, wParam As Int32, ByRef pt As Point) As Integer
            End Function
            Const EM_GETSCROLLPOS As Integer = &H400 + 221
     
            Private ControlList As New List(Of MetaInfo)()
     
            'Contains the initial position data of a control relative to the text content.
            Friend Class MetaInfo
                Private m_charIndex As Integer
                Public Property CharIndex() As Integer
                    Get
                        Return m_charIndex
                    End Get
                    Set(value As Integer)
                        m_charIndex = value
                    End Set
                End Property
     
                Private m_deltaY As Integer
                Public Property DeltaY() As Integer
                    Get
                        Return m_deltaY
                    End Get
                    Set(value As Integer)
                        m_deltaY = value
                    End Set
                End Property
     
                Private m_theControl As Control
                Public Property TheControl() As Control
                    Get
                        Return m_theControl
                    End Get
                    Set(value As Control)
                        m_theControl = value
                    End Set
                End Property
     
                Public Sub New(theControl As Control)
                    Me.m_theControl = theControl
                End Sub
     
            End Class
     
            Public Sub AddControl(oneControl As Control)
                ' Obtain the initial metadata.
                Dim one As New MetaInfo(oneControl)
                MyBase.Controls.Add(oneControl)
                one.CharIndex = Me.TextLength
                one.TheControl.Location = Me.GetPositionFromCharIndex(one.CharIndex)
                one.DeltaY = Me.GetPositionFromCharIndex(0).Y - one.TheControl.Location.Y
                ControlList.Add(one)
     
                '"Push" the text away from the space occupied by the control.
                Do
                    Me.AppendText(Environment.NewLine)
                Loop While Me.GetPositionFromCharIndex(Me.TextLength).Y < (oneControl.Location.Y + oneControl.Height)
     
                RemoveSome()
                AutoScroll()
            End Sub
     
            Public Sub AutoScroll()
                Me.SelectionStart = Me.TextLength - 1
                Me.ScrollToCaret()
            End Sub
     
            Private Sub RemoveSome()
                'Optional. 
                'Remove some text and control if too many, to release system resources and improve performance.
                If Not KeepShort Then
                    Return
                End If
     
                Dim texttoRemove As Integer = 0
                Dim imgtoRemove As Integer = 0
                Try
                    If Me.TextLength > MaximumTextLength Then
                        texttoRemove = TextLengthToBeRemoved
                        Me.Text = Me.Text.Substring(texttoRemove)
                        texttoRemove += Me.Text.IndexOf(vbLf)
                        If texttoRemove > TextLengthToBeRemoved Then
                            Me.Text = Me.Text.Substring(texttoRemove - TextLengthToBeRemoved)
                        End If
     
                        For Each oldone As MetaInfo In ControlList
                            If oldone.CharIndex < texttoRemove Then
                                imgtoRemove += 1
                            Else
                                oldone.CharIndex -= texttoRemove
                            End If
                        Next
     
                        For i As Integer = 0 To imgtoRemove - 1
                            Me.Controls(0).Dispose()
                            ControlList.RemoveAt(0)
                        Next
                        'need to calculate the metadata again.
                        CalculateDelta()
                    End If
                Catch ex As Exception
                    Throw ex
                End Try
     
                Try
                    If ControlList.Count > MaximumNoOfControl Then
                        imgtoRemove = NoOfControlToBeRemoved
                        For i As Integer = 0 To imgtoRemove - 1
                            texttoRemove = ControlList(0).CharIndex
                            ControlList.RemoveAt(0)
                            Me.Controls(0).Dispose()
                        Next
                        Me.Text = Me.Text.Substring(texttoRemove)
                        For Each oldone As MetaInfo In ControlList
                            oldone.CharIndex -= texttoRemove
                        Next
                        'need to calculate the metadata again.
                        CalculateDelta()
                    End If
                Catch ex As Exception
                    Throw ex
                End Try
            End Sub
     
            Private Sub TRichTextBox_VScroll(sender As Object, e As EventArgs)
                Dim pt As New Point()
                SendMessage(Me.Handle, EM_GETSCROLLPOS, 0, pt)
     
                For Each one As MetaInfo In ControlList
                    one.TheControl.Location = New Point(one.TheControl.Location.X, -pt.Y - one.DeltaY)
                Next
            End Sub
     
            Private Sub TRichTextBox_SizeChanged(sender As Object, e As EventArgs)
                CalculateDelta()
            End Sub
     
            Private Sub CalculateDelta()
                For Each one As MetaInfo In ControlList
                    one.TheControl.Location = Me.GetPositionFromCharIndex(one.CharIndex)
                    one.DeltaY = Me.GetPositionFromCharIndex(0).Y - one.TheControl.Location.Y
                Next
            End Sub
     
            Private Sub TRichTextBox_LinkClicked(sender As Object, e As LinkClickedEventArgs)
                System.Diagnostics.Process.Start(e.LinkText)
            End Sub
     
            Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wp As IntPtr, ByVal lp As IntPtr) As IntPtr
     
            ' Render the contents of the RichTextBox for printing
            '	Return the last character printed + 1 (printing start from this point for next page)
            Public Function Print(ByVal charFrom As Integer, ByVal charTo As Integer, ByVal e As PrintPageEventArgs) As Integer
     
                ' Mark starting and ending character 
                Dim cRange As CHARRANGE
                cRange.cpMin = charFrom
                cRange.cpMax = charTo
     
                ' Calculate the area to render and print
                Dim rectToPrint As RECT
                rectToPrint.Top = e.MarginBounds.Top * AnInch
                rectToPrint.Bottom = e.MarginBounds.Bottom * AnInch
                rectToPrint.Left = e.MarginBounds.Left * AnInch
                rectToPrint.Right = e.MarginBounds.Right * AnInch
     
                ' Calculate the size of the page
                Dim rectPage As RECT
                rectPage.Top = e.PageBounds.Top * AnInch
                rectPage.Bottom = e.PageBounds.Bottom * AnInch
                rectPage.Left = e.PageBounds.Left * AnInch
                rectPage.Right = e.PageBounds.Right * AnInch
     
                Dim hdc As IntPtr = e.Graphics.GetHdc()
     
                Dim fmtRange As FORMATRANGE
                fmtRange.chrg = cRange                 ' Indicate character from to character to 
                fmtRange.hdc = hdc                     ' Use the same DC for measuring and rendering
                fmtRange.hdcTarget = hdc               ' Point at printer hDC
                fmtRange.rc = rectToPrint              ' Indicate the area on page to print
                fmtRange.rcPage = rectPage             ' Indicate whole size of page
     
                Dim res As IntPtr = IntPtr.Zero
     
                Dim wparam As IntPtr = IntPtr.Zero
                wparam = New IntPtr(1)
     
                ' Move the pointer to the FORMATRANGE structure in memory
                Dim lparam As IntPtr = IntPtr.Zero
                lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange))
                Marshal.StructureToPtr(fmtRange, lparam, False)
     
                ' Send the rendered data for printing 
                res = SendMessage(Handle, EM_FORMATRANGE, wparam, lparam)
     
                ' Free the block of memory allocated
                Marshal.FreeCoTaskMem(lparam)
     
                ' Release the device context handle obtained by a previous call
                e.Graphics.ReleaseHdc(hdc)
     
                ' Return last + 1 character printer
                Return res.ToInt32()
            End Function
     
        End Class
     
        Class Utility
     
            'Bonus. A simple check on the GIF files because some may contain "bad" data and crash the program.
            Public Shared Function isImageCorrupted(img As Image) As Boolean
                Dim itis As Boolean = False
     
                Try
                    If Not ImageAnimator.CanAnimate(img) Then
                        Return itis
                    End If
                    Dim frames As Integer = img.GetFrameCount(System.Drawing.Imaging.FrameDimension.Time)
                    If frames <= 1 Then
                        Return itis
                    End If
                    Dim times As Byte() = img.GetPropertyItem(&H5100).Value
                    Dim frame As Integer = 0
                    While True
                        Dim dur As Integer = BitConverter.ToInt32(times, 4 * frame)
                        If System.Threading.Interlocked.Increment(frame) >= frames Then
                            Exit While
                        End If
                        img.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Time, frame)
     
                    End While
                Catch ex As Exception
                    Throw ex
                End Try
     
                Return itis
            End Function
     
     
     
     
        End Class
    End Namespace

  4. #4
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2014
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2014
    Messages : 11
    Points : 8
    Points
    8
    Par défaut
    Solution trouver enfin a un petit détaille près la sauvegarde (garder les gif animé lors du chargement [possible de le résoudre en la richtextbox en text brut sans les émoticône] enfin c'est un détail)

    pour le controller
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    using System;
    using System.Windows.Forms;
    using System.Drawing;
    using System.Runtime.InteropServices;
    using System.Drawing.Printing;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
     
     
    namespace RichTextBoxPrint
    {
        public class RichTextBoxPrint : RichTextBox
        {
     
            const int MaximumTextLength = 10000;
            const int TextLengthToBeRemoved = 3000;
            const int MaximumNoOfControl = 50;
            const int NoOfControlToBeRemoved = 20;
            bool KeepShort = true;
     
            [DllImport("user32.dll")]
            private static extern int SendMessage(IntPtr hwnd, Int32 wMsg, Int32 wParam, ref Point pt);
            const int EM_GETSCROLLPOS = 0x0400 + 221;
     
            List<MetaInfo> ControlList = new List<MetaInfo>();
     
            public RichTextBoxPrint()
                : base()
            {
                this.VScroll += new EventHandler(RichTextBoxPrint_VScroll);
                this.SizeChanged += new EventHandler(RichTextBoxPrint_SizeChanged);
                this.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.RichTextBoxPrint_LinkClicked);
            }
     
            //Contains the initial position data of a control relative to the text content.
            internal class MetaInfo
            {
                int charIndex;
                public int CharIndex
                {
                    get { return charIndex; }
                    set { charIndex = value; }
                }
     
                int deltaY;
                public int DeltaY
                {
                    get { return deltaY; }
                    set { deltaY = value; }
                }
     
                Control theControl;
                public Control TheControl
                {
                    get { return theControl; }
                    set { theControl = value; }
                }
     
                public MetaInfo(Control theControl)
                {
                    this.theControl = theControl;
                }
     
            }
     
            public void AddControl(Control oneControl)
            {
                // Obtain the initial metadata.
                MetaInfo one = new MetaInfo(oneControl);
                base.Controls.Add(oneControl);
                one.TheControl.Location = this.GetPositionFromCharIndex(this.SelectionStart);
                one.DeltaY = this.GetPositionFromCharIndex(0).Y - one.TheControl.Location.Y;
                ControlList.Add(one);
     
                RemoveSome();
                AutoScroll();
            }
     
            public void AutoScroll()
            {
                this.SelectionStart = this.TextLength - 1;
                this.ScrollToCaret();
            }
     
            private void RemoveSome()
            {
                //Optional. 
                //Remove some text and control if too many, to release system resources and improve performance.
                if (!KeepShort)
                {
                    return;
                }
     
                int texttoRemove = 0;
                int imgtoRemove = 0;
                try
                {
                    if (this.TextLength > MaximumTextLength)
                    {
                        texttoRemove = TextLengthToBeRemoved;
                        this.Text = this.Text.Substring(texttoRemove);
                        texttoRemove += this.Text.IndexOf("\n");
                        if (texttoRemove > TextLengthToBeRemoved)
                        {
                            this.Text = this.Text.Substring(texttoRemove - TextLengthToBeRemoved);
                        }
     
                        foreach (MetaInfo oldone in ControlList)
                        {
                            if (oldone.CharIndex < texttoRemove)
                            {
                                imgtoRemove++;
                            }
                            else
                            {
                                oldone.CharIndex -= texttoRemove;
                            }
                        }
     
                        for (int i = 0; i < imgtoRemove; i++)
                        {
                            this.Controls[0].Dispose();
                            ControlList.RemoveAt(0);
                        }
                        //need to calculate the metadata again.
                        CalculateDelta();
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
     
                try
                {
                    if (ControlList.Count > MaximumNoOfControl)
                    {
                        imgtoRemove = NoOfControlToBeRemoved;
                        for (int i = 0; i < imgtoRemove; i++)
                        {
                            texttoRemove = ControlList[0].CharIndex;
                            ControlList.RemoveAt(0);
                            this.Controls[0].Dispose();
                        }
                        this.Text = this.Text.Substring(texttoRemove);
                        foreach (MetaInfo oldone in ControlList)
                        {
                            oldone.CharIndex -= texttoRemove;
                        }
                        //need to calculate the metadata again.
                        CalculateDelta();
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
     
            private void RichTextBoxPrint_VScroll(object sender, EventArgs e)
            {
                Point pt = new Point();
                SendMessage(this.Handle, EM_GETSCROLLPOS, 0, ref pt);
     
                foreach (MetaInfo one in ControlList)
                {
                    one.TheControl.Location = new Point(one.TheControl.Location.X, -pt.Y - one.DeltaY);
                }
            }
     
            private void RichTextBoxPrint_SizeChanged(object sender, EventArgs e)
            {
                CalculateDelta();
            }
     
            private void CalculateDelta()
            {
                foreach (MetaInfo one in ControlList)
                {
                    one.TheControl.Location = this.GetPositionFromCharIndex(one.CharIndex);
                    one.DeltaY = this.GetPositionFromCharIndex(0).Y - one.TheControl.Location.Y;
                }
            }
     
            private void RichTextBoxPrint_LinkClicked(object sender, LinkClickedEventArgs e)
            {
                System.Diagnostics.Process.Start(e.LinkText);
            }
     
     
     
     
     
     
            //Convert the unit used by the .NET framework (1/100 inch) 
            //and the unit used by Win32 API calls (twips 1/1440 inch)
            private const double anInch = 14.4;
     
            [StructLayout(LayoutKind.Sequential)]
            private struct RECT
            {
                public int Left;
                public int Top;
                public int Right;
                public int Bottom;
            }
     
            [StructLayout(LayoutKind.Sequential)]
            private struct CHARRANGE
            {
                public int cpMin;         //First character of range (0 for start of doc)
                public int cpMax;           //Last character of range (-1 for end of doc)
            }
     
            [StructLayout(LayoutKind.Sequential)]
            private struct FORMATRANGE
            {
                public IntPtr hdc;             //Actual DC to draw on
                public IntPtr hdcTarget;       //Target DC for determining text formatting
                public RECT rc;                //Region of the DC to draw to (in twips)
                public RECT rcPage;            //Region of the whole DC (page size) (in twips)
                public CHARRANGE chrg;         //Range of text to draw (see earlier declaration)
            }
     
            private const int WM_USER = 0x0400;
            private const int EM_FORMATRANGE = WM_USER + 57;
     
            [DllImport("USER32.dll")]
            private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
     
            // Render the contents of the RichTextBox for printing
            //	Return the last character printed + 1 (printing start from this point for next page)
            public int Print(int charFrom, int charTo, PrintPageEventArgs e)
            {
                //Calculate the area to render and print
                RECT rectToPrint;
                rectToPrint.Top = (int)(e.MarginBounds.Top * anInch);
                rectToPrint.Bottom = (int)(e.MarginBounds.Bottom * anInch);
                rectToPrint.Left = (int)(e.MarginBounds.Left * anInch);
                rectToPrint.Right = (int)(e.MarginBounds.Right * anInch);
     
                //Calculate the size of the page
                RECT rectPage;
                rectPage.Top = (int)(e.PageBounds.Top * anInch);
                rectPage.Bottom = (int)(e.PageBounds.Bottom * anInch);
                rectPage.Left = (int)(e.PageBounds.Left * anInch);
                rectPage.Right = (int)(e.PageBounds.Right * anInch);
     
                IntPtr hdc = e.Graphics.GetHdc();
     
                FORMATRANGE fmtRange;
                fmtRange.chrg.cpMax = charTo;				//Indicate character from to character to 
                fmtRange.chrg.cpMin = charFrom;
                fmtRange.hdc = hdc;                    //Use the same DC for measuring and rendering
                fmtRange.hdcTarget = hdc;              //Point at printer hDC
                fmtRange.rc = rectToPrint;             //Indicate the area on page to print
                fmtRange.rcPage = rectPage;            //Indicate size of page
     
                IntPtr res = IntPtr.Zero;
     
                IntPtr wparam = IntPtr.Zero;
                wparam = new IntPtr(1);
     
                //Get the pointer to the FORMATRANGE structure in memory
                IntPtr lparam = IntPtr.Zero;
                lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange));
                Marshal.StructureToPtr(fmtRange, lparam, false);
     
                //Send the rendered data for printing 
                res = SendMessage(Handle, EM_FORMATRANGE, wparam, lparam);
     
                //Free the block of memory allocated
                Marshal.FreeCoTaskMem(lparam);
     
                //Release the device context handle obtained by a previous call
                e.Graphics.ReleaseHdc(hdc);
     
                //Return last + 1 character printer
                return res.ToInt32();
            }
     
        }
    class Utility
        {
     
            //Bonus. A simple check on the GIF files because some may contain "bad" data and crash the program.
            public static bool isImageCorrupted(Image img)
            {
                bool itis = false;
     
                try
                {
                    if (!ImageAnimator.CanAnimate(img))
                    {
                        return itis;
                    }
                    int frames = img.GetFrameCount(System.Drawing.Imaging.FrameDimension.Time);
                    if (frames <= 1)
                    {
                        return itis;
                    }
                    byte[] times = img.GetPropertyItem(0x5100).Value;
                    int frame = 0;
                    for (; ; )
                    {
                        int dur = BitConverter.ToInt32(times, 4 * frame);
                        if (++frame >= frames) break;
                        img.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Time, frame);
                    }
     
                }
                catch (Exception ex)
                {
                    throw ex;
                }
     
                return itis;
            }
        }
    }

    Et pour mettre les émoticônes
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    Dim emoticontable As Hashtable
        Dim maxshortcutlength As Integer
     
    Private Sub EmoticonizeRTB()
     
            'Loop through all indices (chars) of the Rich text box
            For i As Integer = 0 To RichTextBoxPrint1.TextLength - 1
                Dim remaininglength As Integer = RichTextBoxPrint1.TextLength - i 'the trailing length
                'for each possible length
                For emlength As Integer = maxshortcutlength To 1 Step -1
                    If emlength <= remaininglength Then
                        'check if this value of this length exists in the hashtable
                        Dim lengthtext As String = RichTextBoxPrint1.Text.Substring(i, emlength) 'the part of the text ':)' for example with length 2
                        Dim replacewithimage As Image = emoticontable.Item(lengthtext) 'get item
                        If Not IsNothing(replacewithimage) Then 'check if it is found
                            RichTextBoxPrint1.SelectionStart = i
                            Dim theImage As Image = replacewithimage
                            Dim thePic As New PictureBox()
                            thePic.Image = theImage
                            thePic.Size = theImage.Size
                            Me.RichTextBoxPrint1.AddControl(thePic)
     
                            'replace
     
                            RichTextBoxPrint1.Select(i, emlength)
                            Clipboard.SetDataObject(replacewithimage)
                            RichTextBoxPrint1.Paste()
                            Exit For
                        End If
                    End If
                Next
            Next
     
        End Sub
     
        Public Sub InitEmoticons()
            Try
                emoticontable = New Hashtable(30) 'initial capacity to speed up loading
     
     
                emoticontable.Add(":)", New Bitmap("C:\Users\Benoit\Documents\Visual Studio 2012\Projects\Projet A - Copie (2)\WindowsApplication1\bin\Release\smile\51.gif"))
     
                maxshortcutlength = 9 'the largest length of an emoticon value
            Catch ex As Exception
            End Try
     
        End Sub
     
        Public Sub DisposeEmoticons()
            Try
                For Each img As Image In emoticontable.Values
                    img.Dispose()
                Next
                emoticontable.Clear()
                emoticontable = Nothing
            Catch ex As Exception
     
            End Try
     
        End Sub

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. comment integer une animation swf dans une page
    Par naili dans le forum Intégration
    Réponses: 7
    Dernier message: 18/09/2002, 18h54
  2. Comment ne pas rejouer une animation après un clic ?
    Par mmmmhhh dans le forum ActionScript 1 & ActionScript 2
    Réponses: 4
    Dernier message: 04/09/2002, 16h11
  3. [Composants][Animation] Lire une vidéo compressée
    Par femtosa dans le forum Composants VCL
    Réponses: 6
    Dernier message: 03/09/2002, 08h03
  4. Rx Controls Gif animés
    Par toufou dans le forum Composants VCL
    Réponses: 6
    Dernier message: 23/08/2002, 14h09
  5. Passage de parametre a une anim Flash 5
    Par debug dans le forum Intégration
    Réponses: 4
    Dernier message: 03/06/2002, 17h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo