软件中的“查找窗体”的效果,如word、visual studio等等。
注意我要实现的不是功能是窗体的效果效果描述:
1.窗体焦点
如,在VS2008中,在查找窗口打开并获得焦点的情况下,点工具栏上的调试按钮马上可以进入调试状态,而且点击操作不会让查找窗口失去焦点,也不会使主界面窗体获得焦点。 而在我做的系统中,必须点击两次才能触发主界面工具栏上的按钮,第一次点击使主界面获得焦点,第二次点击才能真正触发工具栏中的按钮操作。
2.窗口活动范围
如,word中的查找窗体是可以任意拖动的(可以是整个桌面范围),它不可能是MDI子窗体,因为MDI子窗体是不可能拖出主界面的。
请各位高人帮帮兄弟吧,让我安心过个十一吧!!!(如果感觉描述的不清楚,请参见上帖:http://topic.csdn.net/u/20090925/17/a4bd0aea-62fc-4e04-9bd9-0e50d4e29e4d.html)
解决方案 »
- 把Excel的数据导入GridView中的问题,急人啊!!
- 打開excel問題
- How to ArrayList convert to DataTable?
- IBatisNet偶尔会出现这个错:Could not load type from string value 'Domain.Adv'
- c#与.net的关系?
- asp.net 2.0首页因为查询数据库显示较慢,怎样在读取过程中显示“请稍侯。。。”
- C#绘制时钟时出现闪烁,自己试着用双缓冲也没有解决,大家帮忙看看怎么回事,谢谢了!
- 请教一个session的问题!!
- 一个报表的打印程序,做了个安装程序,在另一台机器安装后不能正常运行
- C#必败(之四)!!!!!!
- 定义一个动态二维数组
- 菜鸟问题:sqldatareader 没有 HasRows 属性(for windows mobile)
在FORM中加入一字段判断是否被点击过,也就是在所有的按钮的EVENT前全部都加一个判断是否被点击过的委托,如果被点击过才能够执行接下来的东西。在FORM上加一个透明的什么东西。点了后才消失
2、MDI子窗体也是可以拖动的。
Form2 f2 = Form2.CreateStance;
f2.Owner = this;
f2.Show();
1.顶不顶层跟焦点没什么关系,我只想点一次就可以触发主界面中工具栏的按钮
2.帖中已指出 MDI子窗体的活动范围是很有限的,它是不可能被拖出主界面的,而word中的查找窗口是可以再桌面任意拖动的。同样感谢!
已在上帖中说明,http://topic.csdn.net/u/20090925/17/a4bd0aea-62fc-4e04-9bd9-0e50d4e29e4d.html,同样感谢。现在关键是焦点问题,怎样才能点击一次就能打开主界面上的菜单,就能触发主界面上的工具栏命令,
是不是必须通过 windows API 实现?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication11
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); ToolBar TB = new ToolBar();
TB.Parent = this;
TB.Buttons.Add("button1");
TB.ButtonClick += new ToolBarButtonClickEventHandler(TB_ButtonClick); Form F = new Form();
F.TopMost = true;
F.Size = new Size(200, 100);
F.StartPosition = FormStartPosition.CenterParent;
F.Show();
} void TB_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
{
MessageBox.Show(e.Button.Text);
}
}
}点击一次就能运行啊
ToolStripMenuItem。
DllImport("user32.dll", CharSet = CharSet.Auto)]
public extern static IntPtr SetParent(IntPtr hChild, IntPtr hParent);
等实现窗体的布局
那是ToolBar的效果,让ToolBar不获得焦点,而不是窗体的问题
http://msdn.microsoft.com/zh-cn/library/ms171543(VS.80).aspx
//试试下面的,可以达到你的要求.
int i = 0; private void toolStripButton1_Click(object sender, EventArgs e)
{
btnClick();
} public void btnClick()
{
MessageBox.Show("OK");
} private void toolStripButton1_MouseMove(object sender, MouseEventArgs e)
{
i = 1;
} private void Form1_Activated(object sender, EventArgs e)
{
//如果工具栏有多个按钮,那就用多个变量,参照如此方法.
if (i == 1)
{
btnClick();
}
} private void toolStripButton1_MouseLeave(object sender, EventArgs e)
{
i = 0;
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
ToolStrip TS = new ToolStrip(); public Form1()
{
InitializeComponent(); TS.Parent = this; ToolStripButton TSB = new ToolStripButton();
TSB.Text = "button1";
TS.Items.Add(TSB); Form F = new Form();
F.TopMost = true;
F.Size = new Size(200, 100);
F.StartPosition = FormStartPosition.CenterParent;
F.Show(); this.Activated += new EventHandler(ToolStripButtonClick);
} void ToolStripButtonClick(object sender, EventArgs e)
{
Point P = TS.PointToClient(Control.MousePosition);
foreach (ToolStripItem TSI in TS.Items)
if (TSI.Bounds.Contains(P))
MessageBox.Show(TSI.Text);
}
}
}
1、建议楼主参看 NativeWindow 的相关说明。
2、然后研究 DockWindow 的工作原理,这都不是一两句话可以解决的。
2.show一个新窗体
int i = 0; public Form2 frm; private void button1_Click(object sender, EventArgs e)
{
frm = new Form2();
frm.TopMost = true;
frm.Show();
} private void toolStripButton1_Click(object sender, EventArgs e)
{
btnClick();
} public void btnClick()
{
MessageBox.Show("OK");
} private void toolStripButton1_MouseMove(object sender, MouseEventArgs e)
{
i = 1;
} private void Form1_Activated(object sender, EventArgs e)
{
//如果工具栏有多个按钮,那就用多个变量,参照如此方法.
if (i == 1)
{
btnClick();
frm.Focus();
}
} private void toolStripButton1_MouseLeave(object sender, EventArgs e)
{
i = 0;
}
我还需要在 frm 中弹出其他的窗体,弹出的窗体还要具有同样的效果。
也就是说,用户只点了一下,但是实际上却是点了两下,而且在点完之后你的查找窗口立刻又获得了焦点,所以在用户看起来就好像从没失去过焦点一样
foreach (Control c in this.Controls)
{
if (c.Name == "记录的变量值")
{
c.Focus();
}
}