求教如何让frame刷新父页面中左右2个页面滚动条同步滚动

拒绝访问 | www.weste.net | 百度云加速
请打开cookies.
此网站 (www.weste.net) 的管理员禁止了您的访问。原因是您的访问包含了非浏览器特征(a6164d-ua98).
重新安装浏览器,或使用别的浏览器C#超简单方法实现两个richtextbox控件滚动条同步滚动 - 鲁广广 - 博客园
随笔 - 20, 文章 - 0, 评论 - 0, 引用 - 0
& & & & & & & & 此文章属于作者原创,转载请注明,谢谢
  有时候我们需要实现对照文章等,往往将文本放到两个richtextbox控件中,但是,如果我们需要同步滚动查看,来达到更好的观看效果。
当然,传统的方法重载控件或者自定义控件都可以达到目的,但是对于新手或者想仅仅只用一次这个控件的人来说,是非常麻烦的。所以,接
下来我来提供一种简单快捷的方法来实现:richtextbox滚动条同步的功能。
首先,我们在winform窗体创建两个richtextbox控件
下面介绍两个方法,我经常用到
第一个方法,获得当前鼠标所在richtextbox控件中的行号
<span style="color: #
private int GetLineNoVscroll(RichTextBox rtb)
<span style="color: #
<span style="color: #
//获得当前坐标信息
<span style="color: #
Point p = rtb.L
<span style="color: #
int crntFirstIndex = rtb.GetCharIndexFromPosition(p);
<span style="color: #
int crntFirstLine = rtb.GetLineFromCharIndex(crntFirstIndex);
<span style="color: #
return crntFirstL
<span style="color: #
第二个方法,快速转到richtextbox控件中某行
private void TrunRowsId(int iCodeRowsID, RichTextBox rtb)
rtb.SelectionStart = rtb.GetFirstCharIndexFromLine(iCodeRowsID);
rtb.SelectionLength = <span style="color: #;
rtb.ScrollToCaret();
<span style="color: #
<span style="color: #
<span style="color: #
<span style="color: #
  有了这两个方法,我们就可以实现滚动条同步的功能了。
  思路如下:第一,当richtextbox1滚动时,通过GetLineNoVscroll方法,获得richtextbox1的鼠标对应行号。然后
通过TrunRowsId方法,将获得的richtexbox1的行号定位到richtextbox2中,从而达到richtextbox2跟着richtexbox1
滚动条一起滚动;
  在richTextBox1的VScroll事件中添加如下代码,注意,我这里有个?,代表某个偏移量,可能因为布局原因(如控件大小等)
导致两个richtextbox不同步,一般写0就可以了,如果差距过大,自行调整数值。
<span style="color: #
private void richTextBox1_VScroll(object sender, EventArgs e)
<span style="color: #
<span style="color: #
int crntLastLine= GetLineNoVscroll(richTextBox1, panel1)-?;
<span style="color: #
TrunRowsId(crntLastLine, richTextBox2);
<span style="color: #
最后,实现了两个滚动条同步滚动
如果大家发现有其他问题,请在下方留言。本人刚开博客不久,大家互相学习,共同成长,谢谢博客分类:
我在一个页面中有两个iframe,这两个是并列的,一个在左边显示person的数据,一个在右边显示cell的数据,如果被引用的页面数据太大,就会被截掉,但是设置scrolling=“auto”的话,双会出现两个滚动条。在网上查了一下代码,大概有两种方式可以实现
方法一.被引用的页面是静态的高度
//获取被包含的页面的静态高度,来设置iframe的高度
function setFirstIframeHeight(value){
if(value=="person"){
var personHeight = jQuery('#person').contents().find("meta").attr("content");
jQuery('#person').height(personHeight);
}else if(value=="cell"){
var cellHeight = jQuery('#cell').contents().find("meta").attr("content");
jQuery('#cell').height(cellHeight);
主页面代码
&table class="result" width="100%" cellpadding="0" cellspacing="0"&
&td width="49%"&
&iframe name="person" id="person" frameborder="0"
onload="setFirstIframeHeight('person')" scrolling="no" width="100%" height="500"&
&td width="2%"&&&/td&
&td width="49%"&
&iframe name="cell" id="cell" frameborder="0"
onload="setFirstIframeHeight('cell')" scrolling="no" width="100%" height="500"&
&/table&
被引用的页面中要加入:
&meta content="text/ charset=UTF-8; 750px"/&
实现原理是,当主页面中的iframe在加载的时候,调用onload里面的js代码,获取被引入页面的高度,并把这个高度值赋给iframe,这样当被引入的页面的高度超过iframe的高度时,就会在两个iframe的外面出现滚动条
但是这个方法不能获取未知高度的子页面的height值,当被引入的页面高度不能用content:xxxpx来表示时,这个方法就不适用了,于是出现了第二种方法
方法二、利用Interval来实现
&table class="result" width="100%" cellpadding="0" cellspacing="0"&
&td width="49%"&
&iframe name="person" id="person" frameborder="0"
scrolling="no" width="100%" height="500"
onload="this.height=this.contentWindow.document.documentElement.scrollHeight" &
&script type="text/javascript"&
//动态获取被引用的页面的高度
function reinitIframe1(){
var iframe = document.getElementById("person");
var bHeight = iframe.contentWindow.document.body.scrollH
var dHeight = iframe.contentWindow.document.documentElement.scrollH
var height = Math.max(bHeight, dHeight);
iframe.height =
}catch (ex){}
window.setInterval("reinitIframe1()", 200);
&td width="2%"&&&/td&
&td width="49%"&
&iframe name="cell" id="cell" frameborder="0"
scrolling="no" width="100%" height="500"
onload="this.height=this.contentWindow.document.documentElement.scrollHeight" &
&script type="text/javascript"&
//动态获取被引用的页面的高度
function reinitIframe2(){
var iframe = document.getElementById("cell");
var bHeight = iframe.contentWindow.document.body.scrollH
var dHeight = iframe.contentWindow.document.documentElement.scrollH
var height = Math.max(bHeight, dHeight);
iframe.height =
}catch (ex){}
window.setInterval("reinitIframe2()", 200);
浏览: 201596 次
来自: 西安
楼主讲的很详细mark
查询:数据-》xml-》POJO的setter插入:POJO的 ...
chengxiaohu66 写道请问能发下userAnalys ...
楼主解决了吗?我也遇到这个问题了
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'如何让两个控件的滚动条同步_百度知道
如何让两个控件的滚动条同步
我有更好的答案
如果矩形是GDI+自己绘制的 那你必须自己定义一个滚动条来决定大小.. 另一个简单的办法..在绘制的最下边添加一个Label控件.设置大小为0,0 然后设置AutoScrool为true就可以了.
采纳率:90%
来自团队:
为您推荐:
其他类似问题
&#xe675;换一换
回答问题,赢新手礼包&#xe6b9;
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。vb如何让窗口内的内容随着滚动条一起滚动,frame的用法_vb吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:107,991贴子:
vb如何让窗口内的内容随着滚动条一起滚动,frame的用法收藏
想做个小型的计算程序,但是输入数据比较多。于是想在窗口内建立滚动条。拖动滚动条来控制窗口。本来以为会很麻烦的用滚动条控件来控制所有的控件的top属性。但其实异常的简单。只需要用frame控件把你想要的控件套住,只调节frame的top属性即可。看来编程还是需要脑袋灵光啊,有此感想与君分享!楼下赋简单代码。。高手勿笑
通用软件不合适,定做软件太昂贵,自己用vb.net开发太难,何不试试FoxTable?
Private Sub VScroll1_Change()Frame1.Top = -VScroll1.ValueEnd Sub
很好很好,你也可以用图片框装载所有其他控件,道理同frame
单个控件随scrollbar滚动:多个控件随scrollbar滚动
登录百度帐号

我要回帖

更多关于 frame框架页面实例 的文章

 

随机推荐