窗口窗体,面板,无法在运行时/设计时设置ZOrder [英] Window Form, Panel, can't set ZOrder at run time/design time

查看:97
本文介绍了窗口窗体,面板,无法在运行时/设计时设置ZOrder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VS 2005,.net 2.0用于桌面应用程序(Window Form应用程序)。


我不能在设计时设置Panel控件的ZOrder通过工具栏/菜单

命令带到前面/发送到后面也不是在运行时通过调用

BringToFront面板方法。并且Panel控件不支持SetTopLevel

方法等。我尝试了这个,而Dock = Fill和Dock = None但它没有工作在

all。


请告诉我如何在运行时特别更改Panel的ZOrder,我有

来在不同的时间显示不同的面板。有没有办法做到这一点或者我/ b $ b必须将他们的Visible设置为true / false来实现这一点。

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.

推荐答案

似乎对我来说工作正常(下图)......你在做什么不同?

但是 - 改变可见度是一种选择,它听起来像你

正在做的非常类似于TabPage实现...


使用System;

使用System.Windows.Forms;

class Program

{

static void Main()

{

using(Form form = new Form) ()){

for(int i = 0; i< 5; i ++){

Panel p = new Panel();

按钮b =新按钮();

b.Click + = delegate {

p.SendToBack();

};

b.Text =" Panel" + i.ToString();

p.Dock = DockStyle.Fill;

p.Controls.Add(b);

表格。 Controls.Add(p);

}

Application.Run(表格);

}


}

}
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);
}

}
}


Marc,

我唯一不同的是你在创造它在运行时我在设计时在表单中添加了

,并且在.net中没有任何不同,因为

设计器还添加了相同的实例化代码。所以,唯一的区别是

您的控件创建代码在Main()方法中,我的是在Form'的
构造函数中。


我再次检查它,它仍然不能在设计时工作,也不在运行

时间,即使我在运行时检查了面板的SendToBack方法,但它不是

工作。我可以用Visible做到这一点,但我有4-5个面板上下,我需要看到所有面板的可见性。


你执行了吗?您在.net 2.0中的代码?


问候,

Adil


" Marc Gravell"写道:
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:

似乎对我来说工作正常(下图)...你在做什么不同?

但是 - 改变可见度是一个选项,它听起来像你b $ b正在做的非常类似于TabPage实现...


使用系统;

使用System.Windows.Forms;

class Program

{

static void Main()

{

使用(Form form = new Form()){

for(int i = 0; i< 5; i ++){

面板p =新面板();

按钮b =新按钮();

b.Click + = delegate {

p .SendToBack();

};

b.Text =" Panel" + i.ToString();

p.Dock = DockStyle.Fill;

p.Controls.Add(b);

表格。 Controls.Add(p);

}

Application.Run(表格);

}


}

}
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);
}

}
}


Marc,

我正在做的另一件事,我忘了告诉你是我把我的面板

控件放在SplitContainer控件的面板中。


问候,

Adil


" Marc Gravell"写道:
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:

似乎对我来说工作正常(下图)...你在做什么不同?

但是 - 改变可见度是一个选项,它听起来像你b $ b正在做的非常类似于TabPage实现...


使用系统;

使用System.Windows.Forms;

class Program

{

static void Main()

{

使用(Form form = new Form()){

for(int i = 0; i< 5; i ++){

面板p =新面板();

按钮b =新按钮();

b.Click + = delegate {

p .SendToBack();

};

b.Text =" Panel" + i.ToString();

p.Dock = DockStyle.Fill;

p.Controls.Add(b);

表格。 Controls.Add(p);

}

Application.Run(表格);

}


}

}
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);
}

}
}


这篇关于窗口窗体,面板,无法在运行时/设计时设置ZOrder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