GIF ANIMADO NO DATAGRIDVIEW NAO FUNCIONA

RO.DRIGOSG 25/04/2011 13:40:40
#372353
Boa tarde pessoal,

Seguinte, tenho um datadrigview e estou tentando colocar um gif animado, porem o mesmo não funciona. A imagem até carrega, mas não fica como um gif , somente como imagem. Peguei esse código no site : http://www.tek-tips.com/viewthread.cfm?qid=1246926&page=322 .

Alguem poderia me ajudar?

Desde já obrigado.

  

Public Class Form1

Dim img As Image = Image.FromFile([Ô]c:\ani.gif[Ô])

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

Dim ic As New DataGridViewImageColumn

ic.Width = img.Width

dg.Columns.Add(ic)
AddHandler dg.CellPainting, AddressOf dg_CellPainting
ImageAnimator.Animate(img, New EventHandler(AddressOf OnFrameChanged))
End Sub

Private Sub OnFrameChanged(ByVal sender As Object, ByVal e As EventArgs)
dg.Invalidate()
End Sub

Private Sub dg_CellPainting(ByVal sender As Object, ByVal e As DataGridViewCellPaintingEventArgs)

If e.RowIndex >= 0 AndAlso e.ColumnIndex = 0 Then
e.Paint(e.CellBounds, DataGridViewPaintParts.Background)
ImageAnimator.UpdateFrames()
e.Graphics.DrawImage(img, e.CellBounds.Location)
e.Handled = True
End If

End Sub

End Class

JONATHANSTECKER 25/04/2011 16:55:01
#372391
Testei aqui e funcionou Perfeitamente!
Public Class Form1    
Dim img As Image = Image.FromFile([Ô]c:\ani.gif[Ô])

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

Dim ic As New DataGridViewImageColumn

ic.Width = img.Width

dg.Columns.Add(ic)
AddHandler [txt-color=#e80000]Me.DataGridView1[/txt-color].CellPainting, AddressOf dg_CellPainting [ô] Tome atenção de adicionar esse evento com o nome certo do seu DataGridView
ImageAnimator.Animate(img, New EventHandler(AddressOf OnFrameChanged))
End Sub

Private Sub OnFrameChanged(ByVal sender As Object, ByVal e As EventArgs)
dg.Invalidate()
End Sub

Private Sub dg_CellPainting(ByVal sender As Object, ByVal e As DataGridViewCellPaintingEventArgs)

If e.RowIndex >= 0 AndAlso e.ColumnIndex = 0 Then
e.Paint(e.CellBounds, DataGridViewPaintParts.Background)
ImageAnimator.UpdateFrames()
e.Graphics.DrawImage(img, e.CellBounds.Location)
e.Handled = True
End If

End Sub

End Class
RO.DRIGOSG 26/04/2011 14:43:06
#372493
Então Jhonathan,

Coloquei exatamente igual a este exmplo, porém não funcionou. Já revisei o código para ver se tinha alguma coisa de diferente mas esta tudo igual. Porém arrumei outro jeito de fazer o meu gif. Criei um timer e sobreponho a imagem. Ficou assim:

   
Private Sub trmStatus_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles trmStatus.Tick

For Each grdRows As DataGridViewRow In grdChamado.Rows

If grdRows.Cells(edgvChamados.StatusImagem).Tag = True Then

If Val(grdRows.Cells(edgvChamados.Alerta).Value) = 0 Then
grdRows.Cells(edgvChamados.StatusImagem).Value = My.Resources.exclamation_red_16x16
grdRows.Cells(edgvChamados.Alerta).Value = 1
Else
grdRows.Cells(edgvChamados.StatusImagem).Value = My.Resources.exclamation_white_16x16
grdRows.Cells(edgvChamados.Alerta).Value = 0
End If

End If

Next grdRows

End Sub


Mesmo assim, obrigado pela ajuda.
Tópico encerrado , respostas não são mais permitidas