-
Oct 18th, 2012, 02:44 PM
#1
Thread Starter
Member
Simple C# Question
Why doesn't this work? the panel does not show. It really should, it does if i add the panel from the Designer..
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace iPhone_Clone
{
public partial class HomeScreen : Form
{
public HomeScreen()
{
InitializeComponent();
}
Panel Panel = new Panel();
PictureBox PicBox = new PictureBox();
private void HomeScreen_Load(object sender, EventArgs e)
{
Panel.BackColor = Color.Green;
Panel.Width = 50;
Panel.Height = 100;
Panel.Top = 50;
Panel.Left = 50;
PicBox.BackColor = Color.Red;
Panel.Controls.Add(PicBox);
Panel.Visible = true;
}
}
}
-
Oct 18th, 2012, 05:53 PM
#2
Lively Member
Re: Simple C# Question
You need to add the panel to the control collection of the form like you did with the picturebox in the panel.
-
Oct 19th, 2012, 12:32 AM
#3
Thread Starter
Member
-
Oct 19th, 2012, 04:32 AM
#4
Thread Starter
Member
Re: Simple C# Question
This doesn't work..
Code:
This.controls.add(Panel) ;
-
Oct 19th, 2012, 05:50 AM
#5
Re: Simple C# Question
It'll work if you do it properly so you haven't done it properly. Show us what your code actually looks like now.
Also, it's really a very bad idea to use 'Panel' as the name for a variable of type Panel. It's like you're trying to make your code confusing. At least follow the almost universal convention of starting the names of variables with a lower-case letter, but also try to provide a descriptive name that indicates something's purpose and distinguishes it from its type.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|