/// <summary> /// 刷新会话列表 /// </summary> private void refresh() { var height = 0; var hide = sceMessage.Controls[1]; var messageTime = DateTime.MinValue; MessageBox box = null; messages.OrderBy(i => i.timetag).ToList().ForEach(i => { var time = Util.getDateTime(i.timetag); var ts = time - messageTime; if (ts.TotalMinutes > 15) { messageTime = time; var timeControl = new TimeLabel { time = time, Name = Util.newId("N"), Size = new Size(hide.Width, 20), Location = new Point(0, height), Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right }; hide.Controls.Add(timeControl); height = height + timeControl.Height; } box = new MessageBox { width = hide.Width, message = i, targetHead = targetHead, Location = new Point(0, height), Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right }; box.play += (sender, args) => stopPlaying(args.id); box.stop += (sender, args) => playing = false; hide.Controls.Add(box); height = height + box.Height; }); hide.Dock = height > Height ? DockStyle.Top : DockStyle.Fill; hide.Height = height; hide.Visible = true; sceMessage.ScrollControlIntoView(box); var show = sceMessage.Controls[0]; show.Visible = false; show.SendToBack(); show.Controls.Clear(); }
/// <summary> /// 构造并添加时间控件到消息窗口 /// </summary> /// <param name="time"></param> private void addTime(DateTime time) { messageTime = time; var control = new TimeLabel { time = time, Name = Util.newId("N"), Dock = DockStyle.Top }; pceHistory.Controls.Add(control); height = height + control.Size.Height; pceHistory.Height = height; }