Autor Beitrag
$harp
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Mo 10.10.05 12:00 
Hi also ich habe 2 forms ...
Form1:
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace LanStat
{
  /// <summary>
  /// Zusammenfassung für Form1.
  /// </summary>
  public class Form1 : System.Windows.Forms.Form
  {
    public class Person
    {
      public int    ID = 0;
      public string Name = "";
      public string Vorname = "";
      public DateTime Gebdatum = DateTime.Now;
            public string Clan = "";
            public double Siege = 0;
            public double Loses = 0;
            public double Prozent = 0;

      public override string ToString()
      {
        return Name;
      }
    }      
    private System.Windows.Forms.PictureBox pictureBox1;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.TabControl tabControl1;
    private System.Windows.Forms.TabPage tabPage1;
    private System.Windows.Forms.TabPage tabPage2;
    private System.Windows.Forms.TabPage tabPage3;
    /// <summary>          
    /// Erforderliche Designervariable.
    /// </summary>
    private System.ComponentModel.Container components = null;
    private System.Windows.Forms.DateTimePicker dpGebdatum;

    public ArrayList PersonenArray = new ArrayList();           //container mit daten zu den personen
    private System.Windows.Forms.ListBox lbPersonenListe;
    private System.Windows.Forms.TextBox tbClan;
    private System.Windows.Forms.TextBox tbProzent;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.Button bEntfernen;
        private System.Windows.Forms.Label label7;
        private System.Windows.Forms.Label label8;
        private System.Windows.Forms.ListBox lbGames;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.TextBox tbLoses;
        private System.Windows.Forms.TextBox tbSiege;
        private System.Windows.Forms.Button bPunkte;
      private System.Windows.Forms.Label label1;
      private System.Windows.Forms.TextBox tbVorname;
      private System.Windows.Forms.TextBox tbName;
      private System.Windows.Forms.Label label6; 
    public int m_MaxIndex = 0;

    public Form1()
    {  
      
      //
      // Erforderlich für die Windows Form-Designerunterstützung
      //
      InitializeComponent();
      
      //
      // TODO: Fügen Sie den Konstruktorcode nach dem Aufruf von InitializeComponent hinzu
      //
    }

    /// <summary>
    /// Die verwendeten Ressourcen bereinigen.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
      if( disposing )
      {
        if (components != null
        {
          components.Dispose();
        }
      }
      base.Dispose( disposing );
    }

    #region Vom Windows Form-Designer generierter Code
    /// <summary>
    /// Erforderliche Methode für die Designerunterstützung. 
    /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
    /// </summary>
    private void InitializeComponent()
    {
         this.lbPersonenListe = new System.Windows.Forms.ListBox();
         this.pictureBox1 = new System.Windows.Forms.PictureBox();
         this.lbGames = new System.Windows.Forms.ListBox();
         this.label2 = new System.Windows.Forms.Label();
         this.tbClan = new System.Windows.Forms.TextBox();
         this.tabControl1 = new System.Windows.Forms.TabControl();
         this.tabPage1 = new System.Windows.Forms.TabPage();
         this.label4 = new System.Windows.Forms.Label();
         this.label3 = new System.Windows.Forms.Label();
         this.tbLoses = new System.Windows.Forms.TextBox();
         this.tbSiege = new System.Windows.Forms.TextBox();
         this.bPunkte = new System.Windows.Forms.Button();
         this.label8 = new System.Windows.Forms.Label();
         this.label7 = new System.Windows.Forms.Label();
         this.label5 = new System.Windows.Forms.Label();
         this.tbProzent = new System.Windows.Forms.TextBox();
         this.dpGebdatum = new System.Windows.Forms.DateTimePicker();
         this.tabPage2 = new System.Windows.Forms.TabPage();
         this.tabPage3 = new System.Windows.Forms.TabPage();
         this.bEntfernen = new System.Windows.Forms.Button();
         this.label1 = new System.Windows.Forms.Label();
         this.tbVorname = new System.Windows.Forms.TextBox();
         this.tbName = new System.Windows.Forms.TextBox();
         this.label6 = new System.Windows.Forms.Label();
         this.tabControl1.SuspendLayout();
         this.tabPage1.SuspendLayout();
         this.SuspendLayout();
         // 
         // lbPersonenListe
         // 
         this.lbPersonenListe.Location = new System.Drawing.Point(832);
         this.lbPersonenListe.Name = "lbPersonenListe";
         this.lbPersonenListe.Size = new System.Drawing.Size(112459);
         this.lbPersonenListe.TabIndex = 0;
         this.lbPersonenListe.SelectedIndexChanged += new System.EventHandler(this.OnSeletcetdItemChnaged);
         // 
         // pictureBox1
         // 
         this.pictureBox1.Location = new System.Drawing.Point(25624);
         this.pictureBox1.Name = "pictureBox1";
         this.pictureBox1.Size = new System.Drawing.Size(120144);
         this.pictureBox1.TabIndex = 4;
         this.pictureBox1.TabStop = false;
         // 
         // lbGames
         // 
         this.lbGames.Location = new System.Drawing.Point(112312);
         this.lbGames.Name = "lbGames";
         this.lbGames.Size = new System.Drawing.Size(12082);
         this.lbGames.TabIndex = 6;
         // 
         // label2
         // 
         this.label2.Location = new System.Drawing.Point(48312);
         this.label2.Name = "label2";
         this.label2.Size = new System.Drawing.Size(4816);
         this.label2.TabIndex = 7;
         this.label2.Text = "Games";
         // 
         // tbClan
         // 
         this.tbClan.Location = new System.Drawing.Point(128136);
         this.tbClan.Name = "tbClan";
         this.tbClan.ReadOnly = true;
         this.tbClan.Size = new System.Drawing.Size(10420);
         this.tbClan.TabIndex = 9;
         this.tbClan.Text = "";
         // 
         // tabControl1
         // 
         this.tabControl1.Controls.Add(this.tabPage1);
         this.tabControl1.Controls.Add(this.tabPage2);
         this.tabControl1.Controls.Add(this.tabPage3);
         this.tabControl1.Location = new System.Drawing.Point(1288);
         this.tabControl1.Name = "tabControl1";
         this.tabControl1.SelectedIndex = 0;
         this.tabControl1.Size = new System.Drawing.Size(720544);
         this.tabControl1.TabIndex = 11;
         // 
         // tabPage1
         // 
         this.tabPage1.Controls.Add(this.label4);
         this.tabPage1.Controls.Add(this.label3);
         this.tabPage1.Controls.Add(this.tbLoses);
         this.tabPage1.Controls.Add(this.tbSiege);
         this.tabPage1.Controls.Add(this.label8);
         this.tabPage1.Controls.Add(this.label7);
         this.tabPage1.Controls.Add(this.label6);
         this.tabPage1.Controls.Add(this.label5);
         this.tabPage1.Controls.Add(this.tbProzent);
         this.tabPage1.Controls.Add(this.dpGebdatum);
         this.tabPage1.Controls.Add(this.tbVorname);
         this.tabPage1.Controls.Add(this.tbName);
         this.tabPage1.Controls.Add(this.lbGames);
         this.tabPage1.Controls.Add(this.pictureBox1);
         this.tabPage1.Controls.Add(this.tbClan);
         this.tabPage1.Controls.Add(this.label2);
         this.tabPage1.Controls.Add(this.label1);
         this.tabPage1.Location = new System.Drawing.Point(422);
         this.tabPage1.Name = "tabPage1";
         this.tabPage1.Size = new System.Drawing.Size(712518);
         this.tabPage1.TabIndex = 0;
         this.tabPage1.Text = "tabPage1";
         this.tabPage1.Click += new System.EventHandler(this.tabPage1_Click);
         // 
         // label4
         // 
         this.label4.Location = new System.Drawing.Point(440344);
         this.label4.Name = "label4";
         this.label4.Size = new System.Drawing.Size(12016);
         this.label4.TabIndex = 24;
         this.label4.Text = "Loses gesamt";
         // 
         // label3
         // 
         this.label3.Location = new System.Drawing.Point(440312);
         this.label3.Name = "label3";
         this.label3.Size = new System.Drawing.Size(12016);
         this.label3.TabIndex = 23;
         this.label3.Text = "Siege gesamt";
         // 
         // tbLoses
         // 
         this.tbLoses.Location = new System.Drawing.Point(568344);
         this.tbLoses.Name = "tbLoses";
         this.tbLoses.ReadOnly = true;
         this.tbLoses.Size = new System.Drawing.Size(12020);
         this.tbLoses.TabIndex = 21;
         this.tbLoses.Text = "";
         // 
         // tbSiege
         // 
         this.tbSiege.Location = new System.Drawing.Point(568312);
         this.tbSiege.Name = "tbSiege";
         this.tbSiege.ReadOnly = true;
         this.tbSiege.Size = new System.Drawing.Size(12020);
         this.tbSiege.TabIndex = 22;
         this.tbSiege.Text = "";
         // 
         // bPunkte
         // 
         this.bPunkte.Location = new System.Drawing.Point(8496);
         this.bPunkte.Name = "bPunkte";
         this.bPunkte.Size = new System.Drawing.Size(11223);
         this.bPunkte.TabIndex = 20;
         this.bPunkte.Text = "Add";
         this.bPunkte.Click += new System.EventHandler(this.button2_Click);
         // 
         // label8
         // 
         this.label8.Location = new System.Drawing.Point(48136);
         this.label8.Name = "label8";
         this.label8.Size = new System.Drawing.Size(7216);
         this.label8.TabIndex = 19;
         this.label8.Text = "Clan";
         // 
         // label7
         // 
         this.label7.Location = new System.Drawing.Point(48104);
         this.label7.Name = "label7";
         this.label7.Size = new System.Drawing.Size(7216);
         this.label7.TabIndex = 18;
         this.label7.Text = "Geburtstag";
         // 
         // label5
         // 
         this.label5.Location = new System.Drawing.Point(440376);
         this.label5.Name = "label5";
         this.label5.Size = new System.Drawing.Size(12016);
         this.label5.TabIndex = 16;
         this.label5.Text = "Siege in Prozent";
         // 
         // tbProzent
         // 
         this.tbProzent.Location = new System.Drawing.Point(568376);
         this.tbProzent.Name = "tbProzent";
         this.tbProzent.ReadOnly = true;
         this.tbProzent.Size = new System.Drawing.Size(12020);
         this.tbProzent.TabIndex = 13;
         this.tbProzent.Text = "";
         // 
         // dpGebdatum
         // 
         this.dpGebdatum.CustomFormat = "";
         this.dpGebdatum.ImeMode = System.Windows.Forms.ImeMode.NoControl;
         this.dpGebdatum.Location = new System.Drawing.Point(128104);
         this.dpGebdatum.Name = "dpGebdatum";
         this.dpGebdatum.Size = new System.Drawing.Size(10420);
         this.dpGebdatum.TabIndex = 12;
         this.dpGebdatum.ValueChanged += new System.EventHandler(this.dpGebdatum_ValueChanged);
         // 
         // tabPage2
         // 
         this.tabPage2.Location = new System.Drawing.Point(422);
         this.tabPage2.Name = "tabPage2";
         this.tabPage2.Size = new System.Drawing.Size(712518);
         this.tabPage2.TabIndex = 1;
         this.tabPage2.Text = "tabPage2";
         // 
         // tabPage3
         // 
         this.tabPage3.Location = new System.Drawing.Point(422);
         this.tabPage3.Name = "tabPage3";
         this.tabPage3.Size = new System.Drawing.Size(712518);
         this.tabPage3.TabIndex = 2;
         this.tabPage3.Text = "tabPage3";
         this.tabPage3.Click += new System.EventHandler(this.tabPage3_Click);
         // 
         // bEntfernen
         // 
         this.bEntfernen.Location = new System.Drawing.Point(8528);
         this.bEntfernen.Name = "bEntfernen";
         this.bEntfernen.Size = new System.Drawing.Size(11223);
         this.bEntfernen.TabIndex = 17;
         this.bEntfernen.Text = "Entfernen";
         // 
         // label1
         // 
         this.label1.Location = new System.Drawing.Point(4840);
         this.label1.Name = "label1";
         this.label1.Size = new System.Drawing.Size(7216);
         this.label1.TabIndex = 5;
         this.label1.Text = "Name";
         // 
         // tbVorname
         // 
         this.tbVorname.Location = new System.Drawing.Point(12872);
         this.tbVorname.Name = "tbVorname";
         this.tbVorname.ReadOnly = true;
         this.tbVorname.Size = new System.Drawing.Size(10420);
         this.tbVorname.TabIndex = 2;
         this.tbVorname.Text = "";
         // 
         // tbName
         // 
         this.tbName.Location = new System.Drawing.Point(12840);
         this.tbName.Name = "tbName";
         this.tbName.ReadOnly = true;
         this.tbName.Size = new System.Drawing.Size(10420);
         this.tbName.TabIndex = 1;
         this.tbName.Text = "";
         // 
         // label6
         // 
         this.label6.Location = new System.Drawing.Point(4872);
         this.label6.Name = "label6";
         this.label6.Size = new System.Drawing.Size(7216);
         this.label6.TabIndex = 17;
         this.label6.Text = "Vorname";
         // 
         // Form1
         // 
         this.AutoScaleBaseSize = new System.Drawing.Size(513);
         this.ClientSize = new System.Drawing.Size(856557);
         this.Controls.Add(this.tabControl1);
         this.Controls.Add(this.lbPersonenListe);
         this.Controls.Add(this.bEntfernen);
         this.Controls.Add(this.bPunkte);
         this.Name = "Form1";
         this.Text = "Form1";
         this.Load += new System.EventHandler(this.Form1_Load);
         this.tabControl1.ResumeLayout(false);
         this.tabPage1.ResumeLayout(false);
         this.ResumeLayout(false);

      }
    #endregion

    /// <summary>
    /// Der Haupteinstiegspunkt für die Anwendung.
    /// </summary>
    [STAThread]
    static void Main() 
    {
      Application.Run(new Form1());
    }

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

    private void tabPage1_Click(object sender, System.EventArgs e)
    {
    
    }

    private void button1_Click(object sender, System.EventArgs e)
    {
      Person neuPerson   = new Person();      //neue person xD
      neuPerson.ID       = m_MaxIndex++;      //ordnet den personen eine laufende zahl zu
      neuPerson.Name     = tbName.Text;       //gibt den personennamen inne textBox Name
      neuPerson.Gebdatum = dpGebdatum.Value;  //geb datum halt :P
            neuPerson.Vorname  = tbVorname.Text;    //und der vorname
            neuPerson.Clan     = tbClan.Text;       //und der clan
            neuPerson.Siege    = Convert.ToDouble(tbSiege.Text);      //ja siege merken
            neuPerson.Loses    = Convert.ToDouble(tbLoses.Text);      //loses merken
            neuPerson.Prozent  = Convert.ToDouble(tbProzent.Text);    //prozent merken


      PersonenArray.Add(neuPerson);

      FillList();
    }

    public void FillList()                    //liste füllen
    {
      lbPersonenListe.Items.Clear();
      foreach (Person p in  PersonenArray)
      {
        lbPersonenListe.Items.Add(p);
      }
    }

    private void OnSeletcetdItemChnaged(object sender, System.EventArgs e)
    {
      Person p;

      int i = lbPersonenListe.SelectedIndex;
            if (i < PersonenArray.Count)
            {
                p = (Person)PersonenArray[i];
                //string s = (string)lbPersonenListe.SelectedValue;
                if (p != null)
                {
                    tbName.Text      = p.Name;
                    dpGebdatum.Value = p.Gebdatum;
                    tbVorname.Text   = p.Vorname;
                    tbClan.Text      = p.Clan;
                    tbSiege.Text     = p.Siege.ToString();
                    tbLoses.Text     = p.Loses.ToString();
                    tbProzent.Text   = p.Prozent.ToString();  
                }
            }                                                           
    }

    private void tabPage3_Click(object sender, System.EventArgs e)
    {
    
    }

        private void button2_Click(object sender, System.EventArgs e)
        {
            Form2 dlg = new Form2();
            dlg.tbLoses.Text = tbLoses.Text;
            dlg.tbSiege.Text = tbSiege.Text;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                // brechene
                tbLoses.Text = dlg.tbLoses.Text;
                tbSiege.Text = dlg.tbSiege.Text;

                int i1 = Int32.Parse(tbLoses.Text);
                int i2 = Int32.Parse(tbSiege.Text);
                double ergebnis = 0.00;
                ergebnis = BrechneDurchschnitt(i2, i1);

                ergebnis = Math.Round(ergebnis,4);
                tbProzent.Text =  ergebnis.ToString();
            }
        }

        public double BrechneDurchschnitt(int iSiege, int iLoses)
        {
            if ((iLoses + iSiege) == 0)
                return 0;
            else
                return (iSiege / ((double)iLoses + (double)iSiege));
        }

        private void dpGebdatum_ValueChanged(object sender, System.EventArgs e)
        {
        
        }
  }
}

