此问题曾困扰了几天的时间,通过网上搜索相关文章,终于解决!庆幸不已!我在想C#也算是高级语言,为什么会出现这个问题,令人费解!
问题描述:在子窗体有边框的情况下,还要可以使用鼠标选取文本!
解决方案:父窗体、子窗体都是普通窗体(非MDI窗体),在调用子窗体时,使用下列代码:
zxsj = new zxsj_edit();
zxsj.TopLevel =true;
zxsj.Dock = DockStyle.None;
//zxsj.FormBorderStyle = FormBorderStyle.None;
SetParent(zxsj.Handle.ToInt32(), this.Handle.ToInt32());
//zxsj.Parent = this;
zxsj.StartPosition = FormStartPosition.CenterParent;
zxsj.BringToFront();
zxsj.Size = new Size(zxsj.Width < this.Size.Width ? zxsj.Width : this.Width, zxsj.Height < this.Size.Height ? zxsj.Height : this.Height);
zxsj.Location = new Point((this.Width - zxsj.Width) / 2, (this.Height - zxsj.Height) / 2 - 20);
zxsj.FormClosed += main_form_state_recover_zxsj1;
zxsj.TopMost = true;
zxsj.Show();
///以下为SetParent函数的引用方法:
[DllImport(“user32”)]
public static extern int SetParent(int hWndChild, int hWndNewParent);