Hello, I trying to create WPF Application. Everything worked well before I tried to switch the project to .NET 5.0 . Then an error appears at startup: "Program does not contain a static 'Main' method suitable for an entry point”. I have VS 2019. I have the main method as the main window. I have three windows.
First:
using System.Windows;
namespace MathGame
{
public partial class Main : Window
{
public Main()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (scitani.IsChecked.HasValue && scitani.IsChecked.Value)
{
uroven lvl = new uroven();
lvl.Show();
this.Close();
}
else if (odcitani.IsChecked.HasValue && odcitani.IsChecked.Value)
{
uroven lvl = new uroven();
lvl.Show();
this.Close();
}
else if (nasobeni.IsChecked.HasValue && nasobeni.IsChecked.Value)
{
uroven lvl = new uroven();
lvl.Show();
this.Close();
}
else if (deleni.IsChecked.HasValue && deleni.IsChecked.Value)
{
uroven lvl = new uroven();
lvl.Show();
this.Close();
}
else
{
MessageBox.Show("Musíš zvolit, jednu z početních operací!");
}
}
}
}
Second:
using System.Windows;
namespace MathGame
{
public partial class uroven : Window
{
public uroven()
{
InitializeComponent();
}
private void start_Click(object sender, RoutedEventArgs e)
{
if (nizka.IsChecked.HasValue && nizka.IsChecked.Value)
{
hra game = new hra();
game.Show();
this.Close();
}
else if (vysoka.IsChecked.HasValue && vysoka.IsChecked.Value)
{
hra game = new hra();
game.Show();
this.Close();
}
else
{
MessageBox.Show("Musíš zvolit, jednu z úrovní!");
}
}
}
}
Third:
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Threading;
namespace MathGame
{
public partial class hra : Window
{
Stopwatch mt = new Stopwatch();
DispatcherTimer posunTimer = new DispatcherTimer();
decimal trvani = new decimal();
int suma = new int();
public hra()
{
InitializeComponent();
posunTimer.Tick += posunTimer_Tick;
posunTimer.Interval = TimeSpan.FromSeconds(1);
}
public void Window_Loaded(object sender, RoutedEventArgs e)
{
Main window1 = Application.Current.Windows.OfType<Main>().First();
var scitani = window1.scitani ;
var odcitani = window1.odcitani;
var nasobeni = window1.nasobeni;
vysledekhrac.Focus();
suma++;
pocetprikladu.Text = suma.ToString();
mt.Start();
timer.Value = 0;
posunTimer.Start();
Random prvni = new Random();
Random druhy = new Random();
int maxprvni = 10;
int maxdruhy = 10;
int prvnic = prvni.Next(1, maxprvni);
int druhyc = druhy.Next(2, maxdruhy);
if (scitani.IsChecked.HasValue && scitani.IsChecked.Value)
{
znamenko.Text = "-";
}
if (odcitani.IsChecked.HasValue && odcitani.IsChecked.Value)
{
znamenko.Text = "-";
}
if (nasobeni.IsChecked.HasValue && nasobeni.IsChecked.Value)
{
znamenko.Text = "*";
}
if (znamenko.Text=="+")
{
int total = (prvnic+druhyc);
prvnit.Text = prvnic.ToString();
druhyt.Text = druhyc.ToString();
vysledek.Text = total.ToString();
}
if (znamenko.Text == "-")
{
int total = (prvnic - druhyc);
prvnit.Text = prvnic.ToString();
druhyt.Text = druhyc.ToString();
vysledek.Text = total.ToString();
}
if (znamenko.Text == "*")
{
int total = (prvnic * druhyc);
prvnit.Text = prvnic.ToString();
druhyt.Text = druhyc.ToString();
vysledek.Text = total.ToString();
}
}
private void posunTimer_Tick(object sender, object e)
{
timer.Value += 1;
if (timer.Value >= timer.Maximum)
{
posunTimer.Stop();
hlaska.Text = "Špatně";
poch++;
suma++;
pocetchyb.Text = poch.ToString();
pocetprikladu.Text = suma.ToString();
timer.Value = 0;
posunTimer.Start();
Random prvni = new Random();
Random druhy = new Random();
int maxprvni = 10;
int maxdruhy = 10;
int prvnic = prvni.Next(1, maxprvni);
int druhyc = druhy.Next(2, maxdruhy);
if (znamenko.Text == "+")
{
int total = (prvnic + druhyc);
prvnit.Text = prvnic.ToString();
druhyt.Text = druhyc.ToString();
vysledek.Text = total.ToString();
}
if (znamenko.Text == "-")
{
int total = (prvnic - druhyc);
prvnit.Text = prvnic.ToString();
druhyt.Text = druhyc.ToString();
vysledek.Text = total.ToString();
}
if (znamenko.Text == "*")
{
int total = (prvnic * druhyc);
prvnit.Text = prvnic.ToString();
druhyt.Text = druhyc.ToString();
vysledek.Text = total.ToString();
}
vysledekhrac.Text = String.Empty;
if (poch == 4)
{
mt.Stop();
timer.Value = 0;
posunTimer.Stop();
MessageBox.Show("Konec hry! Čas vypršel. ");
TimeSpan trvani = TimeSpan.FromMilliseconds(mt.ElapsedMilliseconds);
MessageBox.Show("Tvůj čas je " + trvani.ToString("mm\\:ss\\.ff")+"\n" + "Počet příkladů:" + pocetprikladu.Text + "\n" + "Průměrný čas:" + trvani / suma);
if (!File.Exists(path))
{
StreamWriter str = File.CreateText(path);
str.WriteLine(trvani);
}
else if (File.Exists(path))
{
var str = new StreamWriter(path);
str.WriteLine(trvani);
}
this.Close();
}
}
}
private int poch;
private void kontrola_Click(object sender, RoutedEventArgs e)
{
timer.Value += 1;
posunTimer.Start();
if (vysledekhrac.Text == vysledek.Text )
{
posunTimer.Stop();
hlaska.Text = "Správně";
suma++;
pocetprikladu.Text = suma.ToString();
Random prvni = new Random();
Random druhy = new Random();
int maxprvni = 10;
int maxdruhy = 10;
int prvnic = prvni.Next(1, maxprvni);
int druhyc = druhy.Next(2, maxdruhy);
if (znamenko.Text == "+")
{
int total = (prvnic + druhyc);
prvnit.Text = prvnic.ToString();
druhyt.Text = druhyc.ToString();
vysledek.Text = total.ToString();
}
if (znamenko.Text == "-")
{
int total = (prvnic - druhyc);
prvnit.Text = prvnic.ToString();
druhyt.Text = druhyc.ToString();
vysledek.Text = total.ToString();
}
if (znamenko.Text == "*")
{
int total = (prvnic * druhyc);
prvnit.Text = prvnic.ToString();
druhyt.Text = druhyc.ToString();
vysledek.Text = total.ToString();
}
vysledekhrac.Text = String.Empty;
timer.Value = 0;
posunTimer.Start();
}
else
{
posunTimer.Stop();
hlaska.Text = "Špatně";
poch++;
suma++;
pocetchyb.Text = poch.ToString();
pocetprikladu.Text = suma.ToString();
Random prvni = new Random();
Random druhy = new Random();
int maxprvni = 10;
int maxdruhy = 10;
int prvnic = prvni.Next(1, maxprvni);
int druhyc = druhy.Next(2, maxdruhy);
if (znamenko.Text == "+")
{
int total = (prvnic + druhyc);
prvnit.Text = prvnic.ToString();
druhyt.Text = druhyc.ToString();
vysledek.Text = total.ToString();
}
if (znamenko.Text == "-")
{
int total = (prvnic - druhyc);
prvnit.Text = prvnic.ToString();
druhyt.Text = druhyc.ToString();
vysledek.Text = total.ToString();
}
if (znamenko.Text == "*")
{
int total = (prvnic * druhyc);
prvnit.Text = prvnic.ToString();
druhyt.Text = druhyc.ToString();
vysledek.Text = total.ToString();
}
vysledekhrac.Text = String.Empty;
timer.Value = 0;
posunTimer.Start();
if (poch == 4)
{
mt.Stop();
timer.Value = 0;
posunTimer.Stop();
MessageBox.Show("Konec hry!");
konec_Click(sender, e);
}
}
}
string path = @"C:\\Žebříček.txt";
private void konec_Click(object sender, RoutedEventArgs e)
{
timer.Value = 0;
posunTimer.Stop();
if (mt.IsRunning==true)
{
mt.Stop();
}
TimeSpan trvani = TimeSpan.FromMilliseconds(mt.ElapsedMilliseconds);
MessageBox.Show("Tvůj čas je "+ trvani.ToString("mm\\:ss\\.ff")+"\n"+ "Počet příkladů: " +pocetprikladu.Text+"\n"+"Průměrný čas: "+Math.Round(trvani.TotalSeconds/suma,4) + " sekund");
if (!File.Exists(path))
{
StreamWriter str = File.CreateText(path);
str.WriteLine(trvani);
}
else if (File.Exists(path))
{
var str = new StreamWriter(path);
str.WriteLine(trvani);
}
this.Close();
}
}
}
What I have tried:
I apologize for the combination of multiple languages. Perhaps it is visible even without xaml.
Thank you for advice.