copaz Posted September 24, 2003 Posted September 24, 2003 I am trying to change the picturebox that is visible when you hit a button on the form so that all the other picturebox are not visible and only one is visible. This is done in C# so any help would be great. Quote
*Experts* mutant Posted September 24, 2003 *Experts* Posted September 24, 2003 You could use the Visible property to hide all the other ones (set Visible to false) and leave the one you want visible. Quote
AlexCode Posted September 24, 2003 Posted September 24, 2003 (edited) the answer is so obvious that I thinks we didn't get the question right mutant... copaz... is you problem solved or isn't it? I think you want to know HOW to use the visible property isn't it?? If so, use, for example, a Select Case Statement... Try this code: Public Class Form4 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox Friend WithEvents PictureBox2 As System.Windows.Forms.PictureBox Friend WithEvents PictureBox3 As System.Windows.Forms.PictureBox Friend WithEvents PictureBox4 As System.Windows.Forms.PictureBox Friend WithEvents PictureBox5 As System.Windows.Forms.PictureBox Friend WithEvents Button1 As System.Windows.Forms.Button <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.PictureBox1 = New System.Windows.Forms.PictureBox Me.PictureBox2 = New System.Windows.Forms.PictureBox Me.PictureBox3 = New System.Windows.Forms.PictureBox Me.PictureBox4 = New System.Windows.Forms.PictureBox Me.PictureBox5 = New System.Windows.Forms.PictureBox Me.Button1 = New System.Windows.Forms.Button Me.SuspendLayout() ' 'PictureBox1 ' Me.PictureBox1.BackColor = System.Drawing.Color.FromArgb(CType(224, Byte), CType(224, Byte), CType(224, Byte)) Me.PictureBox1.Location = New System.Drawing.Point(8, 8) Me.PictureBox1.Name = "PictureBox1" Me.PictureBox1.Size = New System.Drawing.Size(72, 88) Me.PictureBox1.TabIndex = 0 Me.PictureBox1.TabStop = False ' 'PictureBox2 ' Me.PictureBox2.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(128, Byte), CType(128, Byte)) Me.PictureBox2.Location = New System.Drawing.Point(88, 8) Me.PictureBox2.Name = "PictureBox2" Me.PictureBox2.Size = New System.Drawing.Size(72, 88) Me.PictureBox2.TabIndex = 1 Me.PictureBox2.TabStop = False Me.PictureBox2.Visible = False ' 'PictureBox3 ' Me.PictureBox3.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(192, Byte), CType(128, Byte)) Me.PictureBox3.Location = New System.Drawing.Point(168, 8) Me.PictureBox3.Name = "PictureBox3" Me.PictureBox3.Size = New System.Drawing.Size(72, 88) Me.PictureBox3.TabIndex = 2 Me.PictureBox3.TabStop = False Me.PictureBox3.Visible = False ' 'PictureBox4 ' Me.PictureBox4.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(255, Byte), CType(128, Byte)) Me.PictureBox4.Location = New System.Drawing.Point(248, 8) Me.PictureBox4.Name = "PictureBox4" Me.PictureBox4.Size = New System.Drawing.Size(72, 88) Me.PictureBox4.TabIndex = 3 Me.PictureBox4.TabStop = False Me.PictureBox4.Visible = False ' 'PictureBox5 ' Me.PictureBox5.BackColor = System.Drawing.Color.FromArgb(CType(128, Byte), CType(255, Byte), CType(128, Byte)) Me.PictureBox5.Location = New System.Drawing.Point(328, 8) Me.PictureBox5.Name = "PictureBox5" Me.PictureBox5.Size = New System.Drawing.Size(72, 88) Me.PictureBox5.TabIndex = 4 Me.PictureBox5.TabStop = False Me.PictureBox5.Visible = False ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(104, 120) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(192, 32) Me.Button1.TabIndex = 5 Me.Button1.Text = "Change Visible PictureBox" ' 'Form4 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(400, 166) Me.Controls.Add(Me.Button1) Me.Controls.Add(Me.PictureBox5) Me.Controls.Add(Me.PictureBox4) Me.Controls.Add(Me.PictureBox3) Me.Controls.Add(Me.PictureBox2) Me.Controls.Add(Me.PictureBox1) Me.Name = "Form4" Me.Text = "Form4" Me.ResumeLayout(False) End Sub #End Region Dim SelPictBox As Integer = 1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Select Case SelPictBox Case 1 SelPictBox = 2 Me.PictureBox1.Visible = False Me.PictureBox2.Visible = True Case 2 SelPictBox = 3 Me.PictureBox2.Visible = False Me.PictureBox3.Visible = True Case 3 SelPictBox = 4 Me.PictureBox3.Visible = False Me.PictureBox4.Visible = True Case 4 SelPictBox = 5 Me.PictureBox4.Visible = False Me.PictureBox5.Visible = True Case 5 SelPictBox = 1 Me.PictureBox5.Visible = False Me.PictureBox1.Visible = True End Select End Sub End Class Let us know! if you got it:D Edited September 24, 2003 by AlexCode Quote Software bugs are impossible to detect by anybody except the end user.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.