⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmtopic.cs

📁 定义社区节点
💻 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();

            

            IE.ScriptErrorsSuppressed = false;
        }
        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            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);

                    value.ShowTopicsEvent += new Topic.DelegateShowTopics(this.ShowTopic);
                    value.OpenedTopicEvent += new Topic.DelegateOpenedTopic(this.RefreshTopic);
                }
                

                _Topic = value;
                

                this.Parent.Text =Topic.RoomName() +"=>"+ Topic.Name;


                LoadingHtml(true);

                _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, bool blnCheckPosted)
        {
            if (this.Topic==null) return;
            if (this.InvokeRequired)
            {

                try
                {
                    Topic.DelegateShowTopics d = new Topic.DelegateShowTopics(ShowTopic);
                    this.Invoke(d, new object[] { strTopicID ,  blnCheckPosted});
                }
                catch
                {
                }

            }
            else
            {
                               

               
                    //打开一个空白页,实际内容在IE_DocumentCompleted中
                    this.IE.Navigate("about:balnk");
                
            }
        }

        private void RefreshTopic(string strTopicID, bool blnCheckPosted)
        {
            if (this.Topic == null) return;
            if (this.InvokeRequired)
            {
                if (this.Topic != null)
                {
                    try
                    {
                        Topic.DelegateOpenedTopic d = new Topic.DelegateOpenedTopic(RefreshTopic);
                        this.Invoke(d, new object[] { strTopicID, blnCheckPosted });
                    }
                    catch
                    {
                    }
                }

            }
            else
            {
                CommonFunc.Addlog(string.Format("RefreshTopic {0}", Topic));
                
                    LoadingHtml(true);
                    Topic.ShowTopic(blnCheckPosted);
                
            }
        }


        private void btnCancel_Click(object sender, EventArgs e)
        {
            txtPost.Text = "";
        }

        private void IE_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            //显示帖子内容
            if (e.Url.ToString() == "about:balnk")
            {
                CommonFunc.Addlog(string.Format("IE_DocumentCompleted {0}", Topic));
                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();
        }

        string strOldHtml = string.Empty;
        /// <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;
                }

                strOldHtml = _Topic.Html;
                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 + -