0
I need an event, which is triggered every time the user clicks Form
, tried to use the event Activated
but the event is shot 8 times for the same click.
I’d like to understand why it’s shot so many times?
While conducting a brief search, I arrived in: Windows Forms Events Lifecycle , but I still can’t figure out why it’s shot 8 times for the same action!
public Menu_Inicial()
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterScreen;
this.Activated += new EventHandler(this.FormGetFocus);
label3.Text = Sessaosistema.NomeUsuario;
label5.Text = Sessaosistema.Departamento;
label4.Text = DateTime.Now.ToLongDateString();
label1.Text = "Versão: Onee 1.10.17.0 Beta";
if (ConfigurationManager.AppSettings["490c840431debb47468cbb81db290654"] != "0")
{
dat_pais.consulta(); // tabela de paises
// é utilizado em:
// Cadastro de cliente;
// Cadastro de fornecedor;
// Emissão de NF;
// Orçamento;
// Pedido de venda.
}
if (ConfigurationManager.AppSettings["b441e9bf13e712e00d99ff2ff5da0af9"] != "0")
{
dat_uf.cmbUF(); // tabela de estados
// é utilizado em:
// Cadastro de cliente;
// Cadastro de fornecedor;
// Emissão de NF;
// Orçamento;
// Pedido de venda.
}
if (ConfigurationManager.AppSettings["02ea6cbd71130a0e01b7a08403a44eda"] != "0")
{
dat_cidade.consulta_cidade(); // tabela de cidades
// é utilizado em:
// Cadastro de cliente;
// Cadastro de fornecedor;
// Emissão de NF;
// Orçamento;
// Pedido de venda.
}
if (ConfigurationManager.AppSettings["4a35aa35aaa7467ff2ad41ed6806b591"] != "0")
{
dat_ncm.consulta(); // tabela de ncm
// é utilizado em:
// Cadastro de produto no estoque;
// Emissão de NF;
// Orçamento;
// Pedido de venda.
}
}
private void Menu_Inicial_Load(object sender, EventArgs e)
{
Thread.Sleep(timeEspera);
set_font();
toolTip();
XtraTabPag_Visible();
Implat_Table_Aux();
loadPrinter.PopulateInstalledPrintersCombo();
if (Sessaosistema.NomeUsuario != "Master")
{
button_opsistema.Enabled = false;
treeView1.Nodes[6].Remove();
}
if (ConfigurationManager.AppSettings["4072c1c3f468878a7d48dd7a4564cb57"] == "0")
{
button_comercial.Visible = false;
}
if (ConfigurationManager.AppSettings["a82a2df07e8039ee4d5a1f46b3f03416"] == "0")
{
button_compras.Visible = false;
}
if (ConfigurationManager.AppSettings["6cfb561ab73cea537cdb793c22c1aa6f"] == "0")
{
button_certificados.Visible = false;
}
if (ConfigurationManager.AppSettings["9046c60fefe66f31f80c61379c92843c"] == "0")
{
button_equipamentos.Visible = false;
}
if (ConfigurationManager.AppSettings["304dac640eee2dfe443840ba5041b7d2"] == "0")
{
button_servicos.Visible = false;
}
if (ConfigurationManager.AppSettings["14b1cf9d15b50e3cc5a19020bca18f59"] == "0")
{
simpleButton1.Visible = false;
}
if (ConfigurationManager.AppSettings["a3cb966624ac67ed7d8e77c0f39ba36f"] == "0")
{
simpleButton2.Visible = false;
}
if (ConfigurationManager.AppSettings["f3c6734eb815854e1ebb0b05cca8a43e"] == "0")
{
simpleButton3.Visible = false;
}
if (ConfigurationManager.AppSettings["4c91d222b139eeccd6eb342f512ec180"] == "0")
{
button_opsistema.Visible = false;
}
if (ConfigurationManager.AppSettings["versao"] != "0")
{
string local = Directory.GetCurrentDirectory();
string stgdestino = local + "\\Documentos Empresa" + "\\" + ConfigurationManager.AppSettings["versao"];
if (File.Exists(stgdestino + "logo"))
{
Image logo = Image.FromFile(stgdestino + "logo");
pictureBox1.Image = logo;
label_bemvindo.Visible = false;
}
}
}
private void FormGetFocus(object sender, EventArgs e)
{
if (Sessaosistema.Departamento == "Compras")
{
loadDiligeInicialCompras();
}
else if (Sessaosistema.Departamento == "PCP")
{
loadDiligeInicialPcp();
}
else if (Sessaosistema.Departamento == "PCP")
{
}
else if (Sessaosistema.Departamento == "Estoque")
{
}
else if (Sessaosistema.Departamento == "Qualidade")
{
}
}
So we can help you, provide a Minimum, Complete and Verifiable code.
– NoobSaibot
This is not the behavior of this event, it may be being caused within your code. Therefore, you should show us your code
– Rovann Linhalis
Yes, the code would make everything much clearer.
– Brewerton Santos
I added part of the code! as requested! thanks
– Thomas Erich Pimentel
We missed the implementation of the click there in the code, no?
– Oralista de Sistemas
it is necessary to know whether these methods
loadDiligeInicialCompras()
,loadDiligeInicialPcp()
among others in this are in the same instantiated class, if these methods open anything else that "steals" the focus from your screen, it will gain focus again as it exits the method, thus firing again the Activated– Celso Lívero
something else, it may seem silly, but it may be happening, in debug mode, if you click on your screen (even paused) the Activated event will be triggered, because your screen gained focus, because the focus was on VS
– Celso Lívero