When I start the debug of my application, sometimes I get a System.NullReferenceException on the principal Form Load in this portion of code

tlbFixed.Width = frmSSDas.ActiveForm.Size.Widt

What I'm trying to do it's to make the width of the toolbar to ocupie all the width of the form. This error doesn't occur very often.

Considerations
- tlbFixed is a System.Windows.Forms.ToolBa
- frmSSDas is a System.Windows.Form

Private Sub frmSSDas_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
tlbFixed.Width = frmSSDas.ActiveForm.Size.Widt
tlbFixed.Refresh(
End Sub '(this is the code of the procedure where it occus - The Language is VB.Net

Thanks in advanc

Rui Pedro Nascimento

Re: System.NullReferenceException in Form Load by Morten

Morten
Fri May 14 06:14:05 CDT 2004

Hi Rui Pedro,

I am guessing that your ActiveForm may not be defined at certain times, in which case trying to access its Size property will cause a NullReferenceException.

If you use Visual Studio.Net break, when you get the exception break and use the command window (in immediate mode, ctrl-alt-i) to study the properties.

Happy coding!
Morten Wennevik [C# MVP]

Re: System.NullReferenceException in Form Load by hirf-spam-me-here

hirf-spam-me-here
Fri May 14 08:21:01 CDT 2004

* "=?Utf-8?B?UnVpIFBlZHJvIE5hc2NpbWVudG8=?=" <rui.nascimento at cgd dot pt> scripsit:
> When I start the debug of my application, sometimes I get a System.NullReferenceException on the principal Form Load in this portion of code:
>
> tlbFixed.Width = frmSSDas.ActiveForm.Size.Width

Dud you check if 'ActiveForm' is pointing to a form?

\\\
If Not Form.ActiveForm Is Nothing Then
...
End If
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>