picturebox问题 我想在MDI父窗体中添加一个图片,就是如果没有子窗体打开就显示这张图片,如果打开了子窗体就显示子窗体,但现在打开了子窗体之后图片还是会显示,怎么才能把图片放在子窗体的下面? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个我做过,但忘了,好像不是一张图片的问题。 /// <summary> /// 添加一个窗体 /// </summary> /// <param name="x"></param> public void AddForms(XtraForm x) { if (x == null) { x = new XtraForm(); } this.pictureEdit1.Visible = false; x.MdiParent = this; x.Show(); } /// <summary> /// 关于在什么时候显示背景图片 /// </summary> private void showBackImage() { if (this.MdiChildren.Length == 0) { this.pictureEdit1.Visible = true; return; } foreach (XtraForm xf in this.MdiChildren) { if (xf.Visible) { return; } } this.pictureEdit1.Visible = true; }呃找到了,以前做的一个项目,用的控件是DEV。不过这个跟标准控件的语法差别不大,应该能看懂吧。 this.pictureEdit1.Visible 为主窗体的填充图。 试试下面的代码,来自http://bingning.net/free/source/form/mdibackgroundimage.html//在背景中显示图片 Bitmap back = new Bitmap("back.bmp"); //MDI父窗体的Load Event Handle private void ParentForm_Load(object sender, System.EventArgs e) { this.IsMdiContainer = true; //取得MdiClient System.Windows.Forms.MdiClient mc = GetMdiClient(this); //增加MdiClient的Paint和Resize Event Handle mc.Paint += new PaintEventHandler(MdiClient_Paint); mc.Resize += new EventHandler(MdiClient_Resize); } private void MdiClient_Paint(object sender, PaintEventArgs e) { System.Windows.Forms.MdiClient mc = (System.Windows.Forms.MdiClient) sender; //将图片按照符合Client领域大小的形式显示 e.Graphics.DrawImage(back, mc.ClientRectangle); } private void MdiClient_Resize(object sender, EventArgs e) { System.Windows.Forms.MdiClient mc = (System.Windows.Forms.MdiClient) sender; //调用Paint事件 mc.Invalidate(); } /// <summary> /// 查找窗体的MdiClient控件并返回 /// </summary> /// <param name="f">查找MdiClient控件的窗体</param> /// <returns>查询到的 MdiClient控件</returns> public static System.Windows.Forms.MdiClient GetMdiClient(System.Windows.Forms.Form f) { foreach (System.Windows.Forms.Control c in f.Controls) if (c is System.Windows.Forms.MdiClient) return (System.Windows.Forms.MdiClient) c; return null; } 好像winform中MDI父窗体中的控件一定会在自窗体之前,无论你怎么把自窗体制顶(我之前也遇到过),我的解决方法就是背景如果要切换,只能切换父窗体中的背景了,根据条件切换,以上是我的个人理解,如果有其他的方法一起学习~ 或者,还有一种方法就是用一个MDI子窗体用你的pictureBox填充,然后一直显示这个子窗体,作为背景一样,其他的窗体都在这个窗体的上边,不过这样的不好的地方是你要去掉这个窗体的最大最小化等按钮和边框,并且要设置大小,否则其他的mdi子窗体在最大最小切换的时候也会影响这个背景。等待更好的解决方法。 关键是什么时候调用showBackImage呢? 主要逻辑是看看还有没有子窗体存在,如果没有就SHOW。因为用了DEV的特殊控件,子窗体是会完全挡住主窗体的MDI窗口的。 C# GDI+绘制文字换行问题 这个问题网上还真没有。。。大家来帮帮忙! 无奈了,全过程 在c#里,如何锁定数据库里的一张表或整个库? datagridview 只显示时间 这个验证码如何识别? 如果一个查询数据的参数有两个以上相同的之值,如何解决! ◥◣㊣◢◤ 小弟由VB转C#希望各位大家多多指教! ◥◣㊣◢◤ For 循环 添加 线程 请问如何在程序中通过progid调用COM组件? 这最后一截代码干什么用的? Lucene搜索
/// 添加一个窗体
/// </summary>
/// <param name="x"></param>
public void AddForms(XtraForm x)
{
if (x == null)
{
x = new XtraForm();
}
this.pictureEdit1.Visible = false;
x.MdiParent = this;
x.Show();
} /// <summary>
/// 关于在什么时候显示背景图片
/// </summary>
private void showBackImage()
{
if (this.MdiChildren.Length == 0)
{
this.pictureEdit1.Visible = true;
return;
} foreach (XtraForm xf in this.MdiChildren)
{
if (xf.Visible)
{
return;
}
}
this.pictureEdit1.Visible = true;
}
呃找到了,以前做的一个项目,用的控件是DEV。不过这个跟标准控件的语法差别不大,应该能看懂吧。
Bitmap back = new Bitmap("back.bmp"); //MDI父窗体的Load Event Handle
private void ParentForm_Load(object sender, System.EventArgs e)
{
this.IsMdiContainer = true;
//取得MdiClient
System.Windows.Forms.MdiClient mc = GetMdiClient(this);
//增加MdiClient的Paint和Resize Event Handle
mc.Paint += new PaintEventHandler(MdiClient_Paint);
mc.Resize += new EventHandler(MdiClient_Resize);
} private void MdiClient_Paint(object sender, PaintEventArgs e)
{
System.Windows.Forms.MdiClient mc =
(System.Windows.Forms.MdiClient) sender;
//将图片按照符合Client领域大小的形式显示
e.Graphics.DrawImage(back, mc.ClientRectangle);
}
private void MdiClient_Resize(object sender, EventArgs e)
{
System.Windows.Forms.MdiClient mc =
(System.Windows.Forms.MdiClient) sender;
//调用Paint事件
mc.Invalidate();
} /// <summary>
/// 查找窗体的MdiClient控件并返回
/// </summary>
/// <param name="f">查找MdiClient控件的窗体</param>
/// <returns>查询到的 MdiClient控件</returns>
public static System.Windows.Forms.MdiClient
GetMdiClient(System.Windows.Forms.Form f)
{
foreach (System.Windows.Forms.Control c in f.Controls)
if (c is System.Windows.Forms.MdiClient)
return (System.Windows.Forms.MdiClient) c;
return null;
}
等待更好的解决方法。
关键是什么时候调用showBackImage呢?