und Form 2
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace LanStat
{
  /// <summary>
  /// Zusammenfassung für Form2.
  /// </summary>
  public class Form2 : System.Windows.Forms.Form
  {
        private System.Windows.Forms.Button button1;
      private System.Windows.Forms.Label label1;
      private System.Windows.Forms.TextBox tbVorname;
      private System.Windows.Forms.TextBox tbName;
      private System.Windows.Forms.Label label6;
      private System.Windows.Forms.Label label8;
      private System.Windows.Forms.TextBox tbClan;
      private System.Windows.Forms.Label label2;
      private System.Windows.Forms.CheckBox checkBox1;
      private System.Windows.Forms.CheckBox checkBox2;
      private System.Windows.Forms.CheckBox checkBox3;
      private System.Windows.Forms.CheckBox checkBox4;
      private System.Windows.Forms.CheckBox checkBox5;
      private System.Windows.Forms.CheckBox checkBox6;
      private System.Windows.Forms.CheckBox checkBox7;
      private System.Windows.Forms.CheckBox checkBox8;
      private System.Windows.Forms.CheckBox checkBox9;
      private System.Windows.Forms.CheckBox checkBox10;
    /// <summary>
    /// Erforderliche Designervariable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public Form2()
    {
      //
      // Erforderlich für die Windows Form-Designerunterstützung
      //
      InitializeComponent();

      //
      // TODO: Fügen Sie den Konstruktorcode nach dem Aufruf von InitializeComponent hinzu
      //
    }

    /// <summary>
    /// Die verwendeten Ressourcen bereinigen.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
      if( disposing )
      {
        if(components != null)
        {
          components.Dispose();
        }
      }
      base.Dispose( disposing );
    }

    #region Vom Windows Form-Designer generierter Code
    /// <summary>
    /// Erforderliche Methode für die Designerunterstützung. 
    /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
    /// </summary>
    private void InitializeComponent()
    {
         this.button1 = new System.Windows.Forms.Button();
         this.label1 = new System.Windows.Forms.Label();
         this.tbVorname = new System.Windows.Forms.TextBox();
         this.tbName = new System.Windows.Forms.TextBox();
         this.label6 = new System.Windows.Forms.Label();
         this.label8 = new System.Windows.Forms.Label();
         this.tbClan = new System.Windows.Forms.TextBox();
         this.label2 = new System.Windows.Forms.Label();
         this.checkBox1 = new System.Windows.Forms.CheckBox();
         this.checkBox2 = new System.Windows.Forms.CheckBox();
         this.checkBox3 = new System.Windows.Forms.CheckBox();
         this.checkBox4 = new System.Windows.Forms.CheckBox();
         this.checkBox5 = new System.Windows.Forms.CheckBox();
         this.checkBox6 = new System.Windows.Forms.CheckBox();
         this.checkBox7 = new System.Windows.Forms.CheckBox();
         this.checkBox8 = new System.Windows.Forms.CheckBox();
         this.checkBox9 = new System.Windows.Forms.CheckBox();
         this.checkBox10 = new System.Windows.Forms.CheckBox();
         this.SuspendLayout();
         // 
         // button1
         // 
         this.button1.Location = new System.Drawing.Point(208240);
         this.button1.Name = "button1";
         this.button1.TabIndex = 20;
         this.button1.Text = "OK";
         this.button1.Click += new System.EventHandler(this.button1_Click);
         // 
         // label1
         // 
         this.label1.Location = new System.Drawing.Point(816);
         this.label1.Name = "label1";
         this.label1.Size = new System.Drawing.Size(7216);
         this.label1.TabIndex = 5;
         this.label1.Text = "Name";
         // 
         // tbVorname
         // 
         this.tbVorname.Location = new System.Drawing.Point(8848);
         this.tbVorname.Name = "tbVorname";
         this.tbVorname.Size = new System.Drawing.Size(10420);
         this.tbVorname.TabIndex = 2;
         this.tbVorname.Text = "";
         // 
         // tbName
         // 
         this.tbName.Location = new System.Drawing.Point(8816);
         this.tbName.Name = "tbName";
         this.tbName.Size = new System.Drawing.Size(10420);
         this.tbName.TabIndex = 1;
         this.tbName.Text = "";
         // 
         // label6
         // 
         this.label6.Location = new System.Drawing.Point(848);
         this.label6.Name = "label6";
         this.label6.Size = new System.Drawing.Size(7216);
         this.label6.TabIndex = 17;
         this.label6.Text = "Vorname";
         // 
         // label8
         // 
         this.label8.Location = new System.Drawing.Point(880);
         this.label8.Name = "label8";
         this.label8.Size = new System.Drawing.Size(7216);
         this.label8.TabIndex = 22;
         this.label8.Text = "Clan";
         // 
         // tbClan
         // 
         this.tbClan.Location = new System.Drawing.Point(8880);
         this.tbClan.Name = "tbClan";
         this.tbClan.Size = new System.Drawing.Size(10420);
         this.tbClan.TabIndex = 21;
         this.tbClan.Text = "";
         // 
         // label2
         // 
         this.label2.Location = new System.Drawing.Point(8112);
         this.label2.Name = "label2";
         this.label2.Size = new System.Drawing.Size(4816);
         this.label2.TabIndex = 24;
         this.label2.Text = "Games";
         // 
         // checkBox1
         // 
         this.checkBox1.Location = new System.Drawing.Point(56112);
         this.checkBox1.Name = "checkBox1";
         this.checkBox1.Size = new System.Drawing.Size(8816);
         this.checkBox1.TabIndex = 25;
         this.checkBox1.Text = "Cs 1.6";
         // 
         // checkBox2
         // 
         this.checkBox2.Location = new System.Drawing.Point(56136);
         this.checkBox2.Name = "checkBox2";
         this.checkBox2.Size = new System.Drawing.Size(8816);
         this.checkBox2.TabIndex = 26;
         this.checkBox2.Text = "CS:S";
         // 
         // checkBox3
         // 
         this.checkBox3.Location = new System.Drawing.Point(56160);
         this.checkBox3.Name = "checkBox3";
         this.checkBox3.Size = new System.Drawing.Size(8816);
         this.checkBox3.TabIndex = 27;
         this.checkBox3.Text = "Doom 3";
         // 
         // checkBox4
         // 
         this.checkBox4.Location = new System.Drawing.Point(56184);
         this.checkBox4.Name = "checkBox4";
         this.checkBox4.Size = new System.Drawing.Size(8816);
         this.checkBox4.TabIndex = 28;
         this.checkBox4.Text = "UT";
         // 
         // checkBox5
         // 
         this.checkBox5.Location = new System.Drawing.Point(56208);
         this.checkBox5.Name = "checkBox5";
         this.checkBox5.Size = new System.Drawing.Size(8816);
         this.checkBox5.TabIndex = 29;
         this.checkBox5.Text = "Starcraft";
         // 
         // checkBox6
         // 
         this.checkBox6.Location = new System.Drawing.Point(152112);
         this.checkBox6.Name = "checkBox6";
         this.checkBox6.Size = new System.Drawing.Size(8816);
         this.checkBox6.TabIndex = 30;
         this.checkBox6.Text = "Warcraft 3";
         // 
         // checkBox7
         // 
         this.checkBox7.Location = new System.Drawing.Point(152136);
         this.checkBox7.Name = "checkBox7";
         this.checkBox7.Size = new System.Drawing.Size(9616);
         this.checkBox7.TabIndex = 31;
         this.checkBox7.Text = "Warcraft : TFT";
         // 
         // checkBox8
         // 
         this.checkBox8.Location = new System.Drawing.Point(152160);
         this.checkBox8.Name = "checkBox8";
         this.checkBox8.Size = new System.Drawing.Size(8816);
         this.checkBox8.TabIndex = 32;
         this.checkBox8.Text = "AOE 3";
         // 
         // checkBox9
         // 
         this.checkBox9.Location = new System.Drawing.Point(152184);
         this.checkBox9.Name = "checkBox9";
         this.checkBox9.Size = new System.Drawing.Size(9616);
         this.checkBox9.TabIndex = 33;
         this.checkBox9.Text = "Empire Earth";
         // 
         // checkBox10
         // 
         this.checkBox10.Location = new System.Drawing.Point(152208);
         this.checkBox10.Name = "checkBox10";
         this.checkBox10.Size = new System.Drawing.Size(8816);
         this.checkBox10.TabIndex = 34;
         this.checkBox10.Text = "Soldat";
         // 
         // Form2
         // 
         this.AutoScaleBaseSize = new System.Drawing.Size(513);
         this.ClientSize = new System.Drawing.Size(292273);
         this.Controls.Add(this.checkBox10);
         this.Controls.Add(this.checkBox9);
         this.Controls.Add(this.checkBox8);
         this.Controls.Add(this.checkBox7);
         this.Controls.Add(this.checkBox6);
         this.Controls.Add(this.checkBox5);
         this.Controls.Add(this.checkBox4);
         this.Controls.Add(this.checkBox3);
         this.Controls.Add(this.checkBox2);
         this.Controls.Add(this.checkBox1);
         this.Controls.Add(this.label2);
         this.Controls.Add(this.label8);
         this.Controls.Add(this.tbClan);
         this.Controls.Add(this.button1);
         this.Controls.Add(this.label1);
         this.Controls.Add(this.tbVorname);
         this.Controls.Add(this.tbName);
         this.Controls.Add(this.label6);
         this.Name = "Form2";
         this.Text = "Form2";
         this.Load += new System.EventHandler(this.Form2_Load);
         this.ResumeLayout(false);

      }
    #endregion

        private void button1_Click(object sender, System.EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

      private void Form2_Load(object sender, System.EventArgs e)
      {
      
      }
  }
}


