在没有资源文件vb.net的usercontrol中嵌入图像

时间:2011-03-21 10:54:11

标签: .net image user-controls embed

我需要在用户控件中嵌入4个小的16x16图像,没有图像列表,资源文件等。原因是因为我将在不同的项目中使用这个用户控件,而我只是想要包含用户控件而不需要太多。

无论如何我可以在代码中执行此操作吗?

2 个答案:

答案 0 :(得分:2)

将用户控件作为dll共享是可行的方法,但如果您希望将usercontrol作为源包含,则可以包含图像...“hardcoded”:

    Dim PictureStream As New IO.MemoryStream(New Byte() _
    {&H89, &H50, &H4E, &H47, &HD, &HA, &H1A, &HA, &H0, &H0, &H0, &HD, &H49, &H48, &H44, &H52, &H0, &H0, &H0, &H30, _
     &H0, &H0, &H0, &H30, &H4, &H3, &H0, &H0, &H0, &HA5, &H2C, &HE4, &HB4, &H0, &H0, &H0, &H1, &H73, &H52, &H47, _
     &H42, &H0, &HAE, &HCE, &H1C, &HE9, &H0, &H0, &H0, &H4, &H67, &H41, &H4D, &H41, &H0, &H0, &HB1, &H8F, &HB, &HFC, _
     &H61, &H5, &H0, &H0, &H0, &H20, &H63, &H48, &H52, &H4D, &H0, &H0, &H7A, &H26, &H0, &H0, &H80, &H84, &H0, &H0, _
     &HFA, &H0, &H0, &H0, &H80, &HE8, &H0, &H0, &H75, &H30, &H0, &H0, &HEA, &H60, &H0, &H0, &H3A, &H98, &H0, &H0, _
     &H17, &H70, &H9C, &HBA, &H51, &H3C, &H0, &H0, &H0, &H30, &H50, &H4C, &H54, &H45, &H0, &H0, &H0, &H80, &H0, &H0, _
     &H0, &H80, &H0, &H80, &H80, &H0, &H0, &H0, &H80, &H80, &H0, &H80, &H0, &H80, &H80, &H80, &H80, &H80, &HC0, &HC0, _
     &HC0, &HFF, &H0, &H0, &H0, &HFF, &H0, &HFF, &HFF, &H0, &H0, &H0, &HFF, &HFF, &H0, &HFF, &H0, &HFF, &HFF, &HFF, _
     &HFF, &HFF, &H7B, &H1F, &HB1, &HC4, &H0, &H0, &H0, &H9, &H70, &H48, &H59, &H73, &H0, &H0, &HE, &HC2, &H0, &H0, _
     &HE, &HC2, &H1, &H15, &H28, &H4A, &H80, &H0, &H0, &H1, &H8, &H49, &H44, &H41, &H54, &H38, &HCB, &H85, &H54, &H4B, _
     &H16, &HC4, &H20, &H8, &HE3, &H70, &H2C, &H39, &H36, &HCB, &H1C, &H6A, &H8, &HE0, &H67, &HDE, &H94, &H4E, &H17, &H16, _
     &HD, &H60, &H88, &HA2, &HA8, &HC2, &H55, &HD5, &H94, &HA3, &HBA, &H71, &HE4, &H8A, &H28, &H68, &HAA, &HD9, &HD7, &HCF, _
     &H55, &HCA, &H6A, &HD7, &H15, &H18, &HFF, &H0, &H2C, &H22, &HD1, &HB, &HE1, &H10, &H13, &H14, &HE0, &H1, &H69, &H7, _
     &H2A, &HFD, &H32, &H5E, &H3A, &H47, &H11, &H68, &H83, &H19, &HC5, &H9D, &H5B, &H61, &H91, &HE9, &H89, &H3B, &H23, &HDC, _
     &H7A, &HBD, &H10, &H30, &H93, &HCB, &H21, &H14, &H7F, &H6C, &H6A, &H76, &H0, &H18, &H60, &HBE, &H39, &H6F, &HC0, &H1C, _
     &H88, &H64, &H17, &HD0, &H35, &H5D, &H40, &HBA, &H6E, &H80, &H99, &H56, &HAE, &H2, &HAE, &H2D, &HEE, &H4D, &H64, &H89, _
     &H11, &H80, &H2F, &H80, &HC2, &HC8, &H12, &HC3, &H9C, &HEC, &HB1, &H85, &H11, &HEB, &HA2, &HC2, &H3B, &H3E, &HAC, &H62, _
     &H43, &HAB, &H5C, &H4F, &H46, &H96, &HCC, &H90, &H8, &H2B, &H4F, &H91, &H98, &H9E, &H18, &HCD, &HF4, &H95, &H12, &H3, _
     &H25, &H15, &HF2, &H8, &H32, &H44, &H36, &HD3, &H4, &HB0, &H39, &H13, &HA8, &H79, &H84, &H91, &H2, &HAD, &H6, &H6A, _
     &HCB, &H62, &H90, &H63, &H92, &H26, &H50, &H13, &H74, &H3E, &HE6, &HFA, &H13, &H31, &HEE, &H31, &HB3, &H1A, &HEB, &H78, _
     &HAE, &H7C, &HD4, &H6A, &H54, &HF7, &H9C, &H47, &H46, &H9C, &HF3, &H98, &H4F, &H70, &H3A, &HF3, &HF9, &H96, &H8C, &HF7, _
     &H6A, &HBC, &H89, &HFF, &HEE, &HEE, &HCF, &H6D, &HC7, &H63, &H7F, &HD8, &H7B, &H47, &H3D, &HF7, &HE0, &HD8, &HB5, &H2F, _
     &H7D, &H3E, &HBC, &HC, &HE3, &H5B, &H32, &HBF, &H3E, &H8B, &H8D, &HEF, &H31, &HE7, &H1F, &H67, &H2E, &H8, &HE7, &H2A, _
     &HE1, &HA1, &H7E, &H0, &H0, &H0, &H0, &H49, &H45, &H4E, &H44, &HAE, &H42, &H60, &H82})
    PictureBox1.Image = New Drawing.Bitmap(PictureStream)
    PictureStream = Nothing

(这是VB.Net,随意适应您选择的语言)

答案 1 :(得分:1)

如果您添加ImageList(将在controL下使用resx文件)或项目级资源文件,则它们不会创建额外的文件并将其编译到您的DLL中。