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();
    }
}

}

Recommended Answers

All 4 Replies

Yes and your exact question would be?
Show us some example code, with the calculations, I mean.

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?

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

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();
    }
}

}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.