找回密码
 立即注册

QQ登录

只需一步,快速开始

yuye

初级会员

5

主题

12

帖子

407

积分

初级会员

积分
407

活字格认证

yuye
初级会员   /  发表于:2014-11-18 14:42  /   查看:11046  /  回复:12
如题:控件添加上去了,但是滑动滚动条的时候位置会随着改变。关键代码如下:
        #region 向指定列添加自定义控件 + public static void AddCustControl(this C1FlexGrid flex, int rowIndex, int colIndex, Control control)
        /// <summary>
        /// 向指定列添加自定义控件
        /// </summary>
        /// <param name="flex"></param>
        /// <param name="rowIndex"></param>
        /// <param name="colIndex"></param>
        /// <param name="control"></param>
        public static void AddCustControl(this C1FlexGrid flex, int rowIndex, int colIndex, Control control, int rowHeight)
        {
            HostedControl host = new HostedControl(flex, control, rowIndex, colIndex, rowHeight);
            host.UpdatePosition();
        }
        #endregion


/// <summary>
    /// HostedControl  添加自定义控件
    /// helper class that contains a control hosted within a C1FlexGrid
    /// </summary>
    internal class HostedControl
    {
        internal C1FlexGrid _flex;
        internal Control _ctl;
        internal Row _row;
        internal Column _col;
        int rowHeight;
        internal HostedControl(C1FlexGrid flex, Control hosted, int row, int col, int rowHeight)
        {
            this.rowHeight = rowHeight;

            // save info
            _flex = flex;
            _ctl = hosted;
            _row = flex.Rows[row];
            _col = flex.Cols[col];
            // insert hosted control into grid
            _flex.Controls.Add(_ctl);
        }
        internal bool UpdatePosition()
        {
            // get row/col indices
            int r = _row.Index;
            int c = _col.Index;
            if (r < 0 || c < 0) return false;

            // get cell rect
            Rectangle rc = _flex.GetCellRect(r, c, false);

            rc.Y = rowHeight * r + 2;

            // hide control if out of range
            if (rc.Width <= 0 || rc.Height <= 0 || !rc.IntersectsWith(_flex.ClientRectangle))
            {
                _ctl.Visible = false;
                return true;
            }

            // move the control and show it
            _ctl.Bounds = rc;
            _ctl.Visible = true;

            // done
            return true;
        }
    }
附图:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

12 个回复

倒序浏览
Alice
社区贡献组   /  发表于:2014-11-27 16:04:00
推荐
回复 5楼yuye的帖子

因为滚动后,其实单元格和控件的位置已经发生改变。
所以需要在AfterScroll事件里更新控件位置,调用host.UpdatePosition方法。
代码参考:
  1.         void c1FlexGrid1_AfterScroll(object sender, RangeEventArgs e)
  2.         {
  3.             host.UpdatePosition();
  4.             host1.UpdatePosition();
  5.         }
复制代码
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-11-18 19:41:00
沙发
回复 1楼yuye的帖子

感谢你的问题反馈,请问你的意思是添加自定义控件后,滚动条自动变化位置了吗?通过1#的代码并没有重现这个问题。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
yuye
初级会员   /  发表于:2014-11-21 09:37:00
板凳
您好,您给的例子我这边试了还是会这样?是什么情况呢?滚动到后面还是一样控件显示着
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2014-11-24 11:05:00
地板
回复 3楼yuye的帖子

请问,你使用的是C1的2014 V2版本么?使用的是VisualStudio的什么版本?
就这个Sample来说,具体的步骤是什么。
我帮你根据差别找找原因
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
yuye
初级会员   /  发表于:2014-11-27 09:36:00
5#
2014 v1版本,VisualStudio是2010专业版。
日期有起始日期与结束日期,我封装成自定义控件,然后把自定义控件添加到网格的单元格里面,添加成功,如果查询条件太多了,出现滚动条,我一下滑就会跟着滚动条跑了,不会固定位置。
回复 使用道具 举报
yuye
初级会员   /  发表于:2014-11-28 14:20:00
7#
UpdatePosition可行,但是在更新后看了,滑动没到顶的时候,位置还是会有点偏差
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2014-11-28 16:54:00
8#
回复 7楼yuye的帖子

UpdatePosition方法里,你设置的rectangle,会指定位置,你需要根据自己的控件大小和想要show的位置进行更改和调整。

评分

参与人数 1满意度 +5 收起 理由
yuye + 5 已解决

查看全部评分

请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
s004600
注册会员   /  发表于:2019-3-13 08:47:09
9#
Alice 发表于 2014-11-27 16:04
回复 5楼yuye的帖子

因为滚动后,其实单元格和控件的位置已经发生改变。

你好在吗? 我有个c1 的问题想咨询你 谢谢!
回复 使用道具 举报
s004600
注册会员   /  发表于:2019-3-13 08:49:57
10#
Alice 发表于 2014-11-24 11:05
回复 3楼yuye的帖子

请问,你使用的是C1的2014 V2版本么?使用的是VisualStudio的什么版本?

你好 在吗 有个棘手的c1 控件问题想咨询你 谢谢!
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部