用户控件动态控件将置于其他父控件的前面 [英] User Control dynamic Control to be Bring to front of other Parent Control

查看:96
本文介绍了用户控件动态控件将置于其他父控件的前面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用textBox构建了一个用户控件,并生成了动态代码生成的DataGridView
我已经设置了所有属性,并根据自己的要求很好地工作.我只想单击文本框,它将在显示帮助时显示为datagridview,而在失去焦点后隐藏文本框以隐藏datagridview.

但是问题是DatagridView数据不在其他父窗体控件之上.所有事件均正常运行.如何将其显示在屏幕前.
usercontrol文本框正常工作并显示正常吗?

我在Plz下方发布我的代码帮我吗?
仅比我的用户控件落后一步..

I have Build a user control with textBox and dynamic code generated DataGridView
I have set all its Properties and working according to my requirement well. I just want to click the textbox and it will display help as datagridview and after lost focus of textbox to hide datagridview.

But the problem is that DatagridView data are not Coming above the other parent form control. All its event working fine .How to bring it on front of the screen.
usercontrol textbox working and display fine ?

I am posting my code below Plz Help me ?
only i am one step behind my user control..

namespace textGrid
{
    public partial class CustText : UserControl
    {
        #region Variable
        DataTable dtfil = new DataTable();
        DataTable dtstr = new DataTable();
        BindingSource bSource = new BindingSource();
        Point GvPos;
     
       DataGridView gv = new DataGridView();
       
        Boolean Req = false, Act_Code = true;
      
        string _SelVal;
        string _DisplayMember;
        string _ValueMember;
        string _text;
        string filterFld = "";
            string valfld = "";
            int num = 0;
        #endregion

        public CustText()
        {
            this.gv.Visible = false;
            gv.TabIndex = TabIndex;
           // gv.Enabled = false;
           // gv.Enter += new System.EventHandler(this.gv_Enter);
            this.gv.Size = new System.Drawing.Size(180, 140);
            gv.MouseClick += new System.Windows.Forms.MouseEventHandler(this.gv_MouseClick);
            gv.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.gv_MouseDoubleClick);
            gv.KeyDown += new System.Windows.Forms.KeyEventHandler(this.gv_KeyDown);
            gv.Leave += new System.EventHandler(this.gv_Leave);
            gv.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.gv_KeyPress);
            gv.BringToFront();
            gv.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
            Controls.Add(gv);
       
            InitializeComponent();
        }

        //unrelated code removed
}

推荐答案

下次,仅提供与您的问题直接相关的代码.该代码中的大多数与您的问题无关.

现在,要回答您的问题,请使用
Next time, only provide the code that is directly related to your question. The majority of that code has nothing to do with your question.

Now, to answer your question, use
this.Controls.SetChildIndex(gv,0);


将其添加到控件集合后.这将告诉UserControl首先绘制它.

另外,作为国际雪联,打电话给
也不是一个好习惯


after you add it to the controls collection. This will tell the UserControl to draw it first before anything else.

Also, as an FYI, it is not good practice to call

DataGridView gv = new DataGridView();


在方法之外.那应该真的放在构造函数内部.

您仍然可以在全局范围内声明gv,但不应该在方法外部调用new.


outside of a method. That should really be placed inside the contstructor.

You can declare gv globally still, but you shouldn''t call new outside of a method.


您好

澄清:

要获得控制权,只需添加以下行

gv.BringToFront();

创建新实例后;

DataGridView gv =新的DataGridView();

看起来应该像这样:

Hi

to clarify:

To get control to front just add the line

gv.BringToFront();

after making new instance;

DataGridView gv = new DataGridView();

This should look like this:

DataGridView gv = new DataGridView();
gv.BringToFront();



这应该有帮助.

问候



this should help.

regards


尝试设置动态控件的zindex.
在msdn上搜索以阅读/了解有关此属性的更多信息.
Try setting the zindex of the dynamic control.
Search on msdn to read / learn more about this property.


这篇关于用户控件动态控件将置于其他父控件的前面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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