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

📄 frmtopic.cs

📁 是一款式CSDN阅读器,可以方便CSDN用户阅读自己感兴趣的内容!
💻 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 ShowTopicsDelegate(this.ShowTopic);
            DelegateFunc.OpenedTopicEvent  += new OpenedTopicDelegate (this.RefreshTopic);
        }
        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            //因为我用的是static event,所以关闭时一定要移除事件
            DelegateFunc.ShowTopicsEvent -= new ShowTopicsDelegate(this.ShowTopic);
            DelegateFunc.OpenedTopicEvent -= new OpenedTopicDelegate(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
            {
                LoadingHtml(true);

                _Topic = value;
                TopicFunc tFunc = new TopicFunc(_Topic);

                this.Parent.Text = Topic.Name;

                tFunc.ShowTopic();
            }
        }

        private void ShowTopic(string strTopicID)
        {
            if (this.Topic==null) return;
            if (this.InvokeRequired)
            {

                try
                {
                    ShowTopicsDelegate d = new ShowTopicsDelegate(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.InvokeRequired)
            {
                if (this.Topic != null)
                {
                    try
                    {
                        OpenedTopicDelegate d = new OpenedTopicDelegate(RefreshTopic);
                        this.Invoke(d, new object[] { strTopicID });
                    }
                    catch
                    {
                    }
                }

            }
            else
            {
                if (Topic.Id == strTopicID)
                {
                    TopicFunc tFunc = new TopicFunc(Topic);
                    tFunc.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 (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)
        {
            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;
                }

                TopicFunc tFunc = new TopicFunc(this.Topic);
                if (tFunc.Post(txtPost.Text, (chkSign.Checked ? true : false)))
                {
                    this.Topic = this.Topic;
                }
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private bool ValidCheck()
        {
            if (Variant.CurrentUser == null)
            {
                frmLogin frm = new frmLogin();
                frm.ShowDialog();
            }

            if (Variant.CurrentUser == null)
            {
                return false;
            }
            if (txtPost.Text.Trim() == "")
            {
                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() =="")
                    {
                
                    }

        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -