Thx for samples. I tryed something little different but in line with your
example. I passed the object to the dialog constructor directly. I am still
kinda confused why I really need to do that if I made the object "public' in
the first place. I am wondering if I truely understand what public really
means.
If I have a name space of lets say "MyTestProject" and all the objects
(class, emulation ect) I create are inside of it. Those that are public can
be seen from all of those objects .... right?
Thx,
//////////////////////////////////////////////////////////////////
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public config myConfig = new config();--->Why can I not see this
outside of this form since it is public?
private void button1_Click(object sender, EventArgs e)
{
dialog MyDialog = new dialog(myConfig);
if(MyDialog.ShowDialog() == DialogResult.OK)
{
button2.Visible=true;
}
}
public partial class dialog : Form
{
private config myConfigs;
public dialog(config myConfigs)
{
InitializeComponent();
this.myConfigs = myConfigs;
}
private void button1_Click(object sender, EventArgs e)
{
myConfigs.name="testit";
}
}
////////////////////////////////////////////////////////////
public partial class dialog : Form
{
private config myConfigs;
public dialog(config myConfigs)
{
InitializeComponent();
this.myConfigs = myConfigs;
}
private void button1_Click(object sender, EventArgs e)
{
myConfigs.name="testit";
}
}
/////////////////////////////////////////////////////////////////
"Mark R. Dawson" <Ma*********@discussions.microsoft.comwrote in message
news:31**********************************@microsof t.com...
The problem you are having is that the MyObject instance, EditMe, is
defined
inside the Frame1 class and you are trying to refer to that instance from
the
dialog class, but you have no reference to that instance, by declarig the
EditMe instance it is NOT a global variable, you need to acquire a
reference
to it. So for example you need to expose it from inside the Frame1 class
(Since at the moment in your code it is declared private, so nothing
outside
of the class can see it) and then inside your SomeControlHandle method you
need to have a reference to an instance of the Frame1 class i.e.
class Frame1 : Frame
{
private MyObject editMe = new MyObject();
public MyObject Foo
{
get
{
return this.editMe;
}
}
}
class Dialog : Frame
{
private Frame1 frame;
//Need a reference to the Frame1 instance we want to use
public Dialog(Frame1 frame)
{
this.frame = frame;
}
public void ControlHandle()
{
this.frame.Foo.name = "bob";
}
}
//Then somewhere you are going to do;
void Bar()
{
Frame1 f = new Frame1();
Dialog d = new Dialog(f);
d.ControlHandle();
}
Hope that helps
Mark.
--
http://www.markdawson.org
http://themightycoder.spaces.live.com
"Muffin" wrote:
>It is really simple what I am try to do.
I create a class with a member variable
public class MyObject
{
public string name;
}
Them from within the main frame I create an instance of the object. Then
I
have a control that launches a dialog. From within that dialog I try to
update the object (EditMe.name)
class Frame1: frame
{
MyObject EditMe = new MyObject(); create instance when frame is launched
SomeEventHandle()
{
just create an instance of dialog class
}
SomeOtherControlHandle()
{
EditMe.name="ThisWorks" ---I can do this with no problem
}
class dialog: frame
{
SomeControlHandle()
{
EditMe.name="test";--->I can not edit this
}
}
I do not understand why I can not see EditMe from within an instance of
dialog or another class for that matter.
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP************************@msnews.microsoft. com...
Muffin <mu****@NoEmail.localwrote:
I am a little new to C# and an have a hard time understanding why I
get a
nonstatic error. I create an object in my main form that has member
properties by using a control. From another form/dialog I try to
access
that
object to set a property. I get a non static error. I can change my
object
to static, which works fine. Static objects are acting as I expect.
Non
static objects are not. I do not understand why this is happening. I
have
made it public and am in the same name space for my project. It seem
that
I
can only use an object in the same class that I created it in. In
this
case
I created my object in my main form class and can access easly from
any
control in that class and set any property, however if I try to access
this
object from another form/dialog class I recieve a non static error.
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
Bear in mind that there's no such thing as a "static object" or "non-
static object" - but if you try to access an instance *variable* from
within a static method, you'll need to specify which instance you're
talking about.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too