0

Okay, so I have a pretty basic form. I'm having quite a bit of trouble though, trying to create an OO program keeping my design etc separate. In other words, having a utility class or something like that. Basically I'm unsure if I should only put my calculations there, or also the event handling(like if something was enabled). I have some code below that shows my troubles calling my method. Any help is appreciated, I have a long way to go to finish this.

    namespace FuzzyDiceCompany
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

/// <summary>
/// TODO: Update summary.
/// </summary>
public class Events
{
    public void RedCheckBoxEvent()
    {
        RedCheckBox.Enabled = true;
    }
}

}

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 FuzzyDiceCompany
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        Events redEvent = new Events();
    }

    private void RedCheckBox_CheckedChanged(object sender, EventArgs e)
    {
        redEvent.RedCheckBoxEvent();
    }
}

}

2
Contributors
4
Replies
7
Views
5 Years
Discussion Span
Last Post by kiail
0

The redEvent.RedCheckBoxEvent() doesn't work, how can I get it to work and is this good OOP to use different class for these events and my totals?

0

It sulely cant work this way, your class reference is not accessable. You created and instantiated new class refercne in Form1 constructor. You must define it on a class level, so it can be accessed in your RedCheckBox_CheckedChanged event, like:

Events redEvent; //define class on a class level!
public Form1()
{
    InitializeComponent();
    redEvent = new Events();
}

private void RedCheckBox_CheckedChanged(object sender, EventArgs e)
{
    redEvent.RedCheckBoxEvent();
}

Hope it helps,
bye

0

sadly no, it didn't. I still can't enable the numeric up/down box

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 FuzzyDiceCompany
{


/// <summary>
/// TODO: Update summary.
/// </summary>
public class Events
{
    Form1 RedNumericUpDown;
    Form1 RedCheckBox;

    public void RedCheckBoxEvent()
    {
        RedNumericUpDown = new Form1();
        RedCheckBox = new Form1();

        if (RedCheckBox.Enabled == true)
        {

            RedNumericUpDown.Enabled = true;
        }
        else
        {
            RedNumericUpDown.Enabled = false;
        }
    }
}
}


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 FuzzyDiceCompany
{
public partial class Form1 : Form
{
    Events redEvent;

    public Form1()
    {
        InitializeComponent();
        redEvent= new Events();
    }

    private void RedCheckBox_CheckedChanged(object sender, EventArgs e)
    {
        redEvent.RedCheckBoxEvent();
    }
}

}

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.