Usuário com melhor resposta
Gif

Pergunta
-
Bom dia!
Estou tentando colocar um gif em um form, mas ele fica parado enquanto esta processando. Tentei criar uma thread para a execução do Gif, mas nao funcionou.
Basicamente fiz isso:
1) Criei uma ThreadPublic ProcessoThread As Threading.Thread
2) Iniciei
If Me.ProcessoThread Is Nothing Then
'Inicia uma nova Thread
ProcessoThread = New System.Threading.Thread(AddressOf F_Processando)
ProcessoThread.Priority = System.Threading.ThreadPriority.Highest
ProcessoThread.IsBackground = True
Try
ProcessoThread.Start()
Catch ex As Exception
End TryPublic Sub F_Processando()
If Me.InvokeRequired Then
Me.Invoke(New Windows.Forms.MethodInvoker(AddressOf F_Processando))
Return
End If
Me.pb_Processando.Visible = True
Me.Refresh()
End Sub
3) Chamei o metodo
Frm_Mensagem.F_Processando()
Não funciona, estou fazendo algo errado?
Obrigado!
Respostas
-
Veja se com este código retirado deste link funciona:
public partial class Form1 : Form { Bitmap animatedImage = (Bitmap)Properties.Resources.cat21; bool currentlyAnimating = false; //This method begins the animation. public void AnimateImage() { if (!currentlyAnimating) { //Begin the animation only once. ImageAnimator.Animate(animatedImage, new EventHandler(this.OnFrameChanged)); currentlyAnimating = true; } } public Form1() { InitializeComponent(); this.pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint); } void pictureBox1_Paint(object sender, PaintEventArgs e) { AnimateImage(); ImageAnimator.UpdateFrames(); e.Graphics.DrawImage(this.animatedImage, Point.Empty); } //stop the animation private void button1_Click(object sender, EventArgs e) { ImageAnimator.StopAnimate(this.animatedImage, new EventHandler(this.OnFrameChanged)); } //start the animation private void button2_Click(object sender, EventArgs e) { ImageAnimator.Animate(animatedImage, new EventHandler(this.OnFrameChanged)); } //call the paint method of the PictureBox. void OnFrameChanged(object sender, EventArgs e) { this.pictureBox1.Invalidate(); } }
Juliano Nunes - http://linkedin.com/in/julianonunes
Lembre-se de clicar em "Votar como útil" e "Marcar como Resposta" caso tenha respondido sua dúvida.
Remember to "Vote as Helpful" and "Mark as Answer" if your question has been answered.
- Marcado como Resposta Filipe B CastroModerator sexta-feira, 16 de fevereiro de 2018 18:44
Todas as Respostas
-
-
-
Veja se com este código retirado deste link funciona:
public partial class Form1 : Form { Bitmap animatedImage = (Bitmap)Properties.Resources.cat21; bool currentlyAnimating = false; //This method begins the animation. public void AnimateImage() { if (!currentlyAnimating) { //Begin the animation only once. ImageAnimator.Animate(animatedImage, new EventHandler(this.OnFrameChanged)); currentlyAnimating = true; } } public Form1() { InitializeComponent(); this.pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint); } void pictureBox1_Paint(object sender, PaintEventArgs e) { AnimateImage(); ImageAnimator.UpdateFrames(); e.Graphics.DrawImage(this.animatedImage, Point.Empty); } //stop the animation private void button1_Click(object sender, EventArgs e) { ImageAnimator.StopAnimate(this.animatedImage, new EventHandler(this.OnFrameChanged)); } //start the animation private void button2_Click(object sender, EventArgs e) { ImageAnimator.Animate(animatedImage, new EventHandler(this.OnFrameChanged)); } //call the paint method of the PictureBox. void OnFrameChanged(object sender, EventArgs e) { this.pictureBox1.Invalidate(); } }
Juliano Nunes - http://linkedin.com/in/julianonunes
Lembre-se de clicar em "Votar como útil" e "Marcar como Resposta" caso tenha respondido sua dúvida.
Remember to "Vote as Helpful" and "Mark as Answer" if your question has been answered.
- Marcado como Resposta Filipe B CastroModerator sexta-feira, 16 de fevereiro de 2018 18:44
-
-
Bom dia, Davi.
Conseguiu resolver sua dúvida?
Se te ajudou, marque resposta/útil.
MARIANO1776
- Editado Mariano1776 sexta-feira, 16 de fevereiro de 2018 12:57
-
Boa tarde,
Por falta de retorno essa thread está encerrada.
Se necessário, favor abrir uma nova thread.
Atenciosamente,Filipe B de Castro
Esse conteúdo é fornecido sem garantias de qualquer tipo, seja expressa ou implícita
MSDN Community Support
Por favor, lembre-se de Marcar como Resposta as postagens que resolveram o seu problema. Essa é uma maneira comum de reconhecer aqueles que o ajudaram e fazer com que seja mais fácil para os outros visitantes encontrarem a resolução mais tarde.