Click here to Skip to main content
15,881,559 members
Home / Discussions / C#
   

C#

 
GeneralRe: Looking for a book on C# forms Pin
trønderen26-Aug-20 1:11
trønderen26-Aug-20 1:11 
GeneralRe: Looking for a book on C# forms Pin
OriginalGriff26-Aug-20 1:16
mveOriginalGriff26-Aug-20 1:16 
GeneralRe: Looking for a book on C# forms Pin
trønderen26-Aug-20 5:00
trønderen26-Aug-20 5:00 
AnswerRe: Looking for a book on C# forms Pin
trønderen26-Aug-20 0:38
trønderen26-Aug-20 0:38 
AnswerRe: Looking for a book on C# forms Pin
CHill6026-Aug-20 1:24
mveCHill6026-Aug-20 1:24 
AnswerRe: Looking for a book on C# forms Pin
Ron Nicholson26-Aug-20 2:24
professionalRon Nicholson26-Aug-20 2:24 
AnswerRe: Looking for a book on C# forms Pin
Gerry Schmitz26-Aug-20 7:16
mveGerry Schmitz26-Aug-20 7:16 
QuestionTrying to get my block program working Pin
Brian_TheLion23-Aug-20 16:56
Brian_TheLion23-Aug-20 16:56 
I get this message when I try to run my c# block code program.
I'm hoping someone can suggest what I need to change or add to my prgram so it will work.

Error CS1061 'Form1' does not contain a definition for 'Form1_Load' and no accessible extension method 'Form1_Load' accepting a first argument of type 'Form1' could be found (are you missing a using directive or an assembly reference?)

TRIED TO FORMAT CODE USING ```

```
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BlockGame
{
public partial class Form1 : Form
{
private Rectangle Goal = new Rectangle(350, 600, 50, 50);
private Rectangle Player = new Rectangle(350, 0, 50, 50);
private Rectangle Enemy1 = new Rectangle(0, 150, 75, 75);
private Rectangle Enemy2 = new Rectangle(599, 350, 75, 75);
public Form1()
{
InitializeComponent();
this.MaximumSize = new Size(750, 750);
this.MinimumSize = new Size(750, 750);
}

private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawRectangle(Pens.Red, Goal);
e.Graphics.DrawRectangle(Pens.Blue, Player);
e.Graphics.DrawRectangle(Pens.Red, Enemy1);
e.Graphics.DrawRectangle(Pens.Red, Enemy2);
}

private void Form1_KeyDown(object sender, KeyEventArgs e)
{
int PlayerX = Player.Location.X;
int PlayerY = Player.Location.Y;

switch (e.KeyData)
{
case Keys.Up:
Player.Location = new Point(PlayerX += 0, PlayerY -= 20);
this.Refresh();
break;
}

}

//detect if any rectangles hit each other
public void HitDetect()
{
if (Player.IntersectsWith(Goal))
{
MessageBox.Show("You Win!");
}

int PlayerX = Player.Location.X;
int PlayerY = Player.Location.X;

if (Enemy1.IntersectsWith(Player))
{
Player.Location = new Point(PlayerX = 350, PlayerY = 0);
MessageBox.Show("You Lose!");
}

if (Enemy2.IntersectsWith(Player))
{
Player.Location = new Point(PlayerX = 350, PlayerY = 0);
MessageBox.Show("You Lose!");
}

}

//As when we were moving the player we need variables for the two enemies X and Y location
private void timer1_Tick(object sender, EventArgs e)
{
int EX1 = Enemy1.Location.X;
int EY1 = Enemy1.Location.Y;

if (Enemy1.Location.X > 600)
{
Enemy1.Location = new Point(EX1 = 0, EY1 = 150);
}
Enemy1.Location = new Point(EX1 += 30, EY1 += 0);
this.Refresh();

// To make the game hangler make the enemy go the other way

int EX2 = Enemy2.Location.X;
int EY2 = Enemy2.Location.Y;

if (Enemy2.Location.X < 0)
{
Enemy2.Location = new Point(EX2 = 599, EY2 = 350);
}

Enemy2.Location = new Point(EX2 -= 30, EY2 += 0);
this.Refresh();

// Put limits so player can't go outside the form

if (Player.Location.X > 650)
{
Player.Location = new Point(Player.X -= 20, Player.Y += 0);
}

if (Player.Location.X < 0)
{
Player.Location = new Point(Player.X -= 20, Player.Y += 0);
}

if (Player.Location.Y > 590)
{
Player.Location = new Point(Player.X -= 20, Player.Y += 0);
}

if (Player.Location.Y < 1)
{
Player.Location = new Point(Player.X += 0, Player.Y += 20);
}
HitDetect();

}
}

}

'''
AnswerRe: Trying to get my block program working Pin
Gerry Schmitz23-Aug-20 17:18
mveGerry Schmitz23-Aug-20 17:18 
QuestionHow to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 21:43
Exoskeletor22-Aug-20 21:43 
AnswerRe: How to calculate in c# the possibility of this game Pin
OriginalGriff22-Aug-20 21:47
mveOriginalGriff22-Aug-20 21:47 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 21:51
Exoskeletor22-Aug-20 21:51 
GeneralRe: How to calculate in c# the possibility of this game Pin
OriginalGriff22-Aug-20 22:01
mveOriginalGriff22-Aug-20 22:01 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 22:04
Exoskeletor22-Aug-20 22:04 
GeneralRe: How to calculate in c# the possibility of this game Pin
OriginalGriff22-Aug-20 22:13
mveOriginalGriff22-Aug-20 22:13 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 22:31
Exoskeletor22-Aug-20 22:31 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 22:32
Exoskeletor22-Aug-20 22:32 
GeneralRe: How to calculate in c# the possibility of this game Pin
OriginalGriff22-Aug-20 22:33
mveOriginalGriff22-Aug-20 22:33 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 22:37
Exoskeletor22-Aug-20 22:37 
GeneralRe: How to calculate in c# the possibility of this game Pin
OriginalGriff22-Aug-20 22:43
mveOriginalGriff22-Aug-20 22:43 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 22:57
Exoskeletor22-Aug-20 22:57 
GeneralRe: How to calculate in c# the possibility of this game Pin
OriginalGriff22-Aug-20 23:05
mveOriginalGriff22-Aug-20 23:05 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 23:28
Exoskeletor22-Aug-20 23:28 
GeneralRe: How to calculate in c# the possibility of this game Pin
Luc Pattyn23-Aug-20 12:51
sitebuilderLuc Pattyn23-Aug-20 12:51 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor23-Aug-20 13:01
Exoskeletor23-Aug-20 13:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.