"embedded icon resource" ?

E

eBob.com

Context: I'd like to add a column to an unbounded DataGridView for an icon.
Different icons will be used in different rows.

I found this code in researching how to do this ...

Dim PlusIcon As New Icon(Me.GetType(), "Plus.ico")
Dim iconColumn As New DataGridViewImageColumn()

With iconColumn
.Image = PlusIcon.ToBitmap()
.Name = "Plus"
.HeaderText = "Header Text"
End With

MasterDGV.Columns.Insert(2, iconColumn)

(I found the code here:
http://msdn.microsoft.com/en-us/library/2ab8kd75.aspx; the code above
changes the name of the icon and DataGridView.)

Documentation for the example says that I will need an "embedded icon
resource" named Plus.ico. I couldn't find anything explicit about how to
add an embedded icon resource to my project, but I stumbled around and ended
up using Project > Add Existing Item (VS2008). I can't be certain that
worked but at least Solution Explorer now knows about the icon files I
added.

In any event, when I try to execute the code above I get "Argument Exception
was unhandled / Resource 'Plus.ico' cannot be found in class ...".

Actually I did find instruction
(http://www.devx.com/dotnet/Article/10831/1954) titled "How to Embed
Resource Files in .NET Assemblies" but it refers to a "Build Action"
Property which I cannot find. In fact, on my VS View menu "Property Pages"
is greyed out.

I'd sure appreciate any help anyone can offer.

Thanks, Bob
 
E

eBob.com

eBob.com said:
Context: I'd like to add a column to an unbounded DataGridView for an
icon. Different icons will be used in different rows.

I found this code in researching how to do this ...

Dim PlusIcon As New Icon(Me.GetType(), "Plus.ico")
Dim iconColumn As New DataGridViewImageColumn()

With iconColumn
.Image = PlusIcon.ToBitmap()
.Name = "Plus"
.HeaderText = "Header Text"
End With

MasterDGV.Columns.Insert(2, iconColumn)

(I found the code here:
http://msdn.microsoft.com/en-us/library/2ab8kd75.aspx; the code above
changes the name of the icon and DataGridView.)

Documentation for the example says that I will need an "embedded icon
resource" named Plus.ico. I couldn't find anything explicit about how to
add an embedded icon resource to my project, but I stumbled around and
ended up using Project > Add Existing Item (VS2008). I can't be certain
that worked but at least Solution Explorer now knows about the icon files
I added.

In any event, when I try to execute the code above I get "Argument
Exception was unhandled / Resource 'Plus.ico' cannot be found in class
...".

Actually I did find instruction
(http://www.devx.com/dotnet/Article/10831/1954) titled "How to Embed
Resource Files in .NET Assemblies" but it refers to a "Build Action"
Property which I cannot find. In fact, on my VS View menu "Property
Pages" is greyed out.

I'd sure appreciate any help anyone can offer.

Thanks, Bob

Since this statement: Dim PlusIcon As New Icon(Me.GetType(), "Plus.ico")
was causing the exception I thought maybe I'd have better luck with another
constructor. So I tried this ...
Dim PlusIcon As New Icon("d:\icons\diagona\ico format-03-16\Plus.ico", New
Size(1, 1))
and that did get around the exception and I do get the icon in the column,
BUT it's huge, much larger than an icon. And I can get any of the
constructors to honor a size specification. I've tried two integers and, as
above, a Size object, but the icon always comes out the same size, too big!

Still, I'd like the icon resource to be embedded. So I am still very
interested in an answer to my original question.

Thanks, Bob
 

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

Similar Threads


Top