Elevated Gaming Network
http://elevatedgaming.net/forums/

Small but learning...
http://elevatedgaming.net/forums/viewtopic.php?f=13&t=23715
Page 1 of 3

Author:  Geeza [ Tue Jan 10, 2017 11:52 am ]
Post subject:  Small but learning...

hey i wanted to share what I've been doing in college today!

This is my second year in Level 3 IT and it's going pretty well.


At the minute in Programming, we are currently doing Object Oriented Programming, yeah.

We have been practicing nd stuff on Windows Form Applications and have been producing some small things.


Last year we were doing Procedural Programming, we were using Console Applications for that.


Today we did some excersises and had to do one task on our own, which was create 3 buttons using code (without using tool box to draw it) using the Button code and assigning a variable which is basically the name of the button, example:

Button EgNForums; <- This just means when the variable EgNForums is used, it refers to a button as I believe.
public Form1();

to create a button with the name EgNForums, all you have to do is:

EgNForums = new Button();

Baring in mind this is very easy stuff.

here is the full project:

Code:
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace WindowsFormsApplication9

{

      public partial class Form1 : Form

     {

                Button noLady;

                Button Lady;

                Button noLady1;

      public Form1()

      {

                InitializeComponent();

                noLady = new Button();

                Controls.Add(noLady);

                noLady.Text = "Find the Lady";

                noLady.Left = 70;

                noLady.Top = 50;

                noLady.Width = 100;

                noLady.Height = 40;

                noLady.Click +=new EventHandler(noLadyAction);

                Lady = new Button();

                Controls.Add(Lady);

                Lady.Text = "Find the Lady";

                Lady.Left = 120;

                Lady.Top = 100;

                Lady.Width = 100;

                Lady.Height = 40;

                Lady.Click +=new EventHandler(LadyAction);

                noLady1 = new Button();

                Controls.Add(noLady1);

                noLady1.Text = "Find the Lady";

                noLady1.Left = 200;

                noLady1.Top = 350;

                noLady1.Width = 100;

                noLady1.Height = 40;

                noLady1.Click +=new EventHandler(noLady1Action);

      }

      private void noLadyAction(object sender, EventArgs e)

      {

                MessageBox.Show("This is not the lady, please try again");

      }

      private void LadyAction(object sender, EventArgs e)

      {

               MessageBox.Show("You found the Lady, well done");

      }

      private void noLady1Action(object sender, EventArgs e)

      {

               MessageBox.Show("This is not the lady. please try again");

      }

  }

}




The problem is, when you click one of the buttons and it displays you found the lady, it doesnt randomize, it is the same button each time and I want to work on randomizing it making it change buttons each time it is debugged or ran.

By the way this is using C#, I use Visual Studio.

NO HARSH COMMENTS OK!

