Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 00:07

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[C#] Variable aus Form 2 in Form 3

Discussion on [C#] Variable aus Form 2 in Form 3 within the .NET Languages forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Nov 2010
Posts: 8
Received Thanks: 2
[C#] Variable aus Form 2 in Form 3

Hallo, ich bin gerade dabei ein kleinen Bot zu schreiben.. Dabei habe ich eine Form 1 wo mein Browser ( also das Spiel ) drauf läuft. Nun habe ich einen Button, der eine 2 Form öffnet wo man seine Logindaten eingeben kann. Diese daten sollen in string´s gespeichert werden und dann an die Form 3 ( die sich nachdem man Save auf der Form2 gedrückt hat ) gesendet werden und dort dann wieder ausgegeben werden. Doch leider bekomme ich das einfach nicht hin. In google stehen viele verschiedene sachen, die mir aber alle nicht geholfen haben. Daher habe ich mich dazu entschieden hier mal nach zufragen.

Mfg Ramon0205
Ramon0205 is offline  
Old 10/19/2013, 00:21   #2

 
snow's Avatar
 
elite*gold: 724
Join Date: Mar 2011
Posts: 10,479
Received Thanks: 3,318
Schau dir mal Konstruktoren an:
So kannst du Parameter bei der Erstellung von Form3 übergeben.

Das gehört übrigens in die .NET Sektion (), ich schicke mal einen Moverequest ab.
snow is offline  
Thanks
2 Users
Old 10/19/2013, 16:47   #3
 
elite*gold: 15
Join Date: Aug 2012
Posts: 3,041
Received Thanks: 6,397
Form3:
Code:
public string userName;
public string password;
Form2:
Code:
/*
There should be 2 textboxes.
usernameTXT is for the username
passwordTXT is for the password
*/

//Declaration;
private Form3 _Form3 = null;

//Form Load Event;
_Form3 = new Form3();

//Form Close Event;
_Form3.userName = usernameTXT.Text;
_Form3.password = passwordTXT.Text;
_Form3.Dispose(); _Form3 = null;
You can then use them on Form3 using userName & password
berkay2578 is offline  
Old 10/21/2013, 10:54   #4
 
elite*gold: 5
Join Date: Mar 2008
Posts: 460
Received Thanks: 436
Hör bitte nicht auf "berkay2578"

sondern löse es wie snow schon schrieb mittels Konstruktoren, denn dafür sind diese da!


Klar funktioniert das bestimmt auch, aber SAUBER ist was anderes...
SwarN is offline  
Thanks
2 Users
Old 10/22/2013, 19:55   #5
 
elite*gold: 26
Join Date: Sep 2009
Posts: 14
Received Thanks: 2
are you kidding me?
just create class

Code:
public class hereIam
{
public static string variblenumber1 {get;set;}
}
and use
Code:
hereIam.variblenumber1 = "1";
from everywhere.
Icestreak is offline  
Old 10/22/2013, 20:27   #6

 
snow's Avatar
 
elite*gold: 724
Join Date: Mar 2011
Posts: 10,479
Received Thanks: 3,318
Wow, lets violate every single rule about object orientated programming and data encapsulation. :<
snow is offline  
Thanks
11 Users
Old 10/22/2013, 21:10   #7
 
elite*gold: 0
Join Date: Nov 2007
Posts: 62
Received Thanks: 17
Form1 (Browser):

Code:
    public partial class Form1 : Form
    {
        public Form1()
        {
            this.InitializeComponent();
        }

        private void OnButtonOpenForm2Click(object sender, EventArgs e)
        {
            var form2 = new Form2();
            form2.ShowDialog(this);
        }
    }
Form2 (Login):

Code:
    public partial class Form2 : Form
    {
        public Form2()
        {
            this.InitializeComponent();
        }

        private void OnButtonSaveClick(object sender, EventArgs e)
        {
            var loginParameter = new LoginParameter
            {
                Username = "John Doe",  // Or Username = this.TextBoxUsername.Text
                Password = "12345"       // Or Password =  this.TextBoxPassword.Text
            };

            var form3 = new Form3(loginParameter); // Pass login parameters to form3 via constructor.
            form3.ShowDialog(this);
        }
    }
Form3 (Output):

Code:
    public partial class Form3 : Form
    {
        private readonly LoginParameter _loginParameter;

        public Form3(LoginParameter loginParameter)
        {
            this.InitializeComponent();
            this._loginParameter = loginParameter;
        }

        private void ShowLoginParameter()
        {
            string text = String.Format("User: {0} | Password: {1}",
                this._loginParameter.Username, this._loginParameter.Password);

            MessageBox.Show(text, "Login Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
LoginParameter.cs (Extra class for login information)

Code:
    public class LoginParameter
    {
        public string Username { get; set; }
        public string Password { get; set; }
    }
Not tested.
Demon-777 is offline  
Old 11/16/2013, 17:26   #8
 
DeinMud's Avatar
 
elite*gold: 0
Join Date: Jan 2010
Posts: 990
Received Thanks: 127
Form1:

Code:
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form3 frm3 = new Form3();
            frm3.Show();
        }
    }
}
Form2:

Code:
namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        public delegate void LoginEventHandler(object sender, LoginEventArgs e);
        public event LoginEventHandler LoggedIn;
        private void button1_Click_1(object sender, EventArgs e)
        {
            LoggedIn(this, new LoginEventArgs(textBox1.Text, textBox2.Text));
        }
    }

    public class LoginEventArgs
    {
        private string _username;
        public string username { get { return _username; } }
        private string _password;
        public string password { get { return _password; } }
        public LoginEventArgs(string Username, string password)
        {
            this._username = Username;
            this._password = password;
        }

    }
}
Form3:

Code:
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 WindowsFormsApplication1
{
    public partial class Form3 : Form
    {

        public Form3()
        {
            InitializeComponent();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            Form2 frm2 = new Form2();
            frm2.Show();
            frm2.LoggedIn += received;
        }
        private void received(object sender,LoginEventArgs e)
        {
            MessageBox.Show(e.username);
            MessageBox.Show(e.password);
        }
    }
}
DeinMud is offline  
Old 11/23/2013, 23:45   #9
 
elite*gold: 0
Join Date: May 2011
Posts: 179
Received Thanks: 19
Getters und setters festlegen. Dann kannst du ganz normal auf die Variablen zugreifen

LG
Krass, was? is offline  
Old 11/27/2013, 21:35   #10
 
Strean's Avatar
 
elite*gold: 141
Join Date: Dec 2009
Posts: 554
Received Thanks: 3,920
oder man macht es sich ganz einfach in eine properties datei
Strean is offline  
Reply


Similar Threads Similar Threads
Druid Cat Form -> FireLands Cat Form
08/01/2011 - World of Warcraft - 2 Replies
Hallo Leute, hat jemand die Möglichkeiten mir eine Tauren Katze zur Firelands Katze zu swappen - sofern dies in 4.2 FIRELANDS noch möglich ist. Wobei die Vergangenheit uns gelehrt hat, das es immer Mittel und Wege gibt. (: http://manaflask.com/images/galleries/scaled_1307 971939_flamecat.jpg LG Windkirsche
Von Form Zu Form Wechseln.
04/14/2011 - AutoIt - 2 Replies
Hallo Erstmal! Ich wollte mal etwas machen das von einer form zur anderen wechselt jetzt wollt ich das aber auch so machen das wenn man auf einen zurück button klickt es wieder zur ersten form kommt und dann alles neu einstellen kann. also bis zu dem zurück und neu einstellen hab ich geschafft aber wenn man dann wieder auf weiter klickt passiert nix ... Könntet ihr mir helfen? Hier ist ein beispiel script #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include...
Form unsichtbar machen und Variable senden
09/18/2010 - AutoIt - 4 Replies
Hallo, ich habe zwei kleine Probleme und bin durch Google nicht fündig geworden. Wie kann man bei einer Form visible setzen und wie kann ich eine Variable mit Send() senden? Danke schonmal im vorraus :D FizzeBu
Druid Tree form buff without tree Form
11/11/2007 - WoW Exploits, Hacks, Tools & Macros - 5 Replies
My buddy and i were screwing around the other day in Mech and we figured out a way to have a working tree form buff for the party but not be in tree form. Which if anyone knows about druids allows them to cast all their other high healing spells. Anyway follow the instructions below its a bit tricky 1. Change your chest item to something else 2. Get into Combat.. Queue your chestpiece to switch back to your original 3. When the fights finishing, Get ready.. The second the...



All times are GMT +1. The time now is 00:08.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.