Go Back   RunUO - Ultima Online Emulation > Developer's Corner > Programming > C#

C# C# Discussion

Reply
 
Thread Tools Display Modes
Old 09-21-2007, 08:43 AM   #1 (permalink)
Forum Expert
 
RavonTUS's Avatar
 
Join Date: Aug 2004
Location: in a house.
Age: 39
Posts: 582
Send a message via ICQ to RavonTUS Send a message via AIM to RavonTUS
Default Sending data between Windows Forms

Greetings,

I have two tabs open in Visual C# Express. The first is my Forms1.cs and it has my form with several "CheckBox"'s in it. The second tabs has my "code" in it.

In my form I have the following and it works...
Code:
        private void checkBoxMDF_CheckedChanged(object sender, EventArgs e)
        {
            MessageBox.Show("For a small fee, we will add this feature to the program.  :) ");
            if (checkBoxMDF.Checked)
            {
                checkBoxMDF.Checked = true;
            }
            else
            {
                checkBoxMDF.Checked = false;
            }
        }
It checks to see if the box is checked or unchecked and changes accordingly.

In my "code" tab, the code looks like this...
Code:
        if (!Form1.checkBoxMDF.Checked)
        {
            MessageBox.Show("The box in Form1 is Checked.");
        }
        else
        {
            MessageBox.Show("The box in Form1 is NOT Checked.");
        }
It again looks for the check in the box.

However, when I compile it I get the following error...
Quote:
'WindowsApplication1.Form1.checkBoxMDF' is inaccessible due to its protection level"
I have to believe this is something simple that I am missing, however I have spent the night pulling my hair out.

Any one have any suggests as to what I am missing?

-Ravon
__________________

Will RunUO work on Linux? Yes
RavonTUS is offline   Reply With Quote
Old 09-21-2007, 09:35 AM   #2 (permalink)
Forum Expert
 
Kenny164's Avatar
 
Join Date: Sep 2004
Location: Ballymena, Northern Ireland
Age: 23
Posts: 464
Send a message via MSN to Kenny164
Default

Did you try setting the control to public (generated code)?

Heres a wee sample from one of my forms listbox:

Code:
private System.Windows.Forms.ListBox listBox1;
Change it to:

Code:
public System.Windows.Forms.ListBox listBox1;
__________________
Use the middle mouse button on Here for forum rules, if nothing happens get firefox and try again!!!
Kenny164 is offline   Reply With Quote
Old 09-21-2007, 01:08 PM   #3 (permalink)
Forum Expert
 
RavonTUS's Avatar
 
Join Date: Aug 2004
Location: in a house.
Age: 39
Posts: 582
Send a message via ICQ to RavonTUS Send a message via AIM to RavonTUS
Default

Quote:
Originally Posted by Kenny164 View Post
Did you try setting the control to public (generated code)?
Yes, that's what I thought too. However, it did not seem to make a difference.

-Ravon
__________________

Will RunUO work on Linux? Yes
RavonTUS is offline   Reply With Quote
Old 09-21-2007, 01:22 PM   #4 (permalink)
Newbie
 
Join Date: Jun 2006
Posts: 95
Default

Your angle is wrong.

That event is triggered, After they checked/unchecked it.

So your code depends on what you want to do. The events you have to work with are "Checked" and "Unchecked". At the point of those events, the property IsChecked has already been set appropriately through the KeyDown/KeyUp and MouseDown/MouseUp or Click events.

If you wanted to prevent (actually reverse) it from being checked, then do this:
Code:
checkBoxMDF.IsChecked = !checkBoxMDF.IsChecked;
__________________
Record for the sentence that makes the least sense - Go HERE
Kamron is offline   Reply With Quote
Old 09-24-2007, 09:08 AM   #5 (permalink)
Forum Expert
 
RavonTUS's Avatar
 
Join Date: Aug 2004
Location: in a house.
Age: 39
Posts: 582
Send a message via ICQ to RavonTUS Send a message via AIM to RavonTUS
Default

Greetings,

Maybe I should give a better example. I when back to the basics and still can't figure out what I am doing wrong.

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

namespace Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            myCheckBox form1checkbox;
            form1checkbox = new myCheckBox();
          
            if (checkBox1.Checked)
            {
                checkBox1.Checked = true;
                form1checkbox.myCheckBoxStatus = "True";
            }
            else
            {
                checkBox1.Checked = false;
                form1checkbox.myCheckBoxStatus = "True";
            }

        }

        public void button1_Click(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
                MessageBox.Show("Checked");
            else
                MessageBox.Show("UnChecked");

        }
    }
}
Form2.cs
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Test
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        public void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show(form1checkbox.myCheckBoxStatus);
        }
    }
}
myCheckBox.cs
Code:
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
    class myCheckBox
    {
        private string _myCheckBoxStatus;

        public string myCheckBoxStatus
        {
            get { return _myCheckBoxStatus; }
            set { _myCheckBoxStatus = value; }
        }

    }
}
I simply want to click the box in Form 2 and have it check Form 1's check box. How do I link them together?

-Ravon
__________________

Will RunUO work on Linux? Yes
RavonTUS is offline   Reply With Quote
Old 09-24-2007, 12:48 PM   #6 (permalink)
Forum Expert
 
Kenny164's Avatar
 
Join Date: Sep 2004
Location: Ballymena, Northern Ireland
Age: 23
Posts: 464
Send a message via MSN to Kenny164
Default

Heres a wee cheap hack way of doing it (I feel bad for even posting this, lol):

Your form2:
Code:
public void button1_Click(object sender, EventArgs e)
        {
            string s = "False";
            //s = Application.OpenForms["form1"].Controls["CheckBox1"].Text;
            Form1 frm = (Form1)Application.OpenForms["Form1"];
            if (frm.checkBox1.Checked)
                s = "True";

            MessageBox.Show(s);
        }
Here's a few other ways:
Passing Data Between Forms - The Code Project - C# Programming
__________________
Use the middle mouse button on Here for forum rules, if nothing happens get firefox and try again!!!

Last edited by Kenny164; 09-24-2007 at 12:49 PM. Reason: adding web link
Kenny164 is offline   Reply With Quote
Old 09-25-2007, 07:41 AM   #7 (permalink)
Forum Expert
 
RavonTUS's Avatar
 
Join Date: Aug 2004
Location: in a house.
Age: 39
Posts: 582
Send a message via ICQ to RavonTUS Send a message via AIM to RavonTUS
Default

Quote:
Originally Posted by Kenny164 View Post
Heres a wee cheap hack way of doing it (I feel bad for even posting this, lol):
Kenny, thank you that is what I was looking for.

The other piece I needed was this...

This variable can be accessed anywhere from the application.
Code:
public class GlobalParam
{
    private static string strTestValue = "";

    public static string TestValue
    {
        get { return strTestValue; }
        set { strTestValue = value; }
    }
}
Now, you can get/set value to TestValue by using
GlobalParams.TestValue="My World";

Thanks for the help everyone.

-Ravon
__________________

Will RunUO work on Linux? Yes
RavonTUS is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5