c#创建子窗口时,子窗口无法获得焦点,总在父窗口控件的后面…… 30
父窗口调用子窗口的代码是:namespaceexperiment{publicpartialclassForm1:Form{publicForm1(){this.IsMd...
父窗口调用子窗口的代码是:
namespace experiment
{
public partial class Form1 : Form
{
public Form1()
{
this.IsMdiContainer = true;
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.MdiParent = this;
frm.Show();
frm.Focus();
}
}
}
截图: 展开
namespace experiment
{
public partial class Form1 : Form
{
public Form1()
{
this.IsMdiContainer = true;
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.MdiParent = this;
frm.Show();
frm.Focus();
}
}
}
截图: 展开
1个回答
展开全部
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
namespace TaskBarFloatWnd
{
public partial class TaskBarWnd : Office2007Form
{
public TaskBarWnd()
{
InitializeComponent();
actform = GetActiveWindow();
}
private bool isFristShow = true;//标识是否是首次加载
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern IntPtr GetActiveWindow();//获得当前活动窗体
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern IntPtr SetActiveWindow(IntPtr hwnd);//设置活动窗体
private IntPtr actform = IntPtr.Zero;//保存自己得到焦点前拥有活动窗体的柄
private void TaskBarWnd_Load(object sender, EventArgs e)
{
textBox1.Text = DateTime.Now + "——";
textBox1.Text = textBox1.Text + "目前正对网元1进行做单操作,10分钟内请大家避让";
}
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
if (isFristShow == true)
{
SetActiveWindow(actform);
isFristShow = false;
}
}
private void TaskBarWnd_FormClosing(object sender, FormClosingEventArgs e)
{
}
}
}
private void button1_Click(object sender, EventArgs e)
{
TaskBarWnd taskWnd = new TaskBarWnd();
System.Drawing.Rectangle r = System.Windows.Forms.Screen.GetWorkingArea(taskWnd);
taskWnd.Location = new System.Drawing.Point(r.Right - taskWnd.Width, r.Bottom - taskWnd.Height);
taskWnd.Show();
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
namespace TaskBarFloatWnd
{
public partial class TaskBarWnd : Office2007Form
{
public TaskBarWnd()
{
InitializeComponent();
actform = GetActiveWindow();
}
private bool isFristShow = true;//标识是否是首次加载
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern IntPtr GetActiveWindow();//获得当前活动窗体
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern IntPtr SetActiveWindow(IntPtr hwnd);//设置活动窗体
private IntPtr actform = IntPtr.Zero;//保存自己得到焦点前拥有活动窗体的柄
private void TaskBarWnd_Load(object sender, EventArgs e)
{
textBox1.Text = DateTime.Now + "——";
textBox1.Text = textBox1.Text + "目前正对网元1进行做单操作,10分钟内请大家避让";
}
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
if (isFristShow == true)
{
SetActiveWindow(actform);
isFristShow = false;
}
}
private void TaskBarWnd_FormClosing(object sender, FormClosingEventArgs e)
{
}
}
}
private void button1_Click(object sender, EventArgs e)
{
TaskBarWnd taskWnd = new TaskBarWnd();
System.Drawing.Rectangle r = System.Windows.Forms.Screen.GetWorkingArea(taskWnd);
taskWnd.Location = new System.Drawing.Point(r.Right - taskWnd.Width, r.Bottom - taskWnd.Height);
taskWnd.Show();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询