|
You can do, yes - because VS with link all the stuff up for you and throw in a pile of code ready to rock and roll.
But ... it looks like a lot of code to a beginner (because it is) and it's remarkably easy to break it and have no idea where or how to fix it!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Any development environment do things for you. When I went from Pascal to C, ages ago, I was puzzled by the compiler automatically doing the linking for me. It throws in all sorts of library functions as well. In principle, there is little difference to modern IDEs.
I made a minimal GUI Hello World - not quite a one-liner, but not that far away:
using System.Windows;
namespace Hello {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
}
public void Terminate(object sender, RoutedEventArgs evtArg) {
Application.Current.Shutdown();
}
}
} Note that all I had to write myself was
public void Terminate(object sender, RoutedEventArgs evtArg) {
Application.Current.Shutdown();
}
- the rest was generated for me. Then comes the GUI elements:
<Window x:Class="Hello.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="Hello" Height="100" Width="120">
<StackPanel HorizontalAlignment="Left">
<TextBlock x:Name="textBlock" Text="Hello World"/>
<Button x:Name="button" Content="OK" Click="Terminate"/>
</StackPanel>
</Window> - again, a of it lot generated. All I had to write myself was:
<StackPanel HorizontalAlignment="Left">
<TextBlock x:Name="textBlock" Text="Hello World"/>
<Button x:Name="button" Content="OK" Click="Terminate"/>
</StackPanel>
(I did modify the generated window size and title as well, but those are cosmetics and not required for Hello World functionality).
So I had to write seven lines (when also counting the one with nothing but a closing brace) to create a GUI Hello World. It sure is more than
#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;
} But then, hitting F5 is far easier than invoking the C++ compiler from a CLI.
My experience is that to make novices/students fascinated and eager to learn, you must help them to rapidly build something that has a resemblance to what they are used to see on the screen. At least 19 out of 20 have never ever realated to a CLI interface, but 20 out of 20 have seen windows, buttons, text fields etc. Console output does not give them a feeling of having taken the first step into making something "real". A GUI label and a clickable button, much more so.
|
|
|
|
|
Is Windows Forms a requirement? A major part of C# GUI programming today is done with WPF, Windows Presentation Foundation. You can easily fill a shelf with books on WPF. (Some of them unforunately spends a lot of words explaining how WPF differs from Forms, more or less assuming that you already know Forms!)
|
|
|
|
|
trønderen (@Member-8575121) said
Quote: Is Windows Forms a requirement? A major part of C# GUI programming today is done with WPF, Windows Presentation Foundation. If you do go down the WPF route have a look at "WPF 4.5 Unleashed" by Adam Nathan (Pearson ISBN 978-93-325-3603-6). I'm finding it quite digestible.
I've also used Charles Petzold's "Programming Microsoft Windows with C#" (Microsoft ISBN 0-7356-1370-2 - although I have a very old copy)
Some these books come in at a hefty price so also have a look at InformIT: The Trusted Technology Source for IT Pros and Developers[^]. I haven't used it in years but I had a colleague who swore by it.
|
|
|
|
|
I did a search on Amazon, under books. Amazon Book Search[^]. There appear to be quite a few. Some were older, but even those should get you started.
There are a few author's that I've found to be good, mostly the top names, like Charles Petzold[^] and I've had several Murach's[^] and liked them very much. The linked Murach's work might be a good starter, it is 2015 but thats not terribly old.
I'm sure digging through the links and reviews will find you something useful.
Jack of all trades, master of none, though often times better than master of one.
|
|
|
|
|
|
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();
}
}
}
'''
|
|
|
|
|
Somewhere in the designer you said you wanted to handle the "form load event", but you're missing the "handler."
How to: Create Event Handlers Using the Designer | Microsoft Docs
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Im trying to create an app to calculate the posibilities of a game.
In the game every time we play, from 80 numbers only 20 of them are randomly selected and from the 80 numbers i can select maximum 12 of them that they might win.
I want to calculate the posibility to have select the winning x numbers from my selected numbers. (I mean if i have selected 10 numbers and the 7 of them win i want the percentage possibility for that.)
I know that the type to check that is: Ρ(y,x) = (y per x)*(80-y per 20-x)/ (80 per 20) where y are the numbers i have selected to play and x are the numbers that won. How i can convert that to c#?
thanks
|
|
|
|
|
What have you tried?
Where are you stuck?
What help do you need?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I dont know how to convert this equation into c#. i cant understand this per in the type Ρ(y,x) = (y per x)*(80-y per 20-x)/ (80 per 20) is. what per means.
I havent try anything since i cant udnerstand it. i already said where i am stuck and what help i need
|
|
|
|
|
Well, where did you get the equation from? They will probably define y per x for you. Did you look?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
No, that's a mess of pixels with no meaning to anybody...
And as for the Greek, either look for an English language description or use Google Translate.
Did you try Wikipedia: Hypergeometric distribution - Wikipedia[^] ?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Yes i tried all that, here is exactly what i want Kino Statistics Mathematical Analysis[^]
I want this equation in c#. i show online some c# codes for Hypergeometric distribution but they dont give probability and are very complex
|
|
|
|
|
I think i have managed to convert it to a simpler equation: what i want is this to c# now:
(n!/(k!*(n-k)!)*(80-n)!/((20-k)!*((80-n)-(20-k))!))/(80!/(20!*(80-20)!))
|
|
|
|
|
So what's the problem? that link leads you through the process of getting a probability from the inputs, so what have you tried to implement it?
Where are you stuck?
What help do you need? (Other than "somebody else to do all the work for me" which isn't the idea of this site at all.)
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I think i was pretty clear to what i want. I dont know how a equation is being translated to c#. If this to you is translated "to someone else do the work for me" then i cant do anyhting about that, just skip this topin, you dont HAVE to answer something. asking the same question again and again how it helps?
|
|
|
|
|
Yeah, it's pretty clear: you want someone else to do the work for you.
I'm trying to avoid the derision that can attract to you by getting you to think about your task and actually try to do the work yourself, or at least try. But so far, you've shown no sign at all of trying to implement anything yourself!
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you. Plus, if we just "hand you the solution" you don't learn anything useful from that, and the next time you have to do a similar task you have to ask again, and again, and again ... people learn by doing, not by looking at results!
So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
we dont have to do this converstation. i dont want you to solve anything for me or toexplain what solving for me means.
Lets take it from the beginning
Facts: nobody wants to do the work for the other
Problem: how to convert equation to c#
With those facts in this problem where someone starts? as i pointed already in a previous post i try to convert this equation to maths (n!/(k!*(n-k)!)*(80-n)!/((20-k)!*((80-n)-(20-k))!))/(80!/(20!*(80-20)!))
and you said it is pretty clear i want you to do the work for me.. you are obvious wrong but lets not discuss that either if you still want to think im trying to find someone to do my the job.. great. (you should REALLY check what you think is pretty clear since you are posting very often here, my messages didnt at all show what you are saying, i have share many and many informations)
Now to the point: i used this tool (as i methioned already in the previous posts) Converting math equations to C#[^] and it has create some Factorial() procedures, c# cant recognise them, those exist in a library or something
|
|
|
|
|
That's because C# doesn't contain a factorial function - but it's trivial to create one yourself, it's one of the first exercise beginners are often given. Recursive or iterative, it's simple either way:
private static int FactorialRecursive(int x)
{
return (x > 1 ? x * FactorialRecursive(x - 1) : 1);
}
private static int FactorialIterative(int x)
{
int f = 1;
while (x > 1)
{
f *= x--;
}
return f;
}
So why couldn't you just write those? Or google for them?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Because maybe im missing something and this function exists. I dont prefer always solving anything by my own because im not sure if it the best approach. Thanks, i think ive got it from here.
I will post again here only if i have code to post since i see that if i dont have code people here believe that i intentionally dont have code and i dont those negative situations.
Thanks
|
|
|
|
|
I'm curious what your code will look like; you are in for a couple of surprises when you discover the difference between theory and practice...
Luc Pattyn [My Articles]
If you can't find it on YouTube try TikTok...
|
|
|
|
|
Right now im at this:
private int CalculateProbabilityOfDrawNumbersFromAllNumbers(int drawNumbers, int allNumbers)
{
return ((Factorial(allNumbers) * Factorial(80 - allNumbers)) / (((Factorial(80) * ((Factorial(drawNumbers) * Factorial(allNumbers - drawNumbers)) * (Factorial(20 - drawNumbers) * Factorial(((80 - allNumbers) - (20 - drawNumbers)))))) / (Factorial(20) * Factorial(80 - 20)))));
}
private static int Factorial(int x)
{
int f = 1;
while (x > 1)
{
f *= x--;
}
return f;
}
which gives division by zero and i try to understand if something have gone wrong with all those parenthesis
|
|
|
|
|
investigate and learn!
Luc Pattyn [My Articles]
If you can't find it on YouTube try TikTok...
|
|
|
|