Partilhar via


Etapa 10: Criar botões Adicional e uma caixa de seleção

Agora você está pronto para Concluído os quatro métodos. Você pode copiar e colar esse código, mas se você deseja obter o máximo deste tutorial, digite o código e usar o IntelliSense.

ObservaçãoObservação

sistema autônomo melhor prática: Comentário sempre seu código. Os comentários são as Informação de uma pessoa Leitura, e vale a pena o Hora para tornar seu código compreensível. Tudo em uma linha de comentário é ignorado pelo programa. No Visual c# Você comenta uma linha, digite Dois barras no começo (/ /), e no Visual Basic comentar uma linha, Iniciando em em com uma aspa simples (').

Para criar uma caixa de seleção e botões Adicional

  • Adicione o seguinte código.

    Private Sub clearButton_Click() Handles clearButton.Click
        ' Clear the picture.
        PictureBox1.Image = Nothing
    End Sub
    
    Private Sub backgroundButton_Click() Handles backgroundButton.Click
        ' Show the color dialog box. If the user clicks OK, change the
        ' PictureBox control's background to the color the user chose.
        If ColorDialog1.ShowDialog() = DialogResult.OK Then
            PictureBox1.BackColor = ColorDialog1.Color
        End If
    End Sub
    
    Private Sub closeButton_Click() Handles closeButton.Click
        ' Close the form.
        Close()
    End Sub
    
    Private Sub CheckBox1_CheckedChanged() Handles CheckBox1.CheckedChanged
        ' If the user selects the Stretch check box, change 
        ' the PictureBox's SizeMode property to "Stretch". If the user 
        ' clears the check box, change it to "Normal".
        If CheckBox1.Checked Then
            PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
        Else
            PictureBox1.SizeMode = PictureBoxSizeMode.Normal
        End If
    End Sub
    
    private void clearButton_Click(object sender, EventArgs e)
    {
        // Clear the picture.
        pictureBox1.Image = null;
    }
    
    private void backgroundButton_Click(object sender, EventArgs e)
    {
        // Show the color dialog box. If the user clicks OK, change the
        // PictureBox control's background to the color the user chose.
        if (colorDialog1.ShowDialog() == DialogResult.OK)
            pictureBox1.BackColor = colorDialog1.Color;
    }
    
    private void closeButton_Click(object sender, EventArgs e)
    {
        // Close the form.
        this.Close();
    }
    
    private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        // If the user selects the Stretch check box, 
        // change the PictureBox's
        // SizeMode property to "Stretch". If the user clears 
        // the check box, change it to "Normal".
        if (checkBox1.Checked)
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
        else
            pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
    }
    

Para continuar ou revisar