如何设MDI子窗体在父窗体的pictureBox之上 MDI父窗体中有一个pictureBox做背景用的(窗体的背景不支持拉伸,只好这样做了)但这样的话,这个pictureBox总在子窗体之上,把子窗体给挡住了,显示不出 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void mnuUpload_Click(object sender, System.EventArgs e) { if(UploadOpen == false) { //在生成子窗体时隐藏PictureBox //需要时在显示 //只有这个方法了 myPictureBox.Visible = false; Upload child = new Upload(); child.MdiParent = this; child.Show(); UploadOpen = true; } else { for(int i= 0;i<MdiChildren.Length;i++) { if(MdiChildren[i].Name == "Upload") { MdiChildren[i].BringToFront(); } } } }这里有用采用MDI多文档窗口 的程序(含源代码) 你可参考一下http://support.apress.com/books.asp?bID=186100754x&s=0&Go=Select+Book 用此PICTUREBOX代替父窗体的背景 按你的想法与做法,可能性不大。我们换一种方式:加一个子窗口,并设置该子窗口为最底层,在该子窗口上加一个可拉伸的图片框。当该子窗口被激活,就把它设置为最底层。并且,不允许用户关闭它,就可以了。具体方法:加载一个子窗口(form1),并重写该子窗口的OnActivated事件:protected override void OnActivated(EventArgs e){SendToBack();}===================在该子窗口上加上你要的PictureBox在主窗口中加载一个空窗口:Form mdichile = null;写主窗口的MdiChildActiveate事件:private void MainForm_MdiChildActivate(object sender, System.EventArgs e){Form form = this.ActiveMdiChild;if(form != null){if(form is form1){if(mdichile != null){mdichile.Activate();}}else{mdichile = form;}}else{form1.Activate();}}==================这就可以了。:-) 源代码Form1(主窗口):using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace Demo{ /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.MenuItem menuItem2; private Form form = null; private Form3 form3 = new Form3(); public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.menuItem2 = new System.Windows.Forms.MenuItem(); // // mainMenu1 // this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1}); // // menuItem1 // this.menuItem1.Index = 0; this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem2}); this.menuItem1.Text = "123"; // // menuItem2 // this.menuItem2.Index = 0; this.menuItem2.Text = "123"; this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(508, 302); this.IsMdiContainer = true; this.Menu = this.mainMenu1; this.Name = "Form1"; this.Text = "Form1"; this.MdiChildActivate += new System.EventHandler(this.Form1_MdiChildActivate); this.Load += new System.EventHandler(this.Form1_Load); } #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void menuItem2_Click(object sender, System.EventArgs e) { Form2 form = new Form2(); form.MdiParent = this; form.Show(); } private void Form1_MdiChildActivate(object sender, System.EventArgs e) { Form theform = this.ActiveMdiChild; if(theform != null) { if(theform is Form3) { if(form != null) { this.form.Activate(); } } else { form = theform; } } else { form3.Activate(); } } private void Form1_Load(object sender, System.EventArgs e) { form3.MdiParent = this; form3.Show(); } }} Form2:using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;namespace Demo{ /// <summary> /// Form2 的摘要说明。 /// </summary> public class Form2 : System.Windows.Forms.Form { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public Form2() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.Size = new System.Drawing.Size(300,300); this.Text = "Form2"; } #endregion }} Form3(底层窗口):using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;namespace Demo{ /// <summary> /// Form3 的摘要说明。 /// </summary> public class Form3 : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public Form3() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(12, 32); this.button1.Name = "button1"; this.button1.TabIndex = 1; this.button1.Text = "button1"; this.button1.Click += new System.EventHandler(this.button1_Click); // // button2 // this.button2.Location = new System.Drawing.Point(16, 72); this.button2.Name = "button2"; this.button2.TabIndex = 2; this.button2.Text = "button2"; this.button2.Click += new System.EventHandler(this.button2_Click); // // Form3 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.Name = "Form3"; this.Text = "Form3"; this.ResumeLayout(false); } #endregion protected override void OnActivated(EventArgs e) { SendToBack(); } private void button1_Click(object sender, System.EventArgs e) { MessageBox.Show("OKOK"); } private void button2_Click(object sender, System.EventArgs e) { MessageBox.Show("KOKO"); } }} 导出Excel C# WINFORM 问题 求一段 如何移动菜单栏的代码? 电子邮件的特殊字符? 保存提示框怎么弄哦? vivienne请进,解决问题 请教字符串分割问题 C# 使用com的OfficeViewer OCX组件时 提示没有注册类 BeginReceiveFrom问题,紧急求助,在线等,100分重谢。 在C#中怎樣取當前時間月的第幾周,並返回在Dropdownlist下拉框中 简单问题????急,在线等。详细见里面代码。 如何在ASP中使用C#编写的DLL组件?
{
if(UploadOpen == false)
{
//在生成子窗体时隐藏PictureBox
//需要时在显示
//只有这个方法了
myPictureBox.Visible = false; Upload child = new Upload();
child.MdiParent = this;
child.Show();
UploadOpen = true;
}
else
{
for(int i= 0;i<MdiChildren.Length;i++)
{
if(MdiChildren[i].Name == "Upload")
{
MdiChildren[i].BringToFront();
}
}
}
}
这里有用采用MDI多文档窗口 的程序(含源代码) 你可参考一下
http://support.apress.com/books.asp?bID=186100754x&s=0&Go=Select+Book
具体方法:
加载一个子窗口(form1),并重写该子窗口的OnActivated事件:
protected override void OnActivated(EventArgs e)
{
SendToBack();
}
===================
在该子窗口上加上你要的PictureBox
在主窗口中加载一个空窗口:Form mdichile = null;
写主窗口的MdiChildActiveate事件:
private void MainForm_MdiChildActivate(object sender, System.EventArgs e)
{
Form form = this.ActiveMdiChild;
if(form != null)
{
if(form is form1)
{
if(mdichile != null)
{
mdichile.Activate();
}
}
else
{
mdichile = form;
}
}
else
{
form1.Activate();
}
}
==================
这就可以了。:-)
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace Demo
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private Form form = null;
private Form3 form3 = new Form3(); public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2});
this.menuItem1.Text = "123";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "123";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(508, 302);
this.IsMdiContainer = true;
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Form1";
this.MdiChildActivate += new System.EventHandler(this.Form1_MdiChildActivate);
this.Load += new System.EventHandler(this.Form1_Load); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void menuItem2_Click(object sender, System.EventArgs e)
{
Form2 form = new Form2();
form.MdiParent = this;
form.Show();
} private void Form1_MdiChildActivate(object sender, System.EventArgs e)
{
Form theform = this.ActiveMdiChild;
if(theform != null)
{
if(theform is Form3)
{
if(form != null)
{
this.form.Activate();
}
}
else
{
form = theform;
}
}
else
{
form3.Activate();
}
} private void Form1_Load(object sender, System.EventArgs e)
{
form3.MdiParent = this;
form3.Show();
}
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;namespace Demo
{
/// <summary>
/// Form2 的摘要说明。
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form2()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form2";
}
#endregion
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;namespace Demo
{
/// <summary>
/// Form3 的摘要说明。
/// </summary>
public class Form3 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form3()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(12, 32);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(16, 72);
this.button2.Name = "button2";
this.button2.TabIndex = 2;
this.button2.Text = "button2";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form3
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "Form3";
this.Text = "Form3";
this.ResumeLayout(false); }
#endregion
protected override void OnActivated(EventArgs e)
{
SendToBack();
} private void button1_Click(object sender, System.EventArgs e)
{
MessageBox.Show("OKOK");
} private void button2_Click(object sender, System.EventArgs e)
{
MessageBox.Show("KOKO");
}
}
}