Autor Beitrag
prose
Hält's aus hier
Beiträge: 2



BeitragVerfasst: Di 18.10.05 20:09 
Abend!

ich will gerade einen Würfel machen, der nach einer random Zahl (1-6) ausgibt...

ich zeichne den rand mit DrawRectangle und die Punkte des Würfels mit FillEllipse...
zuerst muss man ja Graphics importieren, mit

Graphics g = e.Graphics;

Da bekomm ich aber schon den ersten fehler(using's wurden alle korrekt eingefügt)...
'System.Event.Args' does not contain a definition for 'Graphics'(CS0117)

Ich weiss ned was falsch ist...
und mit der Auswertung der random Zahl haut auch etwas nicht hin..
ich wil haben dass wenn die Zhal 1 ist, der ganz mittlere Punkt gezeichnet wird, aber er schreibt hier:
Cannot implicitly convert type 'int' to 'bool'(CS0029)


LG PRose

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:
/*
 * Created by SharpDevelop.
 * User: Admin
 * Date: 17.10.2005
 * Time: 19:32
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace Wuerfel
{
  /// <summary>F52A02BD-44DF-4AA9-9EFD-FF98E2DF1FFF
  /// Description of MainForm.
  /// </summary>
  public class MainForm : System.Windows.Forms.Form
  {
    private System.Windows.Forms.Button wuerfelButton;
    private System.Windows.Forms.PictureBox pictureBox;
    private System.Windows.Forms.Label ergebnisLabel;
    public MainForm()
    {
      //
      // The InitializeComponent() call is required for Windows Forms designer support.
      //
      InitializeComponent();
      
      //
      // TODO: Add constructor code after the InitializeComponent() call.
      //
    }
    
    [STAThread]
    public static void Main(string[] args)
    {
      Application.Run(new MainForm());
    }
    
    #region Windows Forms Designer generated code
    /// <summary>
    /// This method is required for Windows Forms designer support.
    /// Do not change the method contents inside the source code editor. The Forms designer might
    /// not be able to load this method if it was changed manually.
    /// </summary>
    private void InitializeComponent() {
      this.ergebnisLabel = new System.Windows.Forms.Label();
      this.pictureBox = new System.Windows.Forms.PictureBox();
      this.wuerfelButton = new System.Windows.Forms.Button();
      this.SuspendLayout();
      // 
      // ergebnisLabel
      // 
      this.ergebnisLabel.Font = new System.Drawing.Font("Arial"15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
      this.ergebnisLabel.Location = new System.Drawing.Point(16024);
      this.ergebnisLabel.Name = "ergebnisLabel";
      this.ergebnisLabel.Size = new System.Drawing.Size(16872);
      this.ergebnisLabel.TabIndex = 2;
      this.ergebnisLabel.Text = "0";
      this.ergebnisLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
      this.ergebnisLabel.Click += new System.EventHandler(this.Label2Click);
      // 
      // pictureBox
      // 
      this.pictureBox.BackColor = System.Drawing.Color.Crimson;
      this.pictureBox.Location = new System.Drawing.Point(88);
      this.pictureBox.Name = "pictureBox";
      this.pictureBox.Size = new System.Drawing.Size(140140);
      this.pictureBox.TabIndex = 0;
      this.pictureBox.TabStop = false;
      // 
      // wuerfelButton
      // 
      this.wuerfelButton.Location = new System.Drawing.Point(160120);
      this.wuerfelButton.Name = "wuerfelButton";
      this.wuerfelButton.Size = new System.Drawing.Size(16824);
      this.wuerfelButton.TabIndex = 3;
      this.wuerfelButton.Text = "Würfeln";
      this.wuerfelButton.Click += new System.EventHandler(this.Button1Click);
      // 
      // MainForm
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.ClientSize = new System.Drawing.Size(336158);
      this.Controls.Add(this.wuerfelButton);
      this.Controls.Add(this.ergebnisLabel);
      this.Controls.Add(this.pictureBox);
      this.Name = "MainForm";
      this.Text = "MainForm";
      this.ResumeLayout(false);
    }
    #endregion
    void Label1Click(object sender, System.EventArgs e)
    {
      
    }
    
    void Label2Click(object sender, System.EventArgs e)
    {
      
    }
    
    void Button1Click(object sender, System.EventArgs e)
    {
      int zahl;
      Random r = new Random();
      zahl = r.Next(1,6);
      ergebnisLabel.Text = "Die Würfel sind gefallen! Die "+zahl+" wurde gewürfelt";
      
      Graphics g = e.Graphics;
      Pen pen = new Pen(Color.White,3);
      SolidBrush solidBrush = new SolidBrush(Color.FromArgb(02550125));
            
      if(zahl=1){
        g.FillEllipse(solidBrush, 60608080); 
      }
      if(zahl=2){
        g.FillEllipse(solidBrush, 1002012040); 
        g.FillEllipse(solidBrush, 2010040120);
      }
      if(zahl=3){
        g.FillEllipse(solidBrush, 1002012040);
        g.FillEllipse(solidBrush, 60608080);
        g.FillEllipse(solidBrush, 2010040120);
      }
      if(zahl=4){
        g.FillEllipse(solidBrush, 20204040);
        g.FillEllipse(solidBrush, 1002012040);
        g.FillEllipse(solidBrush, 2010040120);
        g.FillEllipse(solidBrush, 100100120120); 
      }
      if(zahl=5){
        g.FillEllipse(solidBrush, 20204040); 
        g.FillEllipse(solidBrush, 1002012040);
        g.FillEllipse(solidBrush, 2010040120);
        g.FillEllipse(solidBrush, 100100120120); 
        g.FillEllipse(solidBrush, 2010040120);
      }
      if(zahl=6){
        g.FillEllipse(solidBrush, 20204040); 
        g.FillEllipse(solidBrush, 60208040);
        g.FillEllipse(solidBrush, 1002012040);
        g.FillEllipse(solidBrush, 2010040120); 
        g.FillEllipse(solidBrush, 6010080120);
        g.FillEllipse(solidBrush, 100100120120); 
      }
    }
    
  }
}
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 19.10.05 09:24 
Ich weiß jetzt gar nicht was ich hier schreiben soll um dir zu helfen...
Die Compiler meldung ist doch glasklar, die Code completion zeigt dir auch keinen Member Graphics in EventArgs und auch die SDK Doku wird dir keinen Member namens Graphics in EventArgs zeigen.

Genau das ist jetzt hier die Zwickmühle: Ich könnte dir schreiben wie es richtig aussehen muss, aber wenn ich das mache kommst du immer wieder und öffnest Threads ohne dich selbst damit auseinandergesetzt zu haben. :eyes:

Sorry, kann ich nicht machen, ich würde es sogar jedem übel nehmen, der es macht...
prose Threadstarter
Hält's aus hier
Beiträge: 2



BeitragVerfasst: Mi 19.10.05 22:56 
neich habs dann gesehen... hab schon verbessert...

das problem ist, ich bekomme zwar die zufallszahl ausgegeben, aber in meiner pictureBox sehe ich dir Würfel-Augen nicht...

LG

sieht jetzt so aus:
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:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace Wuerfel
{
  public class MainForm : System.Windows.Forms.Form
  {
    private System.Windows.Forms.Button wuerfelButton;
    private System.Windows.Forms.PictureBox pictureBox;
    private System.Windows.Forms.Label ergebnisLabel;
    public MainForm()
    {
      //
      // The InitializeComponent() call is required for Windows Forms designer support.
      //
      InitializeComponent();
      
      //
      // TODO: Add constructor code after the InitializeComponent() call.
      //
    }
    
    [STAThread]
    public static void Main(string[] args)
    {
      Application.Run(new MainForm());
    }
    
    #region Windows Forms Designer generated code
    /// <summary>
    /// This method is required for Windows Forms designer support.
    /// Do not change the method contents inside the source code editor. The Forms designer might
    /// not be able to load this method if it was changed manually.
    /// </summary>
    private void InitializeComponent() {
      this.ergebnisLabel = new System.Windows.Forms.Label();
      this.pictureBox = new System.Windows.Forms.PictureBox();
      this.wuerfelButton = new System.Windows.Forms.Button();
      this.SuspendLayout();
      // 
      // ergebnisLabel
      // 
      this.ergebnisLabel.Font = new System.Drawing.Font("Arial"15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
      this.ergebnisLabel.Location = new System.Drawing.Point(16024);
      this.ergebnisLabel.Name = "ergebnisLabel";
      this.ergebnisLabel.Size = new System.Drawing.Size(16872);
      this.ergebnisLabel.TabIndex = 2;
      this.ergebnisLabel.Text = "0";
      this.ergebnisLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
      this.ergebnisLabel.Click += new System.EventHandler(this.Label2Click);
      // 
      // pictureBox
      // 
      this.pictureBox.BackColor = System.Drawing.Color.Crimson;
      this.pictureBox.Location = new System.Drawing.Point(88);
      this.pictureBox.Name = "pictureBox";
      this.pictureBox.Size = new System.Drawing.Size(140140);
      this.pictureBox.TabIndex = 0;
      this.pictureBox.TabStop = false;
      // 
      // wuerfelButton
      // 
      this.wuerfelButton.Location = new System.Drawing.Point(160120);
      this.wuerfelButton.Name = "wuerfelButton";
      this.wuerfelButton.Size = new System.Drawing.Size(16824);
      this.wuerfelButton.TabIndex = 3;
      this.wuerfelButton.Text = "Würfeln";
      this.wuerfelButton.Click += new System.EventHandler(this.Button1Click);
      // 
      // MainForm
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.ClientSize = new System.Drawing.Size(336158);
      this.Controls.Add(this.wuerfelButton);
      this.Controls.Add(this.ergebnisLabel);
      this.Controls.Add(this.pictureBox);
      this.Name = "MainForm";
      this.Text = "MainForm";
      this.ResumeLayout(false);
    }
    #endregion
    void Label1Click(object sender, System.EventArgs e)
    {
      
    }
    
    void Label2Click(object sender, System.EventArgs e)
    {
      
    }
    
    public void Button1Click(object sender, System.EventArgs e)
    {
      
      
  
    
    }
      
  
  // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  
  protected override void OnPaint(PaintEventArgs e) {
      Graphics g = e.Graphics;
      SolidBrush solidBrush = new SolidBrush(Color.FromArgb(1502550125));
      
      int zahl;
      Random r = new Random();
      zahl = r.Next(1,6);
      
        
  if(zahl=1){
        g.FillEllipse(solidBrush, 60608080); 
      }
      if(zahl==2){
        g.FillEllipse(solidBrush, 1002012040); 
        g.FillEllipse(solidBrush, 2010040120);
      }
      if(zahl==3){
        g.FillEllipse(solidBrush, 1002012040);
        g.FillEllipse(solidBrush, 60608080);
        g.FillEllipse(solidBrush, 2010040120);
      }
      if(zahl==4){
        g.FillEllipse(solidBrush, 20204040);
        g.FillEllipse(solidBrush, 1002012040);
        g.FillEllipse(solidBrush, 2010040120);
        g.FillEllipse(solidBrush, 100100120120); 
      }
      if(zahl==5){
        g.FillEllipse(solidBrush, 20204040); 
        g.FillEllipse(solidBrush, 1002012040);
        g.FillEllipse(solidBrush, 2010040120);
        g.FillEllipse(solidBrush, 100100120120); 
        g.FillEllipse(solidBrush, 2010040120);
      }
      if(zahl==6){
        g.FillEllipse(solidBrush, 20204040); 
        g.FillEllipse(solidBrush, 60208040);
        g.FillEllipse(solidBrush, 1002012040);
        g.FillEllipse(solidBrush, 2010040120); 
        g.FillEllipse(solidBrush, 6010080120);
        g.FillEllipse(solidBrush, 100100120120); 
      }
  
  }


      
    }
    
}
Robert_G
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 416


Delphi32 (D2005 PE); Chrome/C# (VS2003 E/A, VS2005)
BeitragVerfasst: Do 20.10.05 01:57 
Ok...
Was war falsch?
Du hast die Zahl beim Zeichnen berechnet. Das heißt beim ersten darstellen des Fensters.
Außerdem hast du OnPaint des Fensters überschrieben, anstatt einfach der pictureBox(PB) einen PaintHandler im Form designer zu verpassen. Somit lief dein Code für das Fenster, nicht für die PB.
Das hier lag in der überschrieben OnPaint:
ausblenden C#-Quelltext
1:
2:
3:
int zahl;
Random r = new Random();
zahl = r.Next(1,6);


aus der lokalen Variable zahl machen wir ein Feld des Forms[meta]einfach außerhalb der Methode, aber innerhalb der Formklasse ziehen[/meta].
Damit wir nur dann zeichnen müssen, wenn sich etwas ändert, und damit wir das nicht jedesmal prüfen müssen, verpacken wir zahl in eine Property namens Zahl:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
int zahl;

public int Zahl
{
  get { return zahl; }
  set
  {
    int alterWert = zahl;
    zahl = value;

    if (alterWert != zahl)
    {
      ergebnisLabel.Text := tahl.ToString();

      // Invalidate sagt der pictureBox, sie solle sich bitte neuzeichen. ;)
      pictureBox.Invalidate();
    }
  }
}


Du hast in deinem Form einen leeren Handler[meta]Button1Click[/meta], der auf das Click des Buttons lauscht.
Darin kannst du die Zufallszahl besetzen:
ausblenden C#-Quelltext
1:
2:
3:
Random random = new Random();
// einfach der Property zuweisen, den Rest erledigt der setter
Zahl = random.Next(16);


Du solltest dir nun einen PaintHandler für die PB anlegen[meta]im Form designer[/meta].

Nachdem du nun die Variable zahl und den Zufallsgenerator aus OnPaint entfernt hast, kannst du den gesmten Inhalt dieser Methode ausschneiden und in deinen neuen PaintHandler für die PB packen.

Kleiner Patzer noch:
if(zahl=1) hätte if(zahl == 1) heißen sollen. ;)

Die leere OnPaint kannst du getrost entfernen, du hast ja jetzt den Code in pictureBox_Paint...
Deine Ellipsen zeichnest du noch falsch, aber das bekommst du sicher alleine hin, schließlich siehst du sie nun auch. :lupe:

BTW: Wenn du nochmal einfach deinen gesamten Code hier reinschluderst, habe ich ganz sicher keine Lust zu antworten.
Dass andere dann auch keine Lust haben siehst du an deinen "vielen" Antworten. Einfach die Code schnipsel, die Probleme bereiten rein packen und jeweils etwas dazu schreiben. Wenn du dir keine Mühe gibst, geben sich sicherlich andere keine Mühe für dich. ;)