如何突出显示由form_1创建的form_2 [英] How to highlight the form_2 which is created by form_1
问题描述
改进的问题
回答2:谢谢,但我不能只显示它.
回答1:
(1)如果我不添加"this.Controls.Add(form_2)
"行,则form_2
将显示在form_1
后面.因此,我将这行添加到form_1
的行下方的form_1
中,以便form_2
可以显示在form_1
客户区中.
另外,我必须在"this.Controls.add(form_2)
"之前添加"form_2.toplevel=false
",否则它将显示"无法将顶级控件(form_2)添加到控件(this)"的消息,并且则无法在高级版本中运行.
(2)加亮表示让form_2
中的顶部栏具有加亮的蓝色.因为即使单击form_2
或在form_1
中添加以下任何一行,也只能看到form_2
中顶部栏的灰色蓝色:
Improved question
To Answer 2 : Thanks, but I am not to show it only.
To Answer 1 :
(1) If I don''t add the line of "this.Controls.Add(form_2)
", the form_2
will be shown behind the form_1
. So, I add this line in form_1
just below the line of "initialcomponet()
", so that the form_2
can be shown in the form_1
client area.
Plus, I have to add "form_2.toplevel=false
" before "this.Controls.add(form_2)
", or, it will show message of "can not add top level control(form_2) to control(this)", and then it can not run in advanced.
(2) The highlight means to let top bar in form_2
has highlight blue color. Since I can only see gray blue color of top bar in form_2
even I click the form_2
, or add any line of following in form_1
:
form_2.Show();
form_2.Activate();
form_2.Enabled = true;
form_2.BringToFront();
form_2.Focus();
第一个问题
我有一个名为form_1
的窗体的winform应用程序,我在form_1
中编写代码来创建form_2
,我想用突出显示颜色激活form_2
,但是失败.代码如下:
1.我创建form_2
并将其包含在form_1 (this)
中
First question
I have a winform application with a form named form_1
, I write code in form_1
to create form_2
, and I would like to activate the form_2
with highlight color, however, it fails. The code is below :
1. I create form_2
and let it be included in form_1 (this)
Form_help form_2 = new Form_help();
form_2.TopLevel = false;
this.Controls.Add(form_2);
2.我尝试用以下几行激活form_2
以突出显示它,但是所有操作都没有突出显示它.
2. I try to activate form_2
to highlight it with the following lines, but all fails to highlight it.
form_2.Show();
form_2.Activate();
form_2.Enabled = true;
form_2.BringToFront();
form_2.Focus();
问题是如何突出显示form_2
?由于我将在form_1
中放置多个表单,并且当单击任何表单时,单击的表单将突出显示.
我也尝试使用form_1.activecontrol(form_2)
方法,但仍然失败.
The question is how can I highlight the form_2
? Since I would place multiple forms in form_1
, and when click any of the forms, the clicked form will be highlight.
I also try the way of form_1.activecontrol(form_2)
method, but it still fails.
推荐答案
您是否要使表格1包含多个表格?如果是这样,请尝试使用mdi父容器. <-推荐使用以下解决方案.
否则,您可以使用P/Invoke:
http://www.pinvoke.net/default.aspx/user32.setforegroundwindow
它将任何窗口设置为前景窗口,或者至少尝试使用它,只需使用this.Handle
即可获取表单的句柄.
Are you trying to make form 1 contain multiple forms? If so, try using a mdi Parent Container instead. <-- Recommended over solution below.
Otherwise you can use P/Invoke:
http://www.pinvoke.net/default.aspx/user32.setforegroundwindow
It''ll set any window to the foreground window or atleast try to, just usethis.Handle
to get the form''s handle.
Form_help f = new Form_help();
f.ShowInTaskbar=false;
f.backcolor=color.red;
f.windowstate=formwindowstate.maximized;
f.show();
表单不是控件,您不将其添加到控件集合中.
突出显示是什么意思?
A form is not a control, you don''t add it to the controls collection.
What do you mean by highlight ?
这篇关于如何突出显示由form_1创建的form_2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!