Whenever we create a windows application and if we are using
MDP parent form in that case the process for opening form in MDI window is
different as we open form in not in MDI parent.
In my previous article I have shown you how you can How
to Open Command Prompt Using C#.net,
for displaying the error message I have writer this article How
to show Error & Warning Message Box in .NET | C# MessageBox.Show Examples, Some of my listbox related article are as
follows Remove
Selected Item From Listbox C#.Net and VB.net, How
to add/move multiselected items from one listbox to another listbox in C#.Net
and VB.Net | C# multiple selection listbox move Using C#.Net, Transfer
Listbox Items to Another Listbox Using C#.Net and VB.Net | How to Move List Box
Items to another List Box in C#.
Now for this article first we will create a new windows
application and add two forms form1 and form2. Now take form1 and got to
property window to make the for MDI window form. How to make a form
MDI Form in
window application C#.Net.
Here is the code for this article
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ProjectDemo_Windows
{
public partial class Form2 : Form
{
public
Form2()
{
InitializeComponent();
}
private
void openForm2ToolStripMenuItem_Click(object sender, EventArgs
e)
{
if
(CheckMdiClientDuplicatesForm("ProjectDemo-Windows.Form2")
== true)
{
Form1
objform1 = new Form1();
objform1.MdiParent = this;
objform1.Show();
}
}
public
bool CheckMdiClientDuplicatesForm(string windowsFormName)
{
if
(ActiveMdiChild != null)
{
if
(ActiveMdiChild.Name != windowsFormName.Split('.')[1].ToString())
{
ActiveMdiChild.Close();
}
}
Form[]
mdichld = this.MdiChildren;
if
(this.MdiChildren.Length == 0)
{
return
true;
}
foreach
(Form selfm in
mdichld)
{
string
str = selfm.Name;
str =
str.IndexOf(windowsFormName).ToString();
if
(str != "-1")
{
return
true;
}
}
return
false;
}
}
}
|
Now run the application
DOWNLOAD
0 comments:
Please let me know your view