📄 frmtopic.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using feiyun0112.cnblogs.com.CSDNReader.Functions ;
using feiyun0112.cnblogs.com.CSDNReader.Model;
namespace feiyun0112.cnblogs.com.CSDNReader.Controls
{
public partial class frmTopic : Form
{
public frmTopic()
{
InitializeComponent();
DelegateFunc.ShowTopicsEvent += new DelegateShowTopics(this.ShowTopic);
DelegateFunc.OpenedTopicEvent += new DelegateOpenedTopic (this.RefreshTopic);
IE.ScriptErrorsSuppressed = false;
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
//因为我用的是static event,所以关闭时一定要移除事件
DelegateFunc.ShowTopicsEvent -= new DelegateShowTopics(this.ShowTopic);
DelegateFunc.OpenedTopicEvent -= new DelegateOpenedTopic(this.RefreshTopic);
IE.Dispose();
_Topic = null;
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private Model.Topic _Topic;
//显示的帖子,修改值即执行打开操作
public Model.Topic Topic
{
get { return _Topic; }
set
{
if (_Topic == null || _Topic.Id != value.Id)
{
value.StartPostEvent += new Topic.DelegateStartPost(StartPost);
value.PostedEvent += new Topic.DelegatePost(Posted);
value.ShowWarningEvent += new Topic.DelegateShowWarning(ShowWarning);
}
LoadingHtml(true);
_Topic = value;
this.Parent.Text = Topic.Name;
_Topic.ShowTopic();
}
}
private void ShowWarning(string strMsg)
{
if (this.Topic == null) return;
if (this.InvokeRequired)
{
try
{
Topic.DelegateShowWarning d = new Topic.DelegateShowWarning(ShowWarning);
this.Invoke(d, new object[] { strMsg });
}
catch
{
MsgFunc.ShowWarning(strMsg);
}
}
else
{
}
}
private void StartPost()
{
LoadingHtml(true);
}
private void Posted(bool blnPosted)
{
LoadingHtml(false);
}
private void ShowTopic(string strTopicID)
{
if (this.Topic==null) return;
if (this.InvokeRequired)
{
try
{
DelegateShowTopics d = new DelegateShowTopics(ShowTopic);
this.Invoke(d, new object[] { strTopicID });
}
catch
{
}
}
else
{
if (Topic.Id == strTopicID)
{
//打开一个空白页,实际内容在IE_DocumentCompleted中
this.IE.Navigate("");
}
}
}
private void RefreshTopic(string strTopicID)
{
if (this.Topic == null) return;
if (this.InvokeRequired)
{
if (this.Topic != null)
{
try
{
DelegateOpenedTopic d = new DelegateOpenedTopic(RefreshTopic);
this.Invoke(d, new object[] { strTopicID });
}
catch
{
}
}
}
else
{
if (Topic.Id == strTopicID)
{
Topic.ShowTopic();
}
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
txtPost.Text = "";
}
private void IE_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//显示帖子内容
this.IE.Document.Write( this.Topic.Html);
LoadingHtml(false);
DelegateFunc.OnRefreshInfo("");
}
/// <summary>
/// 显示loading动画
/// </summary>
/// <param name="blnStart"></param>
private void LoadingHtml(bool blnStart)
{
if (this.Topic == null) return;
if (this.InvokeRequired)
{
try
{
DelegateLoadingHtml d = new DelegateLoadingHtml(LoadingHtml);
this.Invoke(d, new object[] { blnStart });
}
catch
{
}
}
else
{
if (blnStart)
{
intLoadingIndex = 1;
((TabPage)this.Parent).ImageKey = "loading_p1";
timerLoading.Enabled = true;
}
else
{
((TabPage)this.Parent).ImageKey = "";
timerLoading.Enabled = false;
}
}
}
private int intLoadingIndex = 1;
/// <summary>
/// 显示loading动画
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timerLoading_Tick(object sender, EventArgs e)
{
if (this.Topic == null) return;
intLoadingIndex = intLoadingIndex + 1;
if (intLoadingIndex > 8) intLoadingIndex = 1;
((TabPage)this.Parent).ImageKey = "loading_p" + intLoadingIndex.ToString();
}
/// <summary>
/// 回复帖子
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnOK_Click(object sender, EventArgs e)
{
try
{
this.Cursor = Cursors.WaitCursor;
if (!ValidCheck())
{
return;
}
Topic.Post(txtPost.Text, (chkSign.Checked ? true : false));
}
finally
{
this.Cursor = Cursors.Default;
}
}
private bool ValidCheck()
{
if (Variant.CurrentUser == null || string.IsNullOrEmpty( Variant.CurrentUser.Name))
{
frmLogin frm = new frmLogin();
frm.ShowDialog();
}
if (Variant.CurrentUser == null ||string.IsNullOrEmpty( Variant.CurrentUser.Name))
{
return false;
}
if (txtPost.Text.Trim() .Length==0)
{
MsgFunc.ShowWarning("回复内容不可以为空");
return false ;
}
return true;
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Parent.Dispose();
}
private void IE_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
}
private void IE_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
if (e.Url.ToString() .Length==0)
{
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -