简体   繁体   English

面板自动滚动

[英]Panel scrolling automatically

I have an UserControl and inside it I have some controls and one of these controls is a CheckBox . 我有一个UserControl ,里面有一些控件,其中一个控件是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 . CheckBox执行CheckedChanged操作,该操作调用方法,此方法将Panel某些控件设置为EnabledVisible

When I click to check the CheckBox the Panel where all these controls are inserted scrolls down automatically like the images below. 当我单击以选中CheckBox ,插入了所有这些控件的Panel会自动向下滚动,如下图所示。

How could I stop the Panel scrolling down after checking the CheckBox ? 选中CheckBox后,如何停止Panel向下滚动?

在此处输入图片说明 Inicial position 初始位置

在此处输入图片说明 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 方法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 方法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 方法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;
                }
            }
        }

Changing visible property of the button at the bottom of the panel, set the focus on that item. 更改面板底部按钮的可见属性,将焦点设置在该项目上。 Try just to enable/disable that button instead. 尝试仅启用/禁用该按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM