为了账号安全,请及时绑定邮箱和手机立即绑定

想要显示最多 5 个缩略图

想要显示最多 5 个缩略图

C#
天涯尽头无女友 2021-11-28 20:19:14
如果要从文件加载图像,可以使用FromFile 方法。来自 msdn 的例子:private void Button2_Click(System.Object sender, System.EventArgs e){    try    {        Bitmap image1 = (Bitmap) Image.FromFile(@"C:\Documents and Settings\" +            @"All Users\Documents\My Music\music.bmp", true);        TextureBrush texture = new TextureBrush(image1);        texture.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile;        Graphics formGraphics = this.CreateGraphics();        formGraphics.FillEllipse(texture,             new RectangleF(90.0F, 110.0F, 100, 100));        formGraphics.Dispose();    }    catch(System.IO.FileNotFoundException)    {        MessageBox.Show("There was an error opening the bitmap." +            "Please check the path.");    }}如果要从流加载图像,也可以使用FromStream 方法。
查看完整描述

2 回答

?
达令说

TA贡献1821条经验 获得超6个赞

您已经在代码中使用了一些 Linq,所以只需多使用一点。Linq 中的Take()方法将完全符合您的要求:


@foreach (var orderline in order.OrderLines.DistinctBy(ol => ol.imageURL).Take(5))

{

    <img height="40" src="@orderline.imageURL" alt="@(orderline.Listing.Title.Length > 15 ? orderline.Listing.Title.Substring(0, 15) : orderline.Listing.Title)" />

}

将Take(5)在年底加入我意味着你只能通过迭代最大的5个项目


查看完整回答
反对 回复 2021-11-28
?
一只萌萌小番薯

TA贡献1795条经验 获得超7个赞

将您的 foreach 更改为 for 循环


@for(var i = 0; i < 5; i++)


  Your code goes here using thing[i]


查看完整回答
反对 回复 2021-11-28
  • 2 回答
  • 0 关注
  • 214 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信