/// <summary> /// 显示标签 /// </summary> /// <param name="allComment"></param> private void ShowTag(List <CommentInfo> allComment) { int minCount = 5; int x = 8; int y = 3; int n = 0; dic_tag = dic_tag.OrderByDescending(p => p.Value.Count).ToDictionary(p => p.Key, o => o.Value); foreach (var item in dic_tag) { int count = item.Value.Count; if (count < minCount) { continue; } string countStr = (count > 99) ? "(99+)" : "(" + count.ToString() + ")"; Label label = new Label() { Text = item.Key + countStr, Location = new Point(x, y), AutoSize = true, Cursor = Cursors.Hand, BackColor = Color.FromArgb(255, 224, 192), Font = new Font("宋体", 12, FontStyle.Regular), BorderStyle = BorderStyle.FixedSingle, Visible = true, TabIndex = n }; label.Click += new EventHandler(CommentLabel_Click); list_tag.Add(label); switch (item.Key.Length) { case 5: x += 140; break; case 4: x += 120; break; case 3: x += 100; break; case 2: x += 80; break; case 1: x += 60; break; default: x += 160; break; } if (count > 99) { x += 10; } //换行 if (x >= 800) { x = 8; y += 25; } n++; } Invoke(new Action(() => { if (list_tag.Count > 0) { this.pnlLabel.Controls.AddRange(list_tag.ToArray()); //默认选中第一个 CommentLabel_Click(list_tag[0], null); } else { int all_count = allComment.Count; //动态添加控件显示提示语 重新搜索会清空pan 上所有控件 Label label = new Label() { Text = all_count > 0 ? "相同评论关键词太少无法提取标签" : "暂无评论数据", Location = new Point(all_count > 0 ? 267 : 360, 35), AutoSize = true, ForeColor = Color.Red }; pnlLabel.Controls.Add(label); lblComment.Visible = true; lblComment.Text = all_count > 0 ? "所有评论" : ""; if (allComment != null && allComment.Count > 0) { allComment = allComment.OrderByDescending(a => a.date).ToList(); } //显示所有评论 foreach (var item in allComment) { //所有评论也过滤下代抢、楼盘顾问 if (MainHelper.FilterAuthor(item.author, txtSearchProject.Text)) { continue; } txtComment.Text += item.author + " " + item.date.ToString("yyyy-MM-dd") + "\r\n\r\n" + item.content + "\r\n\r\n"; } } //启用开启按钮 btnStart.Enabled = true; txtSearchProject.Enabled = true; txtSearchProject.Focus(); })); }