Usuário com melhor resposta
While em Imagem!

Pergunta
-
Galera quero fazer um efeito, parecendo que a imagem está piscando mais o mesmo somente muda uma vez e pronto:
private void timer1_Tick(object sender, EventArgs e) { int cont = 0; while(cont < 1000) { if (cont %2 == 0) { toolStripButton2.Image = StickNote.Properties.Resources.salvar; } else { toolStripButton2.Image = StickNote.Properties.Resources._close; } cont++; } }
Respostas
-
Veja se entende :
sing System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; namespace MSDN { public partial class Form5 : Form { public Form5() { InitializeComponent(); CheckForIllegalCrossThreadCalls = false; Thread thread = new Thread(new ThreadStart(Gatilho)); thread.Start(); } void Gatilho() { int cont = 0; while (cont < 1000) { if (cont % 2 == 0) { toolStripButton1.Image = MSDN.Properties.Resources.images; } else { toolStripButton1.Image = MSDN.Properties.Resources.Print_PC; } cont++; Thread.Sleep(200); } } } }
Veja que é um Form tente entender dessa maneira !
- Sugerido como Resposta Daniel Brito br segunda-feira, 14 de julho de 2014 19:39
- Marcado como Resposta Raniel Nogueira segunda-feira, 14 de julho de 2014 20:33
Todas as Respostas
-
Galera quero fazer um efeito, parecendo que a imagem está piscando mais o mesmo somente muda uma vez e pronto:
private void timer1_Tick(object sender, EventArgs e) { int cont = 0; while(cont < 1000) { if (cont %2 == 0) { toolStripButton2.Image = StickNote.Properties.Resources.salvar; } else { toolStripButton2.Image = StickNote.Properties.Resources._close; } cont++; } }
Realmente não entendo aonde estou errando! -
Olá tente assim :
rivate void timer1_Tick(object sender, EventArgs e) { int cont = 0; while(cont < 1000) { if (cont %2 == 0) { toolStripButton2.Image = StickNote.Properties.Resources.salvar; } else { toolStripButton2.Image = StickNote.Properties.Resources._close; } cont++; Thread.Sleep(500); } }
-
Olá tente assim :
rivate void timer1_Tick(object sender, EventArgs e) { int cont = 0; while(cont < 1000) { if (cont %2 == 0) { toolStripButton2.Image = StickNote.Properties.Resources.salvar; } else { toolStripButton2.Image = StickNote.Properties.Resources._close; } cont++; Thread.Sleep(500); } }
Não deu certo amigo fez foi travar a aplicação -
Entendi,
faça com thread que vai funcionar :
//para usar thread non safe CheckForIllegalCrossThreadCalls = false; Thread thread = new Thread(new ThreadStart(Gatilho)); thread.Start(); } void Gatilho() { int cont = 0; while (cont < 100) { if (cont % 2 == 0) { toolStripButton2.Image = StickNote.Properties.Resources.Salvar; } else { toolStripButton2.Image = StickNote.Properties.Resources._close; } cont++; Thread.Sleep(200); } }
Use Thread ao invés de Timer que vai funcionar ! Caso queira use thread-Safe pesquise e veja como funciona mas desse modo funciona !
-
Entendi,
faça com thread que vai funcionar :
//para usar thread non safe CheckForIllegalCrossThreadCalls = false; Thread thread = new Thread(new ThreadStart(Gatilho)); thread.Start(); } void Gatilho() { int cont = 0; while (cont < 100) { if (cont % 2 == 0) { toolStripButton2.Image = StickNote.Properties.Resources.Salvar; } else { toolStripButton2.Image = StickNote.Properties.Resources._close; } cont++; Thread.Sleep(200); } }
Use Thread ao invés de Timer que vai funcionar ! Caso queira use thread-Safe pesquise e veja como funciona mas desse modo funciona !
Poderia mostrar um exemplo usando esse método w -
Veja se entende :
sing System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; namespace MSDN { public partial class Form5 : Form { public Form5() { InitializeComponent(); CheckForIllegalCrossThreadCalls = false; Thread thread = new Thread(new ThreadStart(Gatilho)); thread.Start(); } void Gatilho() { int cont = 0; while (cont < 1000) { if (cont % 2 == 0) { toolStripButton1.Image = MSDN.Properties.Resources.images; } else { toolStripButton1.Image = MSDN.Properties.Resources.Print_PC; } cont++; Thread.Sleep(200); } } } }
Veja que é um Form tente entender dessa maneira !
- Sugerido como Resposta Daniel Brito br segunda-feira, 14 de julho de 2014 19:39
- Marcado como Resposta Raniel Nogueira segunda-feira, 14 de julho de 2014 20:33