List replies in a winform

眉间皱痕 提交于 2019-11-30 06:04:12

问题


In my C# app I get an xml from a server that contains some replies like in a forum thread (with elements like author, time, body, title, whatever).

When I get this xml, I create a new form in which i want to display these replies, and a little text box with an "add reply" button. I'd also like some edit buttons on perhaps my own replies in the reply list displayed in the form.

The simplest way that came to my mind to display the replies is to put a web browser control in the form, generate a full html page in a string from the xml, and throw it in that web browser control. And under it i can put the text box with the add reply button. Everything is ok, except that i have no idea of how i could implement the edit function on my own replies (i mean i could add a link in there... but link to what)

I would like to know if there is a way to get that edit event from the web browser control (my guess is i can't) or another (maybe simple/easy) idea of displaying the replies in a winform using other controls


回答1:


Yes, that's possible, you want to turn "design mode" on for the document. Add a reference to Microsoft.mshtml. Start a new Windows Forms project and drop a WB and a button on the form. Make the code look similar to this:

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        webBrowser1.DocumentText = "<html><body><textarea rows='15' cols='92' name='post-text' id='wmd-input'></textarea></body></html>";
        webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
        button1.Click += button1_Click;
    }

    void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
        mshtml.IHTMLDocument2 doc = webBrowser1.ActiveXInstance as mshtml.IHTMLDocument2;
        doc.designMode = "On";
    }

    private void button1_Click(object sender, EventArgs e) {
        var html = webBrowser1.Document.Body.All["post-text"].InnerHtml;
        // do something with that
        //...
    }
}


来源:https://stackoverflow.com/questions/2866463/list-replies-in-a-winform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!