Click here to Skip to main content
14,737,711 members
Home » Discussions » C#
   

C#

 
GeneralRe: Looking for a book on C# forms Pin
trønderen26-Aug-20 2:11
Membertrønderen26-Aug-20 2:11 
GeneralRe: Looking for a book on C# forms Pin
OriginalGriff26-Aug-20 2:16
mveOriginalGriff26-Aug-20 2:16 
GeneralRe: Looking for a book on C# forms Pin
trønderen26-Aug-20 6:00
Membertrønderen26-Aug-20 6:00 
AnswerRe: Looking for a book on C# forms Pin
trønderen26-Aug-20 1:38
Membertrønderen26-Aug-20 1:38 
AnswerRe: Looking for a book on C# forms Pin
CHill6026-Aug-20 2:24
mveCHill6026-Aug-20 2:24 
AnswerRe: Looking for a book on C# forms Pin
Ron Nicholson26-Aug-20 3:24
professionalRon Nicholson26-Aug-20 3:24 
AnswerRe: Looking for a book on C# forms Pin
Gerry Schmitz26-Aug-20 8:16
mveGerry Schmitz26-Aug-20 8:16 
QuestionTrying to get my block program working Pin
Brian_TheLion23-Aug-20 17:56
MemberBrian_TheLion23-Aug-20 17: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 18:18
mveGerry Schmitz23-Aug-20 18:18 
QuestionHow to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 22:43
MemberExoskeletor22-Aug-20 22:43 
AnswerRe: How to calculate in c# the possibility of this game Pin
OriginalGriff22-Aug-20 22:47
mveOriginalGriff22-Aug-20 22:47 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 22:51
MemberExoskeletor22-Aug-20 22:51 
GeneralRe: How to calculate in c# the possibility of this game Pin
OriginalGriff22-Aug-20 23:01
mveOriginalGriff22-Aug-20 23:01 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 23:04
MemberExoskeletor22-Aug-20 23:04 
GeneralRe: How to calculate in c# the possibility of this game Pin
OriginalGriff22-Aug-20 23:13
mveOriginalGriff22-Aug-20 23:13 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 23:31
MemberExoskeletor22-Aug-20 23:31 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 23:32
MemberExoskeletor22-Aug-20 23:32 
GeneralRe: How to calculate in c# the possibility of this game Pin
OriginalGriff22-Aug-20 23:33
mveOriginalGriff22-Aug-20 23:33 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 23:37
MemberExoskeletor22-Aug-20 23:37 
GeneralRe: How to calculate in c# the possibility of this game Pin
OriginalGriff22-Aug-20 23:43
mveOriginalGriff22-Aug-20 23:43 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor22-Aug-20 23:57
MemberExoskeletor22-Aug-20 23:57 
GeneralRe: How to calculate in c# the possibility of this game Pin
OriginalGriff23-Aug-20 0:05
mveOriginalGriff23-Aug-20 0:05 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor23-Aug-20 0:28
MemberExoskeletor23-Aug-20 0:28 
GeneralRe: How to calculate in c# the possibility of this game Pin
Luc Pattyn23-Aug-20 13:51
sitebuilderLuc Pattyn23-Aug-20 13:51 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor23-Aug-20 14:01
MemberExoskeletor23-Aug-20 14: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.