Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

C# i forme

[es] :: .NET :: .NET Desktop razvoj :: C# i forme

[ Pregleda: 3434 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

gilespy

Član broj: 39868
Poruke: 232
*.vdial.verat.net.



+1 Profil

icon C# i forme07.01.2005. u 14:51 - pre 234 meseci
Imam kreirane dve forme od kojih je jedna MDI Conteiner.

Dodao sam trecu formu na osnovu koje treba da se pokrenu prve dve, tj. prvo

hocu da se pokrene treca forma, a onda u zavisnosti od rezultata da se

pokrenu ili ne prve dve.


Problem je sto ne znam kako da namestim da se treca forma pokrece prva.

Treca forma ne treba biti u okviru MDI kontejnera vec predstavlja dijalog

koji, ako se odgovori potvrdno, prikazuje druge forme.


Hvala

Igor!!!
 
Odgovor na temu

NeznamTkoSam

Član broj: 39660
Poruke: 279
*.cmu.carnet.hr.



Profil

icon Re: C# i forme07.01.2005. u 21:32 - pre 234 meseci
Code:

public static void Main()
{
    //...
    PrvaForma forma1 = new PrvaForma();
    DrugaForma forma2 = new DrugaForma();
    TrecaForma forma3 = new TrecaForma();
    PrvaForma.Hide();
    DrugaForma.Hide();
    //...
    if (TrecaForma.ShowDialog() == DialogResult.OK)
    {
        PrvaForma.Show();
        DrugaForma.Show();
    }
    while (true)
        Application.DoEvents();
}
 
Odgovor na temu

gilespy

Član broj: 39868
Poruke: 232
*.vdial.verat.net.



+1 Profil

icon Re: C# i forme08.01.2005. u 20:10 - pre 234 meseci
To mi je trebalo vec dva dana. Hvala!

Sad me jos samo zanima kako da namestim da se treca forma ugais, nakon sto

se uslovi ispune i pozovu se prva i druga?


Pokusavao sam sa this.Close(); ali ocigledno to stavljam na pogresno

mesto, jer mi onda gasi sve.



Hvala

Igor!!!
 
Odgovor na temu

NeznamTkoSam

Član broj: 39660
Poruke: 279
*.cmu.carnet.hr.



Profil

icon Re: C# i forme08.01.2005. u 21:35 - pre 234 meseci
Code:

using System;
using System.Windows.Forms;

public class Form1 : Form
{
    public Form1()
    {
        this.Text = "Forma 1 - MDI kontejner";
    }
}

public class Form2 : Form
{
    public Form2()
    {
        this.Text = "Forma 2 - MDI child";
    }
}

public class Form3 : Form
{
    public string Pokrenuti = "?";
    public Form3()
    {
        this.Text = "Forma 3 - dijalog";
        this.Show();
        if (MessageBox.Show("Pokrenuti ostale dvije forme?",
            "Ovo je MessageBox",
            MessageBoxButtons.YesNo) == DialogResult.Yes)
            this.Pokrenuti = "Da";
        else
            this.Pokrenuti = "Ne";
    }
}

public class Test
{
    [STAThread]
    static void Main() 
    {
        Form3 forma3 = new Form3();
        while (forma3.Pokrenuti == "?")
            Application.DoEvents();
        if (forma3.Pokrenuti == "Da")
        {
            forma3.Close();
            Form1 forma1 = new Form1();
            Form2 forma2 = new Form2();
            forma1.IsMdiContainer = true;
            forma2.MdiParent = forma1;
            forma1.Show();
            forma2.Show();
            Application.Run(forma1);
        }
        else
        {
            forma3.Dispose();
        }
    }
}
 
Odgovor na temu

gilespy

Član broj: 39868
Poruke: 232
*.verat.net.



+1 Profil

icon Re: C# i forme08.01.2005. u 22:27 - pre 234 meseci
OK, to tvoje radi u cistoj situaciji, ali...


Pogledaj kod koji radi ono sto sam pricao i vidi, molim te, kako da se

modifikuje (sto jednostavnije) kako bi se zatvorila forma 1, koja

predstavlja logon screen.


Pozdrav

Igor!!!


P.S. Nista od koda nisam izostavio.


Code:
using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;


namespace WindowsApplication1

{

/// <summary>

/// Summary description for Form3.

/// </summary>

public class Form1 : System.Windows.Forms.Form

{

private System.Windows.Forms.TextBox textUser;

private System.Windows.Forms.TextBox textPass;

private System.Windows.Forms.Label label1;

private System.Windows.Forms.Label label2;

private System.Windows.Forms.Button btnOK;

private System.Windows.Forms.Button btnCancel;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;


public Form1()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();


this.btnOK.Enabled = false;

this.textUser.Tag = false;

this.textPass.Tag = false;


this.textUser.Validating += new

System.ComponentModel.CancelEventHandler(this.txtBoxUser_Validating);

this.textPass.Validating += new

System.ComponentModel.CancelEventHandler(this.txtBoxPass_Validating);

this.textUser.TextChanged += new System.EventHandler

(this.txtBoxUser_TextChanged);

this.textPass.TextChanged += new System.EventHandler

(this.txtBoxPass_TextChanged);



//

// 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()

{

System.Resources.ResourceManager resources = new

System.Resources.ResourceManager(typeof(Form1));

this.textUser = new System.Windows.Forms.TextBox();

this.textPass = new System.Windows.Forms.TextBox();

this.label1 = new System.Windows.Forms.Label();

this.label2 = new System.Windows.Forms.Label();

this.btnOK = new System.Windows.Forms.Button();

this.btnCancel = new System.Windows.Forms.Button();

this.SuspendLayout();

//

// textUser

//

this.textUser.Location = new System.Drawing.Point(8, 16);

this.textUser.Name = "textUser";

this.textUser.PasswordChar = "?";

this.textUser.Size = new System.Drawing.Size(168, 20);

this.textUser.TabIndex = 0;

this.textUser.Text = "";

//

// textPass

//

this.textPass.Location = new System.Drawing.Point(8, 48);

this.textPass.Name = "textPass";

this.textPass.PasswordChar = "*";

this.textPass.Size = new System.Drawing.Size(168, 20);

this.textPass.TabIndex = 1;

this.textPass.Text = "";

//

// label1

//

this.label1.Location = new System.Drawing.Point(192, 16);

this.label1.Name = "label1";

this.label1.Size = new System.Drawing.Size(112, 24);

this.label1.TabIndex = 2;

this.label1.Text = "Username";

//

// label2

//

this.label2.Location = new System.Drawing.Point(192, 48);

this.label2.Name = "label2";

this.label2.Size = new System.Drawing.Size(112, 24);

this.label2.TabIndex = 3;

this.label2.Text = "Password";

//

// btnOK

//

this.btnOK.Anchor = ((System.Windows.Forms.AnchorStyles.Top |

System.Windows.Forms.AnchorStyles.Bottom)

| System.Windows.Forms.AnchorStyles.Left);

this.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Popup;

this.btnOK.Image =

((System.Drawing.Bitmap)(resources.GetObject("btnOK.Image")));

this.btnOK.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;

this.btnOK.Location = new System.Drawing.Point(64, 96);

this.btnOK.Name = "btnOK";

this.btnOK.Size = new System.Drawing.Size(80, 24);

this.btnOK.TabIndex = 4;

this.btnOK.Text = "OK";

this.btnOK.Click += new System.EventHandler(this.btnOK_Click);

//

// btnCancel

//

this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Popup;

this.btnCancel.Image =

((System.Drawing.Bitmap)(resources.GetObject("btnCancel.Image")));

this.btnCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;

this.btnCancel.Location = new System.Drawing.Point(200, 96);

this.btnCancel.Name = "btnCancel";

this.btnCancel.TabIndex = 5;

this.btnCancel.Text = "Cancel";

this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(344, 133);

this.Controls.AddRange(new System.Windows.Forms.Control[] {

this.btnCancel,

this.btnOK,

this.label2,

this.label1,

this.textPass,

this.textUser});

this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));

this.Name = "Form1";

this.Text = "Validacija";

this.Load += new System.EventHandler(this.Form1_Load);

this.ResumeLayout(false);


}

#endregion


private void txtBoxUser_Validating (object sender,

System.ComponentModel.CancelEventArgs e)

{

TextBox    tb = (TextBox) sender;


if (textUser.Text == "igor") //&& textPass.Text == "igor")

{

tb.Tag = true;

}

ValidateAll();

}


private void txtBoxPass_Validating (object sender,

System.ComponentModel.CancelEventArgs e)

{

TextBox tb = (TextBox) sender;


if (textPass.Text == "igor")

{

tb.Tag = true;

}

else

{

Form4 novaForma = new Form4();

novaForma.Show();


//MessageBox.Show("Pogrešna šifra!");

}

ValidateAll();

}


private void ValidateAll()

{

this.btnOK.Enabled = ((bool)(this.textUser.Tag) &&

(bool)(this.textPass.Tag));

}


private void Form1_Load(object sender, System.EventArgs e)

{


}


private void btnOK_Click(object sender, System.EventArgs e)

{


Roditelj drugaForma = new Roditelj();

drugaForma.Show();


//MessageBox.Show("Pogrešna šifra!");



}



private void txtBoxUser_TextChanged (object sender, System.EventArgs e)

{

TextBox tb = (TextBox) sender;


if (textUser.Text != "igor")

{

tb.Tag = false;

}

ValidateAll();

}


private void txtBoxPass_TextChanged (object sender, System.EventArgs e)

{

TextBox tb = (TextBox) sender;


if (textPass.Text != "igor")

{

tb.Tag = false;

}

ValidateAll();

}


private void btnCancel_Click(object sender, System.EventArgs e)

{

this.Close();

}




}

}
 
Odgovor na temu

NeznamTkoSam

Član broj: 39660
Poruke: 279
*.cmu.carnet.hr.



Profil

icon Re: C# i forme09.01.2005. u 11:17 - pre 234 meseci
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!
 
Odgovor na temu

[es] :: .NET :: .NET Desktop razvoj :: C# i forme

[ Pregleda: 3434 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.