ImageButton Control at OpenNETCF.org

D

dwhittenburg

http://www.opennetcf.org/forums/topic.asp?TOPIC_ID=228&SearchTerms=color

I included my images into my project at the root level...
I can create an image button, but once it gets to the code below it is
returning a nullreferenceerror...I assume that it cannot find the image, but
I've tried giving a full path from /Program Files/ProjectName/file.jpg and
still cannot get passed this point...

Any help?

redBall.ImageButtonUp = New
Bitmap(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceSt
ream("save_gray_16x16.jpg"))
 
T

Tim Wilson

Looks like you're attempting to load an embedded resource named
"save_gray_16x16.jpg". Have you marked the jpg as an "Embedded Resource" in
the properties window? Are you sure that the resource name is correct?
VS.Net will use <default namespace>.<file name> as the resource name. You
can check the resource name with the ildasm utility.
 
D

dwhittenburg

The jpg was NOT marked as "Embedded Resource", I changed that (Thanks!)...I
redeployed and still the nullreferenceException...
The resource name is correct, however do I need to use a namespace and then
the filename?

I tried using...

Dim str As String =
System.Reflection.Assembly.GetExecutingAssembly().GetName().Name &
".save_gray_16x16.jpg"
redBall.ImageButtonUp = New
Bitmap(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceSt
ream(str))

And now I'm getting a StackOverflowException at this line...
Does this mean that I'm running out of memory?


I know how to use ildasm, but don't know how to get the resourse anme...

Thanks for you help
 
D

dwhittenburg

Just fyi, I also have seperate error handlers for the
nullreferenceexception, stackoverflowexception and the parent exception,
however it's not going into either of the catch clauses, it's just crashing
with the detail/quit screen...
 
M

Mark Arteaga

If the files are located in a directory in your project you will also have
to include those. You can look at the IL code like Tim suggested or you can
use the following to get all the resources in your assembly. This should
give you the correct string to use also.

System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames()
 
T

Tim Wilson

The project properties will show you the "root namespace". So if you
right-click on the project, in the solution explorer, and choose properties,
you can see the root namespace in the dialog that is shown. Instead of just
using the resource name "save_gray_16x16.jpg", the name will be
"<namespace>.save_gray_16x16.jpg". So if the root namespace is
"MyNamespace", then the actual resource name will be
"MyNamespace.save_gray_16x16.jpg".

redBall.ImageButtonUp = New
Bitmap(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceSt
ream("MyNamespace.save_gray_16x16.jpg"))
 
D

dwhittenburg

ok...I've narrowed it down to when I try to set the ImageButtonUp property
of the ImageButton class...
I'm getting a StackOverflowException when trying to call
redBall.ImageButtonUp = oBM...
I have an Exception handler for this Exception but it is not going in
there...Any clue?
The code is below...

GUI Code...

Dim str As String =
System.Reflection.Assembly.GetExecutingAssembly().GetName().Name &
".save_gray_16x16.jpg"
Dim oBM As New
Bitmap(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceSt
ream(str))
redBall.ImageButtonUp = oBM



ImageButton Property...

Public Property ImageButtonUp() As Bitmap
Get
Return ImageButtonUp
End Get

Set(ByVal Value As Bitmap)
ImageButtonUp = Value
End Set
End Property
 
T

Tim Wilson

Looks like your're referencing the property from within the property.
Calling (ImageButton).ImageButtonUp calls (ImageButton).ImageButtonUp calls
(ImageButton).ImageButtonUp... eventually... bam. stack overflow. You must
be storing the ImageButtonUp bitmap in a field somewhere. You need to get
and set that field and not the property.
 
M

Mark Arteaga

Looks like your ImageButtonUp property is referencing itself and calling
itself recursively hence the stack overflow. You will have to change the
property to something like since VB.NET is case insensative.

Public Property ImageButtonUp() As Bitmap
Get
Return _ImageButtonUp
End Get

Set(ByVal Value As Bitmap)
_ImageButtonUp = Value
End Set
End Property
 
D

dwhittenburg

Thanks both Tim and Mark for all of your help...

I figured out that goof-up, now I'm on to my next...

When trying to add the control to either a panel or the main frame I'm still
getting the stack overflow error...
Still researching this one...
I'm doing this...

'Me.pnlTest.Controls.Add(redBall)

Me.Controls.Add(redBall)



Thanks again...
 
T

Tim Wilson

Post the complete code for the ImageButton that you're using. Maybe we'll be
able to tell better what's going on.

--
Tim Wilson
..Net Compact Framework MVP

dwhittenburg said:
Thanks both Tim and Mark for all of your help...

I figured out that goof-up, now I'm on to my next...

When trying to add the control to either a panel or the main frame I'm still
getting the stack overflow error...
Still researching this one...
I'm doing this...

'Me.pnlTest.Controls.Add(redBall)

Me.Controls.Add(redBall)



Thanks again...





"Mark Arteaga <MVP>" <marteaga_[at]_neotericsdc_[dot]_com> wrote in message
Looks like your ImageButtonUp property is referencing itself and calling
itself recursively hence the stack overflow. You will have to change the
property to something like since VB.NET is case insensative.

Public Property ImageButtonUp() As Bitmap
Get
Return _ImageButtonUp
End Get

Set(ByVal Value As Bitmap)
_ImageButtonUp = Value
End Set
End Property


--
Mark Arteaga
.NET Compact Framework MVP
http://www.neotericsdc.com | http://blog.markarteaga.com
Bitmap(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStBitmap(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceSt
 
D

dwhittenburg

Thanks,

Found it...In changing the c# code over to VB I mistakenly changed
base.onpaint to me.onpaint in the onpaint function...duh...This *may* be the
problem :)

Ok...one last final problem...I swear...and you won't hear from me for the
rest of the day...I'm trying to figure out this line of code...I need to
transfer this C# syntax to VB...

C#
redBall.Click += new System.EventHandler(this.balls_Click);
this.Controls.Add(redBall);

VB
redBall.Click += New System.EventHandler(Me.AddressOf(redBalls_Click))


Thanks again

Tim Wilson said:
Post the complete code for the ImageButton that you're using. Maybe we'll be
able to tell better what's going on.

--
Tim Wilson
.Net Compact Framework MVP

dwhittenburg said:
Thanks both Tim and Mark for all of your help...

I figured out that goof-up, now I'm on to my next...

When trying to add the control to either a panel or the main frame I'm still
getting the stack overflow error...
Still researching this one...
I'm doing this...

'Me.pnlTest.Controls.Add(redBall)

Me.Controls.Add(redBall)



Thanks again...





"Mark Arteaga <MVP>" <marteaga_[at]_neotericsdc_[dot]_com> wrote in message
Looks like your ImageButtonUp property is referencing itself and calling
itself recursively hence the stack overflow. You will have to change the
property to something like since VB.NET is case insensative.

Public Property ImageButtonUp() As Bitmap
Get
Return _ImageButtonUp
End Get

Set(ByVal Value As Bitmap)
_ImageButtonUp = Value
End Set
End Property


--
Mark Arteaga
.NET Compact Framework MVP
http://www.neotericsdc.com | http://blog.markarteaga.com


ok...I've narrowed it down to when I try to set the ImageButtonUp property
of the ImageButton class...
I'm getting a StackOverflowException when trying to call
redBall.ImageButtonUp = oBM...
I have an Exception handler for this Exception but it is not going in
there...Any clue?
The code is below...

GUI Code...

Dim str As String =
System.Reflection.Assembly.GetExecutingAssembly().GetName().Name &
".save_gray_16x16.jpg"
Dim oBM As New
Bitmap(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStBitmap(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceSt
 
T

Tim Wilson

Instead of "+=" for dynamic event handler hook up, VB.Net uses the
AddHandler statement
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html
/vaconaddonremoveon.asp).

AddHandler redBall.Click, AddressOf redBalls_Click

--
Tim Wilson
..Net Compact Framework MVP

dwhittenburg said:
Thanks,

Found it...In changing the c# code over to VB I mistakenly changed
base.onpaint to me.onpaint in the onpaint function...duh...This *may* be the
problem :)

Ok...one last final problem...I swear...and you won't hear from me for the
rest of the day...I'm trying to figure out this line of code...I need to
transfer this C# syntax to VB...

C#
redBall.Click += new System.EventHandler(this.balls_Click);
this.Controls.Add(redBall);

VB
redBall.Click += New System.EventHandler(Me.AddressOf(redBalls_Click))


Thanks again

Tim Wilson said:
Post the complete code for the ImageButton that you're using. Maybe
we'll
be
able to tell better what's going on.

--
Tim Wilson
.Net Compact Framework MVP

dwhittenburg said:
Thanks both Tim and Mark for all of your help...

I figured out that goof-up, now I'm on to my next...

When trying to add the control to either a panel or the main frame I'm still
getting the stack overflow error...
Still researching this one...
I'm doing this...

'Me.pnlTest.Controls.Add(redBall)

Me.Controls.Add(redBall)



Thanks again...





"Mark Arteaga <MVP>" <marteaga_[at]_neotericsdc_[dot]_com> wrote in message
Looks like your ImageButtonUp property is referencing itself and calling
itself recursively hence the stack overflow. You will have to
change
the
property to something like since VB.NET is case insensative.

Public Property ImageButtonUp() As Bitmap
Get
Return _ImageButtonUp
End Get

Set(ByVal Value As Bitmap)
_ImageButtonUp = Value
End Set
End Property


--
Mark Arteaga
.NET Compact Framework MVP
http://www.neotericsdc.com | http://blog.markarteaga.com


ok...I've narrowed it down to when I try to set the ImageButtonUp
property
of the ImageButton class...
I'm getting a StackOverflowException when trying to call
redBall.ImageButtonUp = oBM...
I have an Exception handler for this Exception but it is not going in
there...Any clue?
The code is below...

GUI Code...

Dim str As String =
System.Reflection.Assembly.GetExecutingAssembly().GetName().Name &
".save_gray_16x16.jpg"
Dim oBM As New
Bitmap(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceSt
Bitmap(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceSt
 
D

dwhittenburg

You're awesome Tim, thanks...

Tim Wilson said:
Instead of "+=" for dynamic event handler hook up, VB.Net uses the
AddHandler statement
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html
/vaconaddonremoveon.asp).

AddHandler redBall.Click, AddressOf redBalls_Click

--
Tim Wilson
.Net Compact Framework MVP

dwhittenburg said:
Thanks,

Found it...In changing the c# code over to VB I mistakenly changed
base.onpaint to me.onpaint in the onpaint function...duh...This *may* be the
problem :)

Ok...one last final problem...I swear...and you won't hear from me for the
rest of the day...I'm trying to figure out this line of code...I need to
transfer this C# syntax to VB...

C#
redBall.Click += new System.EventHandler(this.balls_Click);
this.Controls.Add(redBall);

VB
redBall.Click += New System.EventHandler(Me.AddressOf(redBalls_Click))


Thanks again

"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message
Post the complete code for the ImageButton that you're using. Maybe
we'll
be
able to tell better what's going on.

--
Tim Wilson
.Net Compact Framework MVP

Thanks both Tim and Mark for all of your help...

I figured out that goof-up, now I'm on to my next...

When trying to add the control to either a panel or the main frame I'm
still
getting the stack overflow error...
Still researching this one...
I'm doing this...

'Me.pnlTest.Controls.Add(redBall)

Me.Controls.Add(redBall)



Thanks again...





"Mark Arteaga <MVP>" <marteaga_[at]_neotericsdc_[dot]_com> wrote in
message
Looks like your ImageButtonUp property is referencing itself and calling
itself recursively hence the stack overflow. You will have to change
the
property to something like since VB.NET is case insensative.

Public Property ImageButtonUp() As Bitmap
Get
Return _ImageButtonUp
End Get

Set(ByVal Value As Bitmap)
_ImageButtonUp = Value
End Set
End Property


--
Mark Arteaga
.NET Compact Framework MVP
http://www.neotericsdc.com | http://blog.markarteaga.com


ok...I've narrowed it down to when I try to set the ImageButtonUp
property
of the ImageButton class...
I'm getting a StackOverflowException when trying to call
redBall.ImageButtonUp = oBM...
I have an Exception handler for this Exception but it is not
going
in
there...Any clue?
The code is below...

GUI Code...

Dim str As String =
System.Reflection.Assembly.GetExecutingAssembly().GetName().Name &
".save_gray_16x16.jpg"
Dim oBM As New
Bitmap(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceSt below
Bitmap(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceSt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top