张静茹作者
11年1个月前IP:山东
796092
9楼
引用 acmilan:
mfc的CEditView实现了查找和替换功能,mfc的完整源代码可在vc/atlmfc/src找到。

只用SetWindowText改变Text还是会自动把光标设置为0 滚动条在最上面,使用你的SetWindowText和我原来办法就完美了~~~
        [DllImport("user32.dll", EntryPoint = "SetWindowText", CharSet = CharSet.Ansi)]
        public static extern int SetWindowText(int hwnd, string lpString);
private void button1_Click(object sender, EventArgs e)
{
    int TextBoxSouSelectionStart = textBox1.SelectionStart;//TextBoxSou光标位置    
    int TextBoxSouSelectionLength = textBox1.SelectionLength;//TextBoxSou选中长度  
    int TextBoxSouScrollPos = GetScrollPos((int)textBox1.Handle, 1);//TextBox滚动条位置 
  
    SetWindowText((int)textBox1.Handle, textBox1.Text + "\r\n" + (Convert.ToUInt32(textBox1.Lines[textBox1.Lines.Length - 1]) + 1));
    textBox1.Focus();
  
    textBox1.SelectionStart = TextBoxSouSelectionStart;
    textBox1.SelectionLength = TextBoxSouSelectionLength;
    SetScrollPos(textBox1.Handle, 1, TextBoxSouScrollPos, true);
    SendMessage(textBox1.Handle, 0x00B6, 0, TextBoxSouScrollPos);
}
评论
文号 / 796092

千古风流
名片专栏发私信
学术分 1
总主题 146 帖总回复 1873 楼拥有证书:进士 学者 机友 笔友
注册于 2010/12/30 03:32:26最后登录 2026/06/20 19:33:53
主体类型:个人
所属领域:无
认证方式:手机号
IP归属地:0

个人简介

暂未填写
笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的