listbox自动添加的一行数据是控件的焦点,就是自动滑动。因为现在数据满了之后后面的每行数据看不到 还要手动滑动下去才能看 可不可以自动滑动下去?

解决方案 »

  1.   

    可以,发消息便可,让listbox向下一行public const int WM_VSCROLL = 0x115;
    SendMessage(listbox.Handle, WM_VSCROLL, 1, 0);
      

  2.   

      /// <summary>
            /// 写事件记录by/ http://blog.csdn.net/wyw308
            /// </summary>
            /// <param name="msg"></param>
            private void WriMsg(string msg)
            {
                bool scroll = false;
                if (this.lsb_e.TopIndex == this.lsb_e.Items.Count - (int)(this.lsb_e.Height / this.lsb_e.ItemHeight)) scroll = true;            lsb_e.Items.Add("[" + System.DateTime.Now.ToString("HH:mm:ss:fff") + "]" + msg);            if (scroll) this.lsb_e.TopIndex = this.lsb_e.Items.Count - (int)(this.lsb_e.Height / this.lsb_e.ItemHeight);
                Application.DoEvents();
            }
      

  3.   

    你可以往listbox里添加的时候插入到第一位啊....