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

如何使图片框沿屏幕边缘移动而不剪裁?

如何使图片框沿屏幕边缘移动而不剪裁?

C#
侃侃无极 2022-07-23 16:22:45
可能有更好的方法来做到这一点,但这有效:        List<NContainer> nList = new List<NContainer>();        nList.Add(new NContainer { _HostFqdn = "ab1.corp.com", _HostIp = "192.168.0.2", _Severity = 1, _Issue = "Check 1", _ProtoPort = "TCP_80" });        nList.Add(new NContainer { _HostFqdn = "ab2.corp.com", _HostIp = "192.168.0.3", _Severity = 2, _Issue = "Check 2", _ProtoPort = "TCP_81" });        nList.Add(new NContainer { _HostFqdn = "ab3.corp.com", _HostIp = "192.168.0.4", _Severity = 1, _Issue = "Check 2", _ProtoPort = "TCP_82" });        nList.Add(new NContainer { _HostFqdn = "ab4.corp.com", _HostIp = "192.168.0.5", _Severity = 3, _Issue = "Check 1", _ProtoPort = "TCP_80" });        nList.Add(new NContainer { _HostFqdn = "ab5.corp.com", _HostIp = "192.168.0.6", _Severity = 3, _Issue = "Check 5", _ProtoPort = "TCP_443" });        nList.Add(new NContainer { _HostFqdn = "ab6.corp.com", _HostIp = "192.168.0.7", _Severity = 4, _Issue = "Check 1", _ProtoPort = "TCP_80" });        IEnumerable<NContainer> query = from NContainer vulns in nList                                 orderby vulns._Issue                                 where vulns._Severity >= 1                                 select vulns;        Console.WriteLine("Group by _Issue");        var prevIssue = "";        bool first = true;        foreach (var vuln in query)        {            if (prevIssue != vuln._Issue)            {                if (first)                    first = false;                else                    Console.WriteLine("\n");                Console.WriteLine("\t{0}", vuln._Issue);                Console.Write("\t");                prevIssue = vuln._Issue;            }        }基本上使用 Console.Write 而不是 WriteLine 以便您可以循环并将特定信息的所有 IP 信息附加到同一行。其余的只是格式化。在一个示例汽车游戏中,我希望能够让汽车在屏幕内移动,并且我希望它被边缘“绑定”。但是,它会不断剪辑并超出屏幕范围。我把图片框做成正方形,并使用汽车图片的尺寸,它在图片框中居中)作为代码模型的基础。图片框为 100x100,汽车图片(侧向时)大约为 50x100。例如,如果汽车在屏幕边缘侧向行驶,我会将图片框的 Y 位置设为 -25。但是,我觉得这太不方便了,因为我可能需要更改汽车的图片。这段代码工作得很好,但我觉得它太长了,太不方便了。
查看完整描述

1 回答

?
紫衣仙女

TA贡献1839条经验 获得超15个赞

如果代码有效,那么,它可以明确地总结为:


int verticalDirection = Convert.ToInt32(iDirection == CarDirection.UP || iDirection == CarDirection.DOWN);

int horizontalDirection = Convert.ToInt32(iDirection == CarDirection.LEFT || iDirection == CarDirection.RIGHT);

if (pNewLoc.X <= 0)

{

    pNewLoc.X = -25 * verticalDirection;

}

else

{

    pNewLoc.X = iX + 25 * verticalDirection;

}

if (pNewLoc.Y <= 0)

{

    pNewLoc.Y = -25 * horizontalDirection;

}

else

{

    pNewLoc.Y = iY + 25 * horizontalDirection;

}

如果您更改图片的大小,那么您不必使用类似的常量,25而是声明一个取决于汽车图片大小的变量。


查看完整回答
反对 回复 2022-07-23
  • 1 回答
  • 0 关注
  • 129 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号