我建立了一個主表單,主表單上面設定了各個功能模塊,每個功能模塊是一個子表單。子表單Form A 中通過new form顯示了一個子表單B, 我最小化Form B,Form A和主表單跟著全部最小化了,很苦惱這件事,請問各位大牛有什么方法,讓Form B最小化的時候只是最小化自己,最小化到任務欄之后點擊又能還原,求大神們支招啊,謝謝大家
uj5u.com熱心網友回復:
我用本地VS2015沒有LZ說的這個問題,這是我本地的代碼
//Form1.cs:
private void Form1_Load(object sender, EventArgs e)
{
FormA fa = new FormA();
fa.MdiParent = this;
fa.Show();
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(554, 351);
this.IsMdiContainer = true;
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
//FormA.cs:
private void button1_Click(object sender, EventArgs e)
{
FormB fb = new FormB();
fb.MdiParent = MdiParent;
fb.Show();
}
uj5u.com熱心網友回復:
補充說明一下,第二個方法是系統自動生成的,我只是把主表單的IsMdiContainer屬性設為trueuj5u.com熱心網友回復:
二樓你的方式是 多檔案表單吧uj5u.com熱心網友回復:
你的代碼寫的有問題,子表單默認只會隨主表單關閉而關閉,不會出現你說的同時最小化的情況uj5u.com熱心網友回復:
謝謝您啦,是我自己程式出錯啦,能否再請教您個問題,您了解多重背包問題嗎,我有N個物品,每個物品的重量和價值都是1,每個物品的最大可取數量是一個陣列A[N],每種物品可以不取, 我想輸出所有可行方案(包括每個物品取了多少),期待您的回復,感謝感謝,分全給您,我會再追加
uj5u.com熱心網友回復:
按理說不會,是不是你用 formB.Show(this) 了,去掉 thisuj5u.com熱心網友回復:
//采用多執行緒可以解決你的問題,因我也碰到你的同樣的問題,開發中應客戶之要求,以此共勉吧!using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace FormA
{
public partial class FormA : Form
{
public FormA()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Thread thread = new Thread(threadPro);
thread.Start();
}
private void threadPro()
{
MethodInvoker methodInvoker = new MethodInvoker(ShowFormB);
BeginInvoke(methodInvoker);
}
private void ShowFormB()
{
FormB frmB = new FormB();
frmB.Show();
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/146908.html
標籤:C#
