|
||
|
|
#1 (permalink) | |
|
Forum Expert
|
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;
}
}
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.");
}
However, when I compile it I get the following error... Quote:
Any one have any suggests as to what I am missing? -Ravon
__________________
|
|
|
|
|
|
|
#2 (permalink) |
|
Forum Expert
|
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; 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!!! |
|
|
|
|
|
#4 (permalink) |
|
Newbie
Join Date: Jun 2006
Posts: 95
|
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 |
|
|
|
|
|
#5 (permalink) |
|
Forum Expert
|
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");
}
}
}
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);
}
}
}
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; }
}
}
}
-Ravon
__________________
|
|
|
|
|
|
#6 (permalink) |
|
Forum Expert
|
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);
}
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 |
|
|
|
|
|
#7 (permalink) | |
|
Forum Expert
|
Quote:
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; }
}
}
GlobalParams.TestValue="My World"; Thanks for the help everyone. -Ravon
__________________
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|