Newbee - Form Laod 
Author Message
 Newbee - Form Laod

I am trying to learn C#
In VS.net I open a new project - a Windows Application.
I get a form called Form1
In the form's load event I would like to specify the form's height and
width.
I use the code:
private void Form1_Load(object sender, System.EventArgs e)

{

    Form1.ActiveForm.Width = 700;

    Form1.ActiveForm.Height = 700;

Quote:
}

I get a run time error:  "Object reference not set to an instance of the
object"  Isn't Form1 an instance of a windows form ?  What concept am I
missing ?

Suggestions along with sample code for a load event would be appreciated.

Thanks,

Jim

ps:  what does the "e" in  (object sender, System.EventArgs e) stand for ?



Fri, 22 Apr 2005 08:56:43 GMT  
 Newbee - Form Laod
What you want to do is simply:

this.Width = 700;
this.Height = 700;

~~Bonnie


Quote:
> I am trying to learn C#
> In VS.net I open a new project - a Windows Application.
> I get a form called Form1
> In the form's load event I would like to specify the form's height and
> width.
> I use the code:
> private void Form1_Load(object sender, System.EventArgs e)

> {

>     Form1.ActiveForm.Width = 700;

>     Form1.ActiveForm.Height = 700;

> }

> I get a run time error:  "Object reference not set to an instance of the
> object"  Isn't Form1 an instance of a windows form ?  What concept am I
> missing ?

> Suggestions along with sample code for a load event would be appreciated.

> Thanks,

> Jim

> ps:  what does the "e" in  (object sender, System.EventArgs e) stand for ?



Fri, 22 Apr 2005 09:03:43 GMT  
 Newbee - Form Laod


Quote:
> I get a run time error:  "Object reference not set to an instance of the
> object"  Isn't Form1 an instance of a windows form ?  What concept am I
> missing ?

> Suggestions along with sample code for a load event would be appreciated.

Bonnie gave you the fix, but I wanted to address the concept that you are
"missing."

Form1 is *not* an instance of a Windows form. It's a derived class.  If you
wanted an instance of Form1, called "winobject," your code would be:

Form1 winobject  = new Form1();

Quote:
> ps:  what does the "e" in  (object sender, System.EventArgs e) stand for ?

It's just a variable of an EventArgs type  that someone decided was to be
used in VS. NET. You can use a different variable if you wish.

--
Michael




Sat, 23 Apr 2005 06:25:58 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How to laod an icon from icon file?

2. how to laod the Bluetooth Drivers?

3. Database - newbee

4. Help a Newbee !

5. Newbee Database

6. newbee database

7. newbee: Help with pulling EventLog from remote computer

8. Function syntax question. Newbee

9. Two newbee questions

10. Newbee question - Passing an HICON between processes on the same machine

11. Help for NewBee to C

12. Newbee to the COM ATL world!

 

 
Powered by phpBB® Forum Software