Ok here is a sample that will illustrate:
public class MainClass : System.Windows.Forms.Form
{
private MyCustomControl myControl;
private Arraylist someVariable.
//add different stuff to the form, including myControl
}
Now, all the events related to "myControl", is ofcourse inside the
"MyCustomControl" class, such as Drag&Drop, onMouseDown...etc...
Now, lets say I do a drag & drop with regards to "MyCustomControl":
public class MyCustomControl : System.Windows.Forms.Control {
private void MyCustomControl _DragEnter(object sender,
System.Windows.Forms.DragEventArgs e) {
if (e.Data.GetDataPresent(DataFormats.Text)){
e.Effect=DragDropEffects.Move;
}
//ATTENTION HERE:
//here is the point where I'd like to access the variable "someVariable"
in the class "MainClass "
//Do something like:
//MainClass.someVariable.add(someObject);
// or: parentObject.someVariable.add(someObject);
}
}
If you look at the original post , and this one, does it clear up what I
want to acceive?
You could say that I'm trying to access a variable that is in the "parent"
object, or that I'm trying to access a variable that is in the class that
instantiated myCustomControl.
My idea was that the only way to do such a thing, would be to create
property or method in "myCustomControl" that receives a reference to the
object in the parent class I want to access.
Example:
public class MyCustomControl : System.Windows.Forms.Control {
private ref someVariable myVar;
public void setSomeVariable(ref someVariable s){
this.myVar=s;
}
private void MyCustomControl _DragEnter(object sender,
System.Windows.Forms.DragEventArgs e) {
if (e.Data.GetDataPresent(DataFormats.Text)){
e.Effect=DragDropEffects.Move;
}
//ATTENTION HERE:
myVar.add(SomeObject)
}
}
Christian H.
"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opr616lin6hntkfz@localhost...
Hi Christian,
Um, I may have misunderstood, but why do you need to know what your
myDrawControl contains? The myDrawControl should be able to handle
everything on it's own without relying on the owner.
If you can tell us in more detail what you are trying to accomplish we
might be able to come up with another way of doing it.
Happy coding!
Morten Wennevik [C# MVP]