my.resources vb.net to c#

my.resources vb.net to c#

^_^clovis^_^
Advocate Advocate
1,052 Views
5 Replies
Message 1 of 6

my.resources vb.net to c#

^_^clovis^_^
Advocate
Advocate

Hello all,

I hope that everyone is OK during this Covid period.

I'm trying to translate  a vb.net project into a c# one. I don't see how to translate "my.resources" as showed here after in my vb.net project:

 

' Sample to illustrate creating a button definition.
            Dim largeIcon As IPictureDisp = PictureDispConverter.ToIPictureDisp(My.Resources.Pic_large)

Any help would be greatly appreciated!

thanks

0 Likes
Accepted solutions (1)
1,053 Views
5 Replies
Replies (5)
Message 2 of 6

yan.gauthier
Advocate
Advocate

System.Drawing.Icon DimGenIcon = new System.Drawing.Icon(this.GetType(), "IconFile.ico");

 

All you have to do is set your IconFile.ico as EmbeddedRessource

0 Likes
Message 3 of 6

yan.gauthier
Advocate
Advocate

Edit was not working, here is a snap of what it looks likeembed.png

Message 4 of 6

^_^clovis^_^
Advocate
Advocate

Hello yan.gauthier

That's also what I did after some search on the internet. I found great guideline from Smallguru.

Thanks to him.

http://www.ar-cad.com/smallguru/2008/08/develop-autodesk-inventor-addin-using-csharp-part-1/

 

I was looking for the same approach as vb.net with just

my.resources... I found it elegant. I guess there isn't a 1 on 1 translation.

 

Thanks for you support!

 

 

0 Likes
Message 5 of 6

yan.gauthier
Advocate
Advocate
Accepted solution

If you wish to do a 1 for 1 translation, some samples uses the Microsoft.VisualBasic.Compatibility.VB6 namespace, but it is not recommended as it is legacy. Instead, you could implement the following class

 

  internal class AxHostConverter : AxHost
    {
        private AxHostConverter() : base("") { }

        static public stdole.IPictureDisp ImageToPictureDisp(Image image)
        {
            return (stdole.IPictureDisp)GetIPictureDispFromPicture(image);
        }
        static public Image PictureDispToImage(stdole.IPictureDisp pictureDisp)
        {
            return GetPictureFromIPicture(pictureDisp);
        }
    }

 

then, you should be able to translate 

Dim largeIcon As IPictureDisp = PictureDispConverter.ToIPictureDisp(My.Resources.Pic_large)

into 

stdole.IPictureDisp largeIcon = AxHostConverter.ImageToPictureDisp(Properties.Resources.Pic_large)

 

Message 6 of 6

^_^clovis^_^
Advocate
Advocate

Hello Yan,

Thank you very much! that'll do!

 

0 Likes