Ich will jez all die daten die ich in Form 2 eingetragen habe in Form 1 übertragen haben :) wie mach ich das ^^
ani
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 77

Windows Vista Home Premium
C#(VS 2008)
BeitragVerfasst: Di 11.10.05 12:00 
Du schreibst eine funktion in form2 die deine daten an die form1 schickt.

in Form2:
ausblenden C#-Quelltext
1:
2:
3:
4:
datentyp funktionsname(datentyp parameter1,datentyp parameter2)
{
    return parameter1 + parameter2;
}


in Form1 kommt der funktionsaufruf:

ausblenden C#-Quelltext
1:
datentyp variable = Form2.funktionsName();					


ist schon lange her...du musst glaub ich die funktion static puplic machen (form2)damit die form1 drauf zugreifen kann.
probiers mal aus, ich suchs derweil hier in meinen unterlagen :)
Robert_G
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 416


Delphi32 (D2005 PE); Chrome/C# (VS2003 E/A, VS2005)
BeitragVerfasst: Mi 12.10.05 01:36 
Könntest du beim nächsten Mal bitte nur die notwendigen Schnipsel einfügen?
Wegen diesen 2 hingeschluderten kompletten Dateien wollte ich hier eigentlich nichts antworten...

Zum Problem:
Du solltest deinen Code style und deine Herangehensweise von Delphi auf .Net umstellen.

  • C# hat einen multi pass compiler, d.h.: du kannst problemlos deine Klasse Person nehmen und in eine eigene Datei packen.
  • Nested classes sollten nur private/protected sein. Um Ordnung zu waren sind namespaces da.
  • Üffentliche felder sollten höchtens für value types (struct) verwendet werden, sonst Properties. (z.b.: ohne Properties, kein DataBinding ;) )


Da .Net 2.0 vor der Tür steht[meta]Release am 7.11.[/meta], werde ich nur auf das VS2005 eingehen. (Die Beta von C# Express kannst du noch bei MS saugen)

Ich habe deine Person so geändert:
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
public class Person
{
  int id;
  string name;
  string firstName;
  DateTime birthDate;
  string clan;
  double won;
  double lost;
  double percentage;

  public int Id
  {
    get { return id; }
    set { id = value; }
  }
  public string Name
  {
    get { return name; }
    set { name = value; }
  }
  public string FirstName
  {
    get { return firstName; }
    set { firstName = value; }
  }
  public DateTime BirthDate
  {
    get { return birthDate; }
    set { birthDate = value; }
  }
  public string Clan
  {
    get { return clan; }
    set { clan = value; }
  }
  public double Won
  {
    get { return won; }
    set { won = value; }
  }
  public double Lost
  {
    get { return lost; }
    set { lost = value; }
  }
  public double Percentage
  {
    get { return percentage; }
    set { percentage = value; }
  }

  public override string ToString()
  {
    if (!string.IsNullOrEmpty(firstName))
      return string.Format("{0}, {1}", name, firstName);
    else
      return name;
  }
}


Das Ganze einmal kompilieren.
Nun kannst du im Menü unter Dataßadd new DataSource deine Person auswählen um sie für den Designer sichtbar zu machen.
In der DataSorces Ansicht siehst du nun deine Person und kannst sie auf dein Form ziehen. Dabei wird ein vorkonfigurierter DataGridView eine BindingSource und ein BindingNavigator angelegt.

Lege nun ein nuees Form an[meta]bleiben wir ruhig bei Form1 und Form2...[/meta].
In den DataSources-Übersicht änderst du die Ansicht von Person indem du auf den DropDown button klickst.
Du kannst nun vom Grid auf Details wechseln[meta]sieht ähnlich aus wie ein Form icon[/meta].
Jetzt ziehst du wieder deine Person auf die Form und hast für jede Property ein passendes Control sowie ein Label.
Den Navigator brauchen wir hier nicht, den kannst du einfach löschen.
Sicherheitshalber jetzt alles speichern. ;)
nun noch die üblichen OK/Cancel buttons[meta]für den DialogResult[/meta] und wir können in den Code wechseln.
Wir fügen eine öffentliche Eigenschaft hinzu, um von außen eine Person an die bindingSource zu hängen, bzw. auszulesen. Aus Einfachheit gleich noch einen constructor, der diese Eigenschaft vorbesetzt:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
public Form2()
{
  InitializeComponent();
}

public Person Person
{
  get { return personBindingSource.DataSource as Person; }
  set { personBindingSource.DataSource = value; }
}

public Form2(Person person) : this()
{
  Person = person;
}

Nun noch deine 2 ButtonClick handler[meta]Darin _nur_ DialogResult bestzen[/meta] und das war's für Form2. ;)
Speichern (nicht vergessen: Beta :P )

Zu Form1:

Hier haben wir ja bereits unseren DataGridView (DGV) und die BindingSource (BS) bzw den Navigator (BN).
Wenn der User eine neue Person anlegt, soll sich das Form2 öffnen so dass er darin die Daten eingeben kann.
Die DGV sollte also so geändert werden, dass darüber keine neuen Personen angelegt werden können. Einfach draufklicken und oben links im Smart Tag das Hinzufügen deaktivieren.
Damit wir das Hinzufügen im BN selbst behandeln können schalten wir die Standard funktion dafür ab. Im Property View findest du unter Items "AddNewItem", setze das auf null.
Nn können wir mit dem Button[meta]der, der aussieht wie ein gelber Stern[/meta] machen was wir wollen.
Also: Doppelklick auf den ToolButton in der TooolBar vom Navigator. ;)

Wir erzeugen eine neue Person, übergeben sie dem constructor von Form2 und führen es als modalen Dialog aus.
Wenn der User OK angeklickt hat kommt die Person in die BS. Das using verhindert ein MemLeak, da modale Dialoge kein Dispose in Close ausführen.
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
{
  Person person = new Person();

  using (Form2 dialog = new Form2(person))
  {
    if (dialog.ShowDialog() == DialogResult.OK)
    {
      personBindingSource.Add(person);
    }
  }
}


Oh eins noch, wo wir gerade im Code sind...
Die BS enthält ja noch kein Objekt als DataSource. :shock:
Im Form2 haben wir nur eine einzelne Person gehbt, hier in form1 haben wir aber eine Liste von Personen.
Dafür bietet sich eine BindingList[meta]Für die Suche in der Doku: System.ComponentModel.BinindList bzw IBindingList[/meta].
Die Liste übergeben wir der BS einfach direkt im constructor[meta]wichtig: _nach_ InitializeComponents[/meta]:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
public Form1()
{
  InitializeComponent();

  personBindingSource.DataSource = new BindingList<Person>();
}


Das war's schon. ;)
Ich habe eine Details Ansicht noch neben die DGV gepackt und einen Screenie gemacht.

Mag zwar alles im 5. Gang runtergerasselt worden sein, aber
  1. für jeden unklaren Begriff gibt es die ausführliche .Net SDK Doku und
  2. dürftest du beim Durchgegehn der Schritte[meta]immer schön mit der Doku[/meta] ganz schnell auf den Trichter kommen
.
_Eigentlich_ hättest du Person nur als öffentliche Klasse deklarieren und eine Instanz dem Form2 übergeben müssen. Da ich aber gerade Lust hatte ist dann doch noch etwas DataBinding á la .Net2.0 draus geworden. :mrgreen:

Da im Code ausschließlich gegen die BS geschrieben wurde, kannst um Design machen was immer du willst. Zum Beispiel den DGV gegen eine ComboBox, ListBox oder ein DataGrid oder die Controls in Form2 gegen andere tauschen. Ist vollkommen Bohne. Und alles ohne ekliges DataSet. :)
Einloggen, um Attachments anzusehen!
$harp Threadstarter
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Mi 12.10.05 11:28 
Habe ich erwähnt das ich mich seid gut 3 wochen mit c# und .net beschäftige ... aber hey ich schaff das Oo ^^ thx aber schonmal auch wenn es sehr hart wird ^^