Malo bolje organiziraj kod.
U fajl Form1.cs upisi
Code:
namespace FormMDIRoditelj_namespace
{
using System;
using System.Windows.Forms;
/// <summary>
/// Summary description for Form1.
/// </summary>
public class FormMDIRoditelj : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public FormMDIRoditelj()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// FormMDIRoditelj
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(402, 292);
this.IsMdiContainer = true;
this.Name = "FormMDIRoditelj";
this.Text = "Form1 - MDI roditelj";
}
#endregion
}
}
U fajl Form2.cs upisi
Code:
namespace FormMDIDijete_namespace
{
using System;
using System.Windows.Forms;
using FormMDIRoditelj_namespace;
/// <summary>
/// Summary description for Form2.
/// </summary>
public class FormMDIDijete : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public FormMDIDijete()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
FormMDIRoditelj roditelj = new FormMDIRoditelj();
this.MdiParent = roditelj;
roditelj.Show();
this.Show();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// FormMDIDijete
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(282, 107);
this.Name = "FormMDIDijete";
this.Text = "Form2 - MDI dijete";
}
#endregion
}
}
U fajl Form3.cs upisi
Code:
namespace FormLogin_namespace
{
using System;
using System.Windows.Forms;
/// <summary>
/// Summary description for Form3.
/// </summary>
public class FormLogin : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnLogin;
public System.Windows.Forms.TextBox txtUsername;
public System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button btnCancel;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public FormLogin()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnLogin = new System.Windows.Forms.Button();
this.txtUsername = new System.Windows.Forms.TextBox();
this.txtPassword = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.btnCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnLogin
//
this.btnLogin.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnLogin.Location = new System.Drawing.Point(10, 60);
this.btnLogin.Name = "btnLogin";
this.btnLogin.Size = new System.Drawing.Size(85, 30);
this.btnLogin.TabIndex = 0;
this.btnLogin.Text = "Login";
//
// txtUsername
//
this.txtUsername.Location = new System.Drawing.Point(75, 10);
this.txtUsername.Name = "txtUsername";
this.txtUsername.Size = new System.Drawing.Size(115, 20);
this.txtUsername.TabIndex = 2;
this.txtUsername.Text = "";
//
// txtPassword
//
this.txtPassword.Location = new System.Drawing.Point(75, 35);
this.txtPassword.Name = "txtPassword";
this.txtPassword.PasswordChar = '*';
this.txtPassword.Size = new System.Drawing.Size(115, 20);
this.txtPassword.TabIndex = 3;
this.txtPassword.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(10, 10);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(60, 20);
this.label1.TabIndex = 4;
this.label1.Text = "Username";
//
// label2
//
this.label2.Location = new System.Drawing.Point(10, 35);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(60, 20);
this.label2.TabIndex = 5;
this.label2.Text = "Password";
//
// btnCancel
//
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(105, 60);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(85, 30);
this.btnCancel.TabIndex = 6;
this.btnCancel.Text = "Cancel";
//
// FormLogin
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(197, 97);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnCancel,
this.label2,
this.label1,
this.txtPassword,
this.txtUsername,
this.btnLogin});
this.Name = "FormLogin";
this.Text = "Form3";
this.ResumeLayout(false);
}
#endregion
}
}
U fajl Test.cs upisi
Code:
namespace Test_namespace
{
using System;
using System.Windows.Forms;
using FormMDIRoditelj_namespace;
using FormMDIDijete_namespace;
using FormLogin_namespace;
/// <summary>
/// Summary description for Test.
/// </summary>
public class Test
{
public static void Main()
{
FormLogin login = new FormLogin();
if (login.ShowDialog() == DialogResult.OK)
{
if (login.txtUsername.Text == "korisnik" &&
login.txtPassword.Text == "lozinka")
{
login.Close();
Application.Run(new FormMDIDijete());
}
else
{
login.Close();
MessageBox.Show("Not valid: username/password!", "ERROR!");
MessageBox.Show("Hvala na koristenju programa.", "");
}
}
else
{
MessageBox.Show("Hvala na koristenju programa.", "");
}
}
}
}
U VS.NET idi u Property Pages i u polje "Startup object" upisi "Test_namespace.Test".
Kompajlaj program i vidi!