Accessing Form Components from another class(namespace)
-
Hi all, I would like to know whether it is possible to access form components from a class which is in another namespace. If not why did they decide to develop C# like that? Many Thanks in advance Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
-
Hi all, I would like to know whether it is possible to access form components from a class which is in another namespace. If not why did they decide to develop C# like that? Many Thanks in advance Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
Programm3r wrote:
I would like to know whether it is possible to access form components from a class which is in another namespace
Yes.
Deja View - the feeling that you've seen this post before.
-
Programm3r wrote:
I would like to know whether it is possible to access form components from a class which is in another namespace
Yes.
Deja View - the feeling that you've seen this post before.
Thanks you for the reply Pete. Is it possible that you could perhaps give me an example or a link of which you may know where I can see such an occurance? Many thanks in advance Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
-
Thanks you for the reply Pete. Is it possible that you could perhaps give me an example or a link of which you may know where I can see such an occurance? Many thanks in advance Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
Hmmm.
namespace MyNamespace1
{
public partial class MyForm : Form
{
MyForm()
{
....
}
public string MyValue{ get ; set; }
}
}namespace MyNamespace2
{
public partial class MyForm2 : Form
{
private MyNamespace1.MyForm _form
public MyForm2()
{
_form = new MyNamespace1.MyForm();
_form.MyValue = "Weyhey.";
}}
}Deja View - the feeling that you've seen this post before.
-
Thanks you for the reply Pete. Is it possible that you could perhaps give me an example or a link of which you may know where I can see such an occurance? Many thanks in advance Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
Any time that you are accessing something from the base class library, you are accessing code that lives in another namespace. For an explicit example, create a console application and observe the default namespace assigned to your code. Now, add a call to
Console.WriteLine
and output some text. If you place your mouse pointer over the wordConsole
, you'll notice that it is a class defined in theSystem
namespace. Thus, you have just accessed a class defined in another namespace. I get the feeling, however, that this is not the question that you meant to ask. You may wish to try rephrasing so that your intended question is a bit more clear. Hope that helps. :)--Jesse
"... the internet's just a big porn library with some useful articles stuck in." - Rob Rodi
-
Hmmm.
namespace MyNamespace1
{
public partial class MyForm : Form
{
MyForm()
{
....
}
public string MyValue{ get ; set; }
}
}namespace MyNamespace2
{
public partial class MyForm2 : Form
{
private MyNamespace1.MyForm _form
public MyForm2()
{
_form = new MyNamespace1.MyForm();
_form.MyValue = "Weyhey.";
}}
}Deja View - the feeling that you've seen this post before.
Hmmm ... So The code below will create a new instance of the first form, right? Now wouldn't that throw away any data / text that would remain on the first form?
... private MyNamespace1.MyForm _form public MyForm2() { _form = new MyNamespace1.MyForm(); _form.MyValue = "Weyhey."; } ...
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
-
Hmmm ... So The code below will create a new instance of the first form, right? Now wouldn't that throw away any data / text that would remain on the first form?
... private MyNamespace1.MyForm _form public MyForm2() { _form = new MyNamespace1.MyForm(); _form.MyValue = "Weyhey."; } ...
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
I just showed you how to access a form in a different namespace. How you want to handle it is up to you.
Deja View - the feeling that you've seen this post before.
-
Hmmm ... So The code below will create a new instance of the first form, right? Now wouldn't that throw away any data / text that would remain on the first form?
... private MyNamespace1.MyForm _form public MyForm2() { _form = new MyNamespace1.MyForm(); _form.MyValue = "Weyhey."; } ...
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
Hi, every time you execute
new something()
you create something new. creating a Form is not the same as showing a Form; your new Form would be invisible until you do something to it, such as _form.Show(). creating or showing a Form does not alter any other Form. :)Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.