Nota:
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
Ahora, está listo para completar los otros cuatro métodos.Podría copiar y pegar este código, pero si desea aprender lo máximo con este tutorial, escriba el código y utilice IntelliSense.
Para obtener una versión en vídeo de este tema, vea tutorial 1: Crear un visor de imagen en Visual Basic - vídeo 5 o tutorial 1: Crear un visor de imagen en C# - vídeo 5.
[!NOTA]
El procedimiento recomendado es comentar siempre el código.Los comentarios son información que leerán otras personas y merece la pena dedicar tiempo a hacer que el código resulte fácil de entender.El programa pasa por alto todo lo que hay en una línea de comentario.En Visual C#, para marcar una línea como comentario se escriben dos barras diagonales (//) al principio. En Visual Basic, se utiliza para ello una comilla sencilla (').
Para escribir código para los botones adicionales y una casilla
Agregue el código siguiente:
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 Subprivate 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 o revisar
Para ir al siguiente paso del tutorial, vea Paso 11: Ejecutar el programa y probar otras características.
Para volver al paso anterior del tutorial, vea Paso 9: Revisar, comentar y probar el código.