Begginers question - accessing properties of another class
Hi,
I am using visual studio to create a C# application. I have designed a form with buttons, etc. The code that visual studio generates is similar to the following:
[code]
namespace WindowsApplication1
{
partial class Form1
{
//lots of stuff here
private System.Windows.Forms.Button btnStart;
private System.Windows.Forms.TextBox tbURL;
}
}
[/code]
In the main application, I have the following
[code]
namespace WindowsApplication1
{
public partial class Form1 : Form
{
//Here I can access the components directly, etc. tbTextBox.Text = whatever
}
}
class someclass
{
//Here i cannot access any of the form components
}
[/code]
I want to access the components from "someclass". I have tried making the components public in the code that visual studio generates, I have tried using: WindowsApplication1.Form1.whatever... nothing works. Any ideas?
NickPosted Apr 9, 2007, 4:19 AM
Scott LyslePosted Apr 9, 2007, 1:36 AM
I looked at your code; you are showing two Form1 classes defined in the same namespace with one inheriting from Form and the other from getWebQuery; the solution shows a single Form1 so this sort of looks like an attempt to inherit from two classes which you cannot do. Aside from the issue of two classes in the same namespace with the same name, getWebQuery sounds like a method call rather than a class. Is getWebQuery a class or a method?
Your reference folder is closed in the image so I can't see what it in it. Where exactly is getWebQuery and what is it (method or class)? I don't see anything in the solution but a single form class (form1) and no other other classes are defined outside of what appears in Form1. I can see the closing brace on the namespace so I assume that getWebQuery is not defined inside this file unless it is a method in one of the classes.
Lets look at this from a different angle; first, what are you trying to do with the two Form1 declarations shown in the Form1 class?
NickPosted Apr 8, 2007, 6:26 PM
Viktor VidmanPosted Apr 4, 2007, 5:11 PM
NickPosted Apr 4, 2007, 4:53 PM
Viktor VidmanPosted Apr 4, 2007, 4:47 PM
NickPosted Apr 4, 2007, 3:24 PM
Mahesh ChandPosted Apr 3, 2007, 10:12 AM
If you don't know how to use partial classes, search this site or go to C# Language section.