c#怎样实现窗体总在最后?,注意是最后!最底层!最下面!
展开全部
呵呵,前几天刚写了这个功能,没想到有人提问了
打包散缓票,绝对可用!!
【有疑问可以HI我,或追问,但请不要关闭问题,谢谢!】
class Win32
{
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetWindowPos")]
//import the native SetWindowPos function--导入SetWindowPos这个函数姿悉
public static extern bool SetWindowPos( int hWnd, //迹掘乎 window handle
int hWndInsertAfter, // placement-order handle
int X, // horizontal position
int Y, // vertical position
int cx, // width
int cy, // height
uint uFlags); // window positioning flags
public const int HWND_BOTTOM = 0x1;
public const uint SWP_NOSIZE = 0x1;
public const uint SWP_NOMOVE = 0x2;
public const uint SWP_SHOWWINDOW = 0x40;
}
//Implement a helper method (ShoveToBackground) to call the SetWindowPos function at the appropriate times. --用一个函数帮助我们调用这个API函数
private void ShoveToBackground()
{
Win32.SetWindowPos((int)this.Handle, Win32.HWND_BOTTOM, 0, 0, 0, 0, Win32.SWP_NOMOVE | Win32.SWP_NOSIZE | Win32.SWP_SHOWWINDOW);
}
//Finally, implement handlers for the form's Activate and Resize events and have them both simply call the helper ShoveToBackground method. --最后在Activate and Resize 事件里调用它就可以了
private void Form1_Activated(object sender, System.EventArgs e)
{
ShoveToBackground();
}
private void Form1_Resize(object sender, System.EventArgs e)
{
ShoveToBackground();
}
打包散缓票,绝对可用!!
【有疑问可以HI我,或追问,但请不要关闭问题,谢谢!】
class Win32
{
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetWindowPos")]
//import the native SetWindowPos function--导入SetWindowPos这个函数姿悉
public static extern bool SetWindowPos( int hWnd, //迹掘乎 window handle
int hWndInsertAfter, // placement-order handle
int X, // horizontal position
int Y, // vertical position
int cx, // width
int cy, // height
uint uFlags); // window positioning flags
public const int HWND_BOTTOM = 0x1;
public const uint SWP_NOSIZE = 0x1;
public const uint SWP_NOMOVE = 0x2;
public const uint SWP_SHOWWINDOW = 0x40;
}
//Implement a helper method (ShoveToBackground) to call the SetWindowPos function at the appropriate times. --用一个函数帮助我们调用这个API函数
private void ShoveToBackground()
{
Win32.SetWindowPos((int)this.Handle, Win32.HWND_BOTTOM, 0, 0, 0, 0, Win32.SWP_NOMOVE | Win32.SWP_NOSIZE | Win32.SWP_SHOWWINDOW);
}
//Finally, implement handlers for the form's Activate and Resize events and have them both simply call the helper ShoveToBackground method. --最后在Activate and Resize 事件里调用它就可以了
private void Form1_Activated(object sender, System.EventArgs e)
{
ShoveToBackground();
}
private void Form1_Resize(object sender, System.EventArgs e)
{
ShoveToBackground();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-04-22
展开全部
哇靠。二楼lchy0987真是高手,学习了!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
引用:
using System.Runtime.InteropServices;
在定义部分引入下面两个函数:
[DllImport("user32")]
private static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
[DllImport("user32")]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
在窗体On_Load事中改件卖银判中添加代搏薯码:
IntPtr hDeskTop=FindWindow("Progman", "Program Manager");
SetParent(this.Handle,hDeskTop);
using System.Runtime.InteropServices;
在定义部分引入下面两个函数:
[DllImport("user32")]
private static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
[DllImport("user32")]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
在窗体On_Load事中改件卖银判中添加代搏薯码:
IntPtr hDeskTop=FindWindow("Progman", "Program Manager");
SetParent(this.Handle,hDeskTop);
更多追问追答
追问
试了不行呀 窗体直接不显示了 ,能再解答下吗?
追答
ntPtr hDeskTop=FindWindow("Progman", "Program Manager"); 这句是你的窗体名字啦。。其实。这句是找到你的窗体句柄。。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询