亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使圖片框沿屏幕邊緣移動而不剪裁?

如何使圖片框沿屏幕邊緣移動而不剪裁?

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 關注
  • 98 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號