More graphics problems!!

Hello all!
As I said in an earlier post I'm interested in getting my hands dirty with graphics in VB.NET. So I downloaded a small sample which (supposedly) displayed a circular form. I say 'supposedly' because the sample failed to compile. In fact when I loaded the sample into VB.NET, I got a huge notification saying that the sample code would have to be 'converted' to the current VB.NET version, and asked me to confirm, which I did.
These are the vital stats of my VB.NET:
MS Development Environment 2003, Version 7.1.3088
MS .NET Framework 1.1, Version 1.1.4322
Error--> Namespace or type 'Winforms' for the Imports 'System.Winforms' cannot be found.

I then exitted VB.NET completely and began again, with a new project (not the downloaded one). I entered the offending Imports statement and VB.NET flagged it as an error. I typed "Imports System." and then scanned the dropdown, but I could not see 'Winforms'.
But "Inherits System.Windows.Forms.Form" is accepted OK.
I have also read some articles where "Imports System.Winforms" is used quite a bit, so I do know that System.Winforms should be an importable library. But it just does not work at my place! Wotgivz?

Primarily, I was checking out how "clipping region" was effected in .NET. Since I had not a clue about how to go about it, I very rapidly drove myself up the wall!
I did:
[code]
Private Sub btnClip_Click(...)
Me.Refresh()
End Sub

Private Sub Form1_Paint(...)
Dim cliprgn As Drawing2D.RegionData
Dim cliprgnarray(4) As Point
Msgbox("Seting the first value...")
cliprgn.Data.SetValue(cliprgnarray(0), 0)
Msgbox("First value set OK!")
...
End Sub
[/code]

The idea is that I click the btnClip button (which forces the form to repaint) to set up a clipping region on the form, and then draw something on the form which should appear clipped.
However, when I run the code and click the button, the first messagebox displays, but not the second. That means the code has executed past the first messagebox. I click the OK button of the messagebox, and then the program grinds to a halt and the following error message comes up:
[code]
"An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll
Additional information: Object reference not set to an instance of an object."
[/code]
What object? I broke (pressed [Break]) the program and the beauty is that the error points to the Me.Refresh() statement in btnClip_Click(...)! That is, the error is attributed to a statement that has already been executed! Wotgivz?

Regards,
Tej Singh

Comments

  • System.WinForms was renamed to System.Windows.Forms. I believe in beta 2. The code sample you found was most likely written in 2000, when .NET was still in flux.

    As for your NullReferenceException, you are not instantiating cliprgn. You are only declaring it to be of type Drawing2D.RegionData. When you try to access the Data property you can't because there is no object - it is still null (Nothing), hence the NullReferenceException.

    Get to know the debugger. If you had put a breakpoint on the line causing the exception (cliprgn.Data.SetValue...), you would have seen in the Autos window that the value of cliprgn is Nothing.

    : Hello all!
    : As I said in an earlier post I'm interested in getting my hands dirty with graphics in VB.NET. So I downloaded a small sample which (supposedly) displayed a circular form. I say 'supposedly' because the sample failed to compile. In fact when I loaded the sample into VB.NET, I got a huge notification saying that the sample code would have to be 'converted' to the current VB.NET version, and asked me to confirm, which I did.
    : These are the vital stats of my VB.NET:
    : MS Development Environment 2003, Version 7.1.3088
    : MS .NET Framework 1.1, Version 1.1.4322
    : Error--> Namespace or type 'Winforms' for the Imports 'System.Winforms' cannot be found.
    :
    : I then exitted VB.NET completely and began again, with a new project (not the downloaded one). I entered the offending Imports statement and VB.NET flagged it as an error. I typed "Imports System." and then scanned the dropdown, but I could not see 'Winforms'.
    : But "Inherits System.Windows.Forms.Form" is accepted OK.
    : I have also read some articles where "Imports System.Winforms" is used quite a bit, so I do know that System.Winforms should be an importable library. But it just does not work at my place! Wotgivz?
    :
    : Primarily, I was checking out how "clipping region" was effected in .NET. Since I had not a clue about how to go about it, I very rapidly drove myself up the wall!
    : I did:
    : [code]
    : Private Sub btnClip_Click(...)
    : Me.Refresh()
    : End Sub
    :
    : Private Sub Form1_Paint(...)
    : Dim cliprgn As Drawing2D.RegionData
    : Dim cliprgnarray(4) As Point
    : Msgbox("Seting the first value...")
    : cliprgn.Data.SetValue(cliprgnarray(0), 0)
    : Msgbox("First value set OK!")
    : ...
    : End Sub
    : [/code]
    :
    : The idea is that I click the btnClip button (which forces the form to repaint) to set up a clipping region on the form, and then draw something on the form which should appear clipped.
    : However, when I run the code and click the button, the first messagebox displays, but not the second. That means the code has executed past the first messagebox. I click the OK button of the messagebox, and then the program grinds to a halt and the following error message comes up:
    : [code]
    : "An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll
    : Additional information: Object reference not set to an instance of an object."
    : [/code]
    : What object? I broke (pressed [Break]) the program and the beauty is that the error points to the Me.Refresh() statement in btnClip_Click(...)! That is, the error is attributed to a statement that has already been executed! Wotgivz?
    :
    : Regards,
    : Tej Singh
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion