473,385 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Window Form, Panel, can't set ZOrder at run time/design time

I'm using VS 2005, .net 2.0 for a desktop application (Window Form app).

I can't set ZOrder of Panel control neither at design time by toolbar/menu
command "Bring to Front"/"Sent to Back" nor at run time by calling
BringToFront method of panel. And Panel control doesn't support SetTopLevel
method etc. I tried this while Dock=Fill and Dock=None but its not working at
all.

Please tell me how can I change Panel's ZOrder specially at run time, I have
to show different panels at different times. Is there any way to do this or I
have to set their Visible to true/false to achieve this.
Nov 20 '06 #1
12 9109
Seems to work fine for me (below)... what are you doing differently?
But yes - changing the visibility is an option, and it sounds like what you
are doing is very similar to the TabPage implementation too...

using System;
using System.Windows.Forms;
class Program
{
static void Main()
{
using (Form form = new Form()) {
for(int i = 0; i < 5; i++) {
Panel p = new Panel();
Button b = new Button();
b.Click += delegate {
p.SendToBack();
};
b.Text = "Panel " + i.ToString();
p.Dock = DockStyle.Fill;
p.Controls.Add(b);
form.Controls.Add(p);
}
Application.Run(form);
}

}
}
Nov 20 '06 #2
Marc,
The only thing I'm doing different is you are creating it at run and I added
it at design time to the form and that is not any different in .net because
designer also adds the same instantiation code. So, the only difference is
your controls creation code is in Main() method and mine is in Form's
constructor.

I checked it again, its still not working neither at design time, nor at run
time even I checked the SendToBack method of panel at run time but its not
working. I can do it with Visible but I have 4-5 panels up and down and I
have to take of visibility of all panels.

Have you executed your code in .net 2.0?

regards,
Adil

"Marc Gravell" wrote:
Seems to work fine for me (below)... what are you doing differently?
But yes - changing the visibility is an option, and it sounds like what you
are doing is very similar to the TabPage implementation too...

using System;
using System.Windows.Forms;
class Program
{
static void Main()
{
using (Form form = new Form()) {
for(int i = 0; i < 5; i++) {
Panel p = new Panel();
Button b = new Button();
b.Click += delegate {
p.SendToBack();
};
b.Text = "Panel " + i.ToString();
p.Dock = DockStyle.Fill;
p.Controls.Add(b);
form.Controls.Add(p);
}
Application.Run(form);
}

}
}
Nov 20 '06 #3
Marc,
Another thing different I'm doing, I forget to tell you is I put my panel
controls inside the SplitContainer control's panel.

regards,
Adil

"Marc Gravell" wrote:
Seems to work fine for me (below)... what are you doing differently?
But yes - changing the visibility is an option, and it sounds like what you
are doing is very similar to the TabPage implementation too...

using System;
using System.Windows.Forms;
class Program
{
static void Main()
{
using (Form form = new Form()) {
for(int i = 0; i < 5; i++) {
Panel p = new Panel();
Button b = new Button();
b.Click += delegate {
p.SendToBack();
};
b.Text = "Panel " + i.ToString();
p.Dock = DockStyle.Fill;
p.Controls.Add(b);
form.Controls.Add(p);
}
Application.Run(form);
}

}
}
Nov 20 '06 #4
Marc,
I tried placing several panels in same project on another form and their
BringToFront/SendToBack working both at design time and runtime. I think the
SplitterContainer is the real culprit and prevents panels to work properly.

Have you any solution for the panels inside SplitterContainer to work or
I'll have to use Visible property.

regards,
Adil

"Marc Gravell" wrote:
Seems to work fine for me (below)... what are you doing differently?
But yes - changing the visibility is an option, and it sounds like what you
are doing is very similar to the TabPage implementation too...

using System;
using System.Windows.Forms;
class Program
{
static void Main()
{
using (Form form = new Form()) {
for(int i = 0; i < 5; i++) {
Panel p = new Panel();
Button b = new Button();
b.Click += delegate {
p.SendToBack();
};
b.Text = "Panel " + i.ToString();
p.Dock = DockStyle.Fill;
p.Controls.Add(b);
form.Controls.Add(p);
}
Application.Run(form);
}

}
}
Nov 20 '06 #5
Have you executed your code in .net 2.0?
Yes

Marc
Nov 20 '06 #6
Still works fine for me... Have you any code that demonstrates this?

using System;
using System.Windows.Forms;
using System.Drawing;
class Program
{
static void Main()
{
using (Form form = new Form())
using (SplitContainer sc = new SplitContainer())
{
sc.Panel1.BackColor = Color.Red;
sc.Panel2.BackColor = Color.Blue;
AddPanels(sc.Panel1);
AddPanels(sc.Panel2);
sc.Dock = DockStyle.Fill;
form.Controls.Add(sc);
Application.Run(form);
}

}

private static void AddPanels(SplitterPanel panel)
{
for (int i = 0; i < 5; i++)
{
Panel p = new Panel();
Button b = new Button();
b.Location = new System.Drawing.Point(10 * i, 10 * i);
b.Click += delegate
{
p.SendToBack();
};
b.Text = "Panel " + i.ToString();
p.Dock = DockStyle.Fill;
p.Controls.Add(b);
panel.Controls.Add(p);
}
}
}

Marc
Nov 20 '06 #7
Adil Akram wrote:
Marc,
I tried placing several panels in same project on another form and their
BringToFront/SendToBack working both at design time and runtime. I think the
SplitterContainer is the real culprit and prevents panels to work properly.

Have you any solution for the panels inside SplitterContainer to work or
I'll have to use Visible property.
I gather you are trying to have one or more panels inside a
SplitterContainer and then selectively show and hide them?

Rather than using panels, use UserControls. You can design them
separately and show them inside the panels of the SplitterContainer.

You can also do this using forms instead of UserControls.

Chris

Nov 20 '06 #8
Marc,
Thank you very much for your follow up. I again missed to mention that I'm
using a SplitterContainer inside another SplitterContainer, first one
(Parent) has vertical orientation and 2nd (Child) has horizontal orientation.
I just like to mention if it may help to find some clue.

But even with this addition to your code, its still working properly and its
annoying me so much that why it is not working for me not even at design
time. My project is currently not so big, it has a single form only and I
check it out and find nothing different I'm doing in it.

Here's your coding with addition of another child SplitterContainer and its
working.

using System;
using System.Windows.Forms;
using System.Drawing;
class Program
{
static void Main()
{
using (Form form = new Form())
using (SplitContainer sc = new SplitContainer())
{
SplitContainer scl = new SplitContainer();
scl.Orientation = Orientation.Horizontal;

scl.Panel1.BackColor = Color.Red;
scl.Panel2.BackColor = Color.Blue;
AddPanels(scl.Panel1);
AddPanels(scl.Panel2);
sc.Dock = DockStyle.Fill;
scl.Dock = DockStyle.Fill;
sc.Panel1.Controls.Add(scl);
form.Controls.Add(sc);
Application.Run(form);
}

}

private static void AddPanels(SplitterPanel panel)
{
for (int i = 0; i < 5; i++)
{
Panel p = new Panel();
Button b = new Button();
b.Location = new System.Drawing.Point(10 * i, 10 * i);
b.Click += delegate
{
p.SendToBack();
};
b.Text = "Panel " + i.ToString();
p.Dock = DockStyle.Fill;
p.Controls.Add(b);
panel.Controls.Add(p);
}
}
}
regards,
Adil

"Chris Dunaway" wrote:
Adil Akram wrote:
Marc,
I tried placing several panels in same project on another form and their
BringToFront/SendToBack working both at design time and runtime. I think the
SplitterContainer is the real culprit and prevents panels to work properly.

Have you any solution for the panels inside SplitterContainer to work or
I'll have to use Visible property.

I gather you are trying to have one or more panels inside a
SplitterContainer and then selectively show and hide them?

Rather than using panels, use UserControls. You can design them
separately and show them inside the panels of the SplitterContainer.

You can also do this using forms instead of UserControls.

Chris

Nov 21 '06 #9
Chris,
Thank you for your assistance and suggesting alternatives.

I have another alternate solution to use the Visible property of Panels to
show hide but it requires to do more management/coding to set visible false
for one and setting true for other.

I would just like to know that is there any known bug/design flaw in panels
ZOrder as in my case its not working not even at design time or is there
something I'm doing wrong?

regards,
Adil


"Chris Dunaway" wrote:
Adil Akram wrote:
Marc,
I tried placing several panels in same project on another form and their
BringToFront/SendToBack working both at design time and runtime. I think the
SplitterContainer is the real culprit and prevents panels to work properly.

Have you any solution for the panels inside SplitterContainer to work or
I'll have to use Visible property.

I gather you are trying to have one or more panels inside a
SplitterContainer and then selectively show and hide them?

Rather than using panels, use UserControls. You can design them
separately and show them inside the panels of the SplitterContainer.

You can also do this using forms instead of UserControls.

Chris

Nov 21 '06 #10
Marc,
Thanks for staying to resolve the problem. I indentified the problem,
actually I while dropping panels on form I dropped one on top of other that
causes one to be child of other that is why its not coming front of its
parent.
regards,
Adil

"Marc Gravell" wrote:
Still works fine for me... Have you any code that demonstrates this?

using System;
using System.Windows.Forms;
using System.Drawing;
class Program
{
static void Main()
{
using (Form form = new Form())
using (SplitContainer sc = new SplitContainer())
{
sc.Panel1.BackColor = Color.Red;
sc.Panel2.BackColor = Color.Blue;
AddPanels(sc.Panel1);
AddPanels(sc.Panel2);
sc.Dock = DockStyle.Fill;
form.Controls.Add(sc);
Application.Run(form);
}

}

private static void AddPanels(SplitterPanel panel)
{
for (int i = 0; i < 5; i++)
{
Panel p = new Panel();
Button b = new Button();
b.Location = new System.Drawing.Point(10 * i, 10 * i);
b.Click += delegate
{
p.SendToBack();
};
b.Text = "Panel " + i.ToString();
p.Dock = DockStyle.Fill;
p.Controls.Add(b);
panel.Controls.Add(p);
}
}
}

Marc
Nov 21 '06 #11
Glad you resolved it.

As a future guide, if you see this again have a look at the document outline
([Ctrl]+[Alt]+T) - makes it easy to see what nests where.

Marc
Nov 21 '06 #12
Marc,
Thanks its very helpful to view controls outline.

regards,
Adil

"Marc Gravell" wrote:
Glad you resolved it.

As a future guide, if you see this again have a look at the document outline
([Ctrl]+[Alt]+T) - makes it easy to see what nests where.

Marc
Nov 21 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Yang Li Ke | last post by:
Hi guys, let's say I want to load a window behind the main window. how do i do it? because right now everytime i do it the main window gets behind and the new window get the focus. Thank you.
2
by: rawCoder | last post by:
Hi I am having this InvalidOperationException with message Cannot call Invoke or InvokeAsync on a control until the window handle has been created This is raised when i try to invoke a method...
1
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
37
by: Geoff Jones | last post by:
Hi Suppose I have two forms: Form1 and Form2. I create and show an instance of Form2 in the code of Form1 e.g. Dim myForm2 = New Form2 myForm2.Show() How do I tell myForm2 that Form1 is...
9
by: Quina | last post by:
Hi. Is there someone that can tell me how can I have multiple screens on the the same form, displaying only on at the time? Thank you all for any replys. Joćo Carias
0
by: Larry Charlton | last post by:
Is there a way to make a Panel (or other control that can contain child controls) so that it will size correctly at design time (based on CSS)? Panel seems to be doing something weird at design...
4
by: Mikus Sleiners | last post by:
I can't seem to add new controls to form that is inherited from another form. I have BaseForm wich have table layout on it 2 panelsm and some buttons. Now i create InheritedForm : BaseForm and...
4
by: iKiLL | last post by:
Hi All I am Developing in C# with VS2005. I am Developing a Windows Mobile Forms Application with the CF2 My problem is that when the Input panel is displayed my screen does not
2
by: Jonathan Boivin | last post by:
Hi people, Let me introduce to how I get this error. I have a form which load all my bills representation depending upon filters which each bill is a usercontrol of my own having some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.