Author:  CharlieKelly [ Tue Jan 10, 2017 12:08 pm ]
Post subject:  Re: Small but learning...

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication9 {

public partial class Form1 : Form {

   Button noLady;
   Button Lady;
   Button noLady1;

   public Form1() {
         InitializeComponent();

         noLady = new Button();
         Controls.Add(noLady);

         noLady.Text = "Find the Lady";
         noLady.Left = 70;
         noLady.Top = 50;
         noLady.Width = 100;
         noLady.Height = 40;

         noLady.Click +=new EventHandler(noLadyAction);

         Lady = new Button();
         Controls.Add(Lady);

         Lady.Text = "Find the Lady";
         Lady.Left = 120;
         Lady.Top = 100;
         Lady.Width = 100;
         Lady.Height = 40;
         Lady.Click +=new EventHandler(LadyAction);

         noLady1 = new Button();
         Controls.Add(noLady1);

         noLady1.Text = "Find the Lady";
         noLady1.Left = 200;
         noLady1.Top = 350;
         noLady1.Width = 100;
         noLady1.Height = 40;
         noLady1.Click +=new EventHandler(noLady1Action);

      }

      private void noLadyAction(object sender, EventArgs e) {         
         MessageBox.Show(generateRandomText());
      }

      private void LadyAction(object sender, EventArgs e) {
         MessageBox.Show(generateRandomText());
      }

      private void noLady1Action(object sender, EventArgs e) {
         MessageBox.Show(generateRandomText());
      }
      
      private string generateRandomText() {
         int randomNumber = new Random().Next(1, 3);
         
         switch (randomNumber() {
            case 1:
               return "Random lady one";
               break;
               case 2:
               return "Random lady two";
               break;
               case 3:
               return "Random lady three";
               break;
               default:
               return "Random lady default";
               break;
         }      
      }
   }

}

gg no re

Author:  Yiggles Moto [ Tue Jan 10, 2017 12:09 pm ]
Post subject:  Re: Small but learning...

From the looks of it and by what you're saying,

Last year you did some small C++ console apps (could've been C# too)

and now you're learning .NET Visual Studio with C#

I'm not sure if it's just how you pasted it in your [code] tag, but the formatting isn't all that great

Indentation and commenting your code is key to becoming a better developer. Especially when you want others to critique your work. If you ever need help I can show you some pointers but I (and I hope nobody else) will be doing your homework for you

edit: gg charlie

Author:  CharlieKelly [ Tue Jan 10, 2017 12:11 pm ]
Post subject:  Re: Small but learning...

Yiggles Moto wrote:
From the looks of it and by what you're saying,

Last year you did some small C++ console apps (could've been C# too)

and now you're learning .NET Visual Studio with C#

I'm not sure if it's just how you pasted it in your [code] tag, but the formatting isn't all that great

Indentation and commenting your code is key to becoming a better developer. Especially when you want others to critique your work. If you ever need help I can show you some pointers but I (and I hope nobody else) will be doing your homework for you

edit: gg charlie

Yea, Im just that bored at work.

Author:  Yiggles Moto [ Tue Jan 10, 2017 12:12 pm ]
Post subject:  Re: Small but learning...

@Geeza, take a look at Charlie's code. I hope that's how you have yours indented, etc in your actual code...

@Charlie, gg no re

Author:  CharlieKelly [ Tue Jan 10, 2017 12:13 pm ]
Post subject:  Re: Small but learning...

Yiggles Moto wrote:
, take a look at Charlie's code. I hope that's how you have yours indented, etc in your actual code...

, gg no re


Ya I was gonna quickly show the new function, but I just couldn't handle the crappy formatting, it was killing me inside.

also () {
}

>

()
{
}

ILL FITE YA IF YOU DISAGREE

Author:  Yiggles Moto [ Tue Jan 10, 2017 12:15 pm ]
Post subject:  Re: Small but learning...

CharlieKelly wrote:
Yiggles Moto wrote:
, take a look at Charlie's code. I hope that's how you have yours indented, etc in your actual code...

, gg no re


Ya I was gonna quickly show the new function, but I just couldn't handle the crappy formatting, it was killing me inside.

also () {
}

>

()
{
}

ILL FITE YA IF YOU DISAGREE


I have never used
Code:
function()
{
    //code
}


It just kills me to even look at it

Author:  Phillip [ Tue Jan 10, 2017 12:16 pm ]
Post subject:  Re: Small but learning...

Charlies is way neat :)

Author:  CharlieKelly [ Tue Jan 10, 2017 12:19 pm ]
Post subject:  Re: Small but learning...

YigglesMoto wrote:

I have never used
Code:
function()
{
    //code
}


It just kills me to even look at it

Yea I always like the first version... but looking at my codebase I've been using that way almost exclusively lmao, didn't even notice.
I think it just auto-formats like that in Visual Studio and I've been too lazy to change it.

Fuck it, as long as its consistent idgaf.

Author:  Yiggles Moto [ Tue Jan 10, 2017 12:21 pm ]
Post subject:  Re: Small but learning...

CharlieKelly wrote:
YigglesMoto wrote:

I have never used
Code:
function()
{
    //code
}


It just kills me to even look at it

Yea I always like the first version... but looking at my codebase I've been using that way almost exclusively lmao, didn't even notice.
I think it just auto-formats like that in Visual Studio and I've been too lazy to change it.

Fuck it, as long as its consistent idgaf.


Like this?
Image

Page 1 of 3 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/