滚动富文本框时如何移动按钮和文本框 [英] How to move button and textbox while scrolling richtext box

查看:115
本文介绍了滚动富文本框时如何移动按钮和文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在RichTextBox中添加了标签控件,按钮控件和文本框控件,但是当文本增加时
并出现滚动条,则标签控件按钮控件和文本框控件不随
滚动 文字....任何机构都可以提出解决方案吗...

我真的会非常感激

问候,
阿亚兹·艾哈迈德(Ayaz ahmed)

我尝试过的事情:

我想使它们像Google和youtube滚动选项一样可移动

Hi,
I have added a label control, button control and textbox control in RichTextBox, but when text increases
and scroll bar appears, the label control button control and textbox control does not scroll with the
text.... Can any body suggest a solution for this...

I will be really thankfull

Regards,
Ayaz ahmed

What I have tried:

i want to make them moveable just like google and youtube scrolling option

推荐答案

首先,您应该通过调用
将Button带到RichTextBox的前面
At first you should bring you Button to front of RichTextBox by calling
Button.BringToFront();


然后,您订阅RichTextBox VScroll事件


Then you subscribe to RichTextBox VScroll event

RichTextBox.VScroll+= RichTextBox_VScroll;


在此事件中,调用ScrollBar的实际位置,请参见GetScrollPos()方法
最后,使用HorizontalPositionVerticalPosition
计算并设置Button的位置


in this Event call the actual ScrollBar position see GetScrollPos() Method
At last calculate and set the Button location by using HorizontalPosition and VerticalPosition

private void RichTextBox_VScroll(object sender, EventArgs e)
{
   var X_POS = //calculate it by using HorizontalPosition
   var Y_POS = //calculate it by using VerticalPosition
   Button.Location = new System.Drawing.Point(X_POS, Y_POS);
}



要获取滚动条位置,请使用以下代码段



To get scrollbar position use this code snippet

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetScrollPos(IntPtr hWnd, int nBar);

private const int SB_HORZ = 0x0;
private const int SB_VERT = 0x1;
    
public int HorizontalPosition
{
    get { return GetScrollPos((IntPtr)this.Handle, SB_HORZ); }
}

public int VerticalPosition
{
    get { return GetScrollPos((IntPtr)this.Handle, SB_VERT); }
}


这篇关于滚动富文本框时如何移动按钮和文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