1 回答

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超13個(gè)贊
這里的錯(cuò)誤是我假設(shè),LinkLabels 需要一個(gè)相對(duì)于表單的位置。但是,當(dāng)將它們添加到 GroupBox 的 Controls 集合時(shí),它們會(huì)自動(dòng)假定相對(duì)于 GroupBox 而不是 Form 的位置。
所以,我的代碼現(xiàn)在對(duì)于所有四個(gè)組框基本相同,如下所示:
PopulateGroup(newFollowers, grpFollow);
PopulateGroup(unFollow, grpLost);
PopulateGroup(newFriends, grpFriends);
PopulateGroup(unFriend, grpDitched);
和:
private void PopulateGroup(List<string> collPeople, GroupBox groupBox)
{
var folTop = new Point(12, 25);
foreach (var fol in collPeople)
{
var kvp = LookupUser(fol);
if (string.IsNullOrEmpty(kvp.Key)) continue;
var linklabel = new LinkLabel()
{
Text = kvp.Value,
Width = 200,
Height = 15,
Location = folTop
};
ctr++;
linklabel.Links.Add(0, linklabel.Width - 1, $"https://twitter.com/{kvp.Key}");
linklabel.Click += Linklabel_Click;
groupBox.Controls.Add(linklabel);
folTop.Y += 25;
}
}
因此,組框是在表單的左側(cè)還是右側(cè),頂部還是底部并不重要......
- 1 回答
- 0 關(guān)注
- 156 瀏覽
添加回答
舉報(bào)