我正在尝试从我的解决方案中加载一个图像,这个图像是作为jpg嵌入的,但是它表示它没有找到。我正在宣布这两个图像
Image selectedImage = null;
Image emptyImage = null;
selectedImage = Image.FromStream(System.Reflection.Assembly.
GetExecutingAssembly().GetManifestResourceStream(@"selected.png"));
emptyImage = Image.FromStream(System.Reflection.Assembly
.GetExecutingAssembly().GetManifestResourceStream(@"empty.png"));
我需要自定义绘制一个复选框,以便保留样式您可以看到图像包含在我的解决方案中
并且它们都被选为嵌入式资源qazxsw poi
然后我使用此自定义函数将复选框图像绘制到约会上
任何理由为什么我的图像可能为null我认为你不必提供完整的路径,除非它在磁盘上?
编辑2
我尝试了一个资源文件但由于某种原因它也说空了
private void dxsourceNetAppointments_CustomDrawAppointment(object sender, CustomDrawObjectEventArgs e)
{
VerticalAppointmentViewInfo apptViewInfo = e.ObjectInfo as VerticalAppointmentViewInfo;
if (apptViewInfo != null)
{
Rectangle imageBounds = GetImageBoundsFromViewInfo(apptViewInfo);
e.DrawDefault();
bool isCustomSelected = (bool)apptViewInfo.Appointment.CustomFields["CheckedIn"];
e.Graphics.DrawImage(isCustomSelected ? selectedImage : emptyImage, imageBounds);
e.Handled = true;
}
}
}
在调用 selectedImage = WindowsFormsApplication1.SchedurlesImages.selected;
emptyImage = WindowsFormsApplication1.SchedurlesImages.empty;
时,您需要使用程序集名称对其进行限定,例如:
GetManifestResourceStream
我建议使用基于RESX的资源文件,而不是使用嵌入式资源?它将代码生成一个包装器,您可以直接使用静态属性。