jeudi 25 janvier 2018

c# - Panel scrolling automatically

I have an UserControl and inside it I have some controls and one of these controls is a CheckBox. This CheckBox performs a CheckedChanged action that calls a method and this method sets some of the controls of the Panel to Enabled or Visible.

When I click to check the CheckBox the Panel where all these controls are inserted scrolls down automatically like the images below.

How could I stop the Panel scrolling down after checking the CheckBox?

enter image description here Inicial position

enter image description here Position after checking the CheckBox

The code is below

The CheckBox Action

private void usuarioMedicoCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if(usuarioMedicoCheckBox.Checked)
            {
                carregarMedicos();
            } else
            {
                medicos = null;
            }

            usuarioMedicoComboBox.Enabled = usuarioMedicoCheckBox.Checked;
            cadastrarMedicoButton.Enabled = usuarioMedicoCheckBox.Checked;
        }

Method carregarMedico

private void carregarMedicos()
        {
            processandoDados(true);

            ParseQuery<Classes.Medico> query = new ParseQuery<Classes.Medico>();

            query.OrderBy("nomeCompleto").FindAsync().ContinueWith(resultado => {
                if (resultado.IsCompleted && !resultado.IsFaulted)
                {
                    medicos = resultado.Result.ToList();

                    atualizarMedicosComboBoxDelegate atualizarMedicosComboBoxD = new atualizarMedicosComboBoxDelegate(atualizarMedicosComboBox);
                    this.Invoke(atualizarMedicosComboBoxD, new object[] { });
                } else
                {
                    MessageBox.Show("Houve um erro ao buscar os médicos", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                processandoDadosDelegate processandoDadosD = new processandoDadosDelegate(processandoDados);
                this.Invoke(processandoDadosD, new object[] { false });
            });
        }

Method atualizarMedicosComboBox

private void atualizarMedicosComboBox()
        {
            usuarioMedicoComboBox.Items.Clear();

            if (medicos != null && medicos.Count() > 0)
            {
                foreach(Classes.Medico medico in medicos)
                {
                    usuarioMedicoComboBox.Items.Add(medico.nomeCompleto);
                }
            } else
            {
                usuarioMedicoComboBox.Items.Add("Não há médicos cadastrados");
            }
        }

Method processandoDados

private void processandoDados(bool acao)
        {
            if (acao)
            {
                nomeCompletoTextBox.Enabled = false;
                emailTextBox.Enabled = false;
                cpfMaskedTextBox.Enabled = false;
                selecionarFotoButton.Enabled = false;
                usuarioMedicoCheckBox.Enabled = false;
                usuarioMedicoComboBox.Enabled = false;
                cadastrarMedicoButton.Enabled = false;
                usuarioAdmCheckBox.Enabled = false;
                permissoesPacientesGroupBox.Enabled = false;
                permissoesMedicosGroupBox.Enabled = false;
                permissoesUsuariosGroupBox.Enabled = false;
                salvarUsuarioButton.Visible = false;
                salvarUsuarioProgressBar.Visible = true;
            } else
            {
                nomeCompletoTextBox.Enabled = true;
                emailTextBox.Enabled = true;
                cpfMaskedTextBox.Enabled = true;
                selecionarFotoButton.Enabled = true;
                usuarioMedicoCheckBox.Enabled = true;

                if (usuarioMedicoCheckBox.Checked)
                {
                    usuarioMedicoComboBox.Enabled = true;
                    cadastrarMedicoButton.Enabled = true;
                }
                else
                {
                    usuarioMedicoComboBox.Enabled = false;
                    cadastrarMedicoButton.Enabled = false;
                }

                usuarioAdmCheckBox.Enabled = true;
                salvarUsuarioButton.Visible = true;
                salvarUsuarioProgressBar.Visible = false;

                if(!usuarioAdmCheckBox.Checked)
                {
                    permissoesPacientesGroupBox.Enabled = true;
                    permissoesMedicosGroupBox.Enabled = true;
                    permissoesUsuariosGroupBox.Enabled = true;
                }
            }
        }




Aucun commentaire:

Enregistrer un commentaire