我现在想做一个web版的在线客服系统,聊天窗口用的textbox的MultiLine,textbox是从SQL数据库读取聊天内容的,然后在textbox上加了个timer,3秒刷新下textbox窗口,更新聊天内容。现在问题是textbox中有新信息时,滚动条怎么才能自动滚动到最低端?望各位能给出方法及代码。

解决方案 »

  1.   

    博客园有个开源的WebIM系统,你可以看看http://www.cnblogs.com/lucc/archive/2010/06/10/1755192.html
      

  2.   

    用RICHTEXTBOX有方法可以直接到最后一条,你查查吧,我也记不得了
      

  3.   

    用RichTextBox控件,有个方法叫.ScrollToCaret();
    MyRichTextBox.ScrollToCaret();
      

  4.   

    document.getElementById("<%=textbox1.ClientID%>").scrollTop = document.getElementById("<%=textbox1.ClientID%>").scrollHeight;
      

  5.   

    web窗体里是没有RichTextbox,还是我没找到?请指教下!
      

  6.   

    这个方法我也试过啦,不过没有效果呢,是不是位置放错啦?
    我放在Timer1_Tick,textbox1_TextChanged里都没用呢。。
    不好意思,我接触c#不久,请多包含!
      

  7.   

    我知道在一般的textbox里可行,但我的textbox是显示数据库的信息,不输入文本,readonly,貌似这个方法就行不通了。
      

  8.   

    类似源代码:
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
            <asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="3000">
            </asp:Timer>
            <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Height="148px" Width="224px"></asp:TextBox>
         </ContentTemplate></asp:UpdatePanel>
         </div>
        </form>
    </body>
    </html><script type="text/javascript">
    function sc()
    {
    document.getElementById("TextBox1").scrollTop = document.getElementById("TextBox1").scrollHeight;
    }
    </script>
      

  9.   

     
    protected void Timer1_Tick(object sender, EventArgs e)
            {
                TextBox1.Text += "sdfsfsddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\r\n";
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script type=\"text/javascript\">sc();</script>)");
            }
      

  10.   


    这个是winform里的控件 
      

  11.   


    引用错了 是这个RichTextBox控件 它是winform里的控件 
      

  12.   

    弱弱的问一句 document 是自己定义的啊??