using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace sharpWin
{
/ /设置窗体可移动
// Private Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
//设置可移动
protected override void WndProc(ref Message m)
{
// base.WndProc(ref m);
const int WM_NCHITTEST = 0x84;
const int HTCLIENT = 0x01;
const int HTCAPTION = 0x02;
if (m.Msg == WM_NCHITTEST)
{
this.DefWndProc(ref m);
if (m.Result.ToInt32() == HTCLIENT)
m.Result = new IntPtr(HTCAPTION);
else
base.WndProc(ref m);
}
else
base.WndProc(ref m);
}
//设置位置最上方或者最下方
private void ShoveToBackground()
{
Win32.SetWindowPos((int)this.Handle,
Win32.HWND_BOTTOM,
0, 0, 0, 0,
Win32.SWP_NOMOVE | Win32.SWP_NOSIZE |
Win32.SWP_SHOWWINDOW);
}
private void Form1_Activated(object sender, EventArgs e)
{
ShoveToBackground();
}
private void Form1_Resize(object sender, EventArgs e)
{
ShoveToBackground();
}
}
class Win32
{
[DllImport("user32.dll", EntryPoint = "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 = -1; //最上方
//public const int HWND_BOTTOM = 0x1; //最下方
public const uint SWP_NOSIZE = 0x1;
public const uint SWP_NOMOVE = 0x2;
public const uint SWP_SHOWWINDOW = 0x40;
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace sharpWin
{
/ /设置窗体可移动
// Private Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
//设置可移动
protected override void WndProc(ref Message m)
{
// base.WndProc(ref m);
const int WM_NCHITTEST = 0x84;
const int HTCLIENT = 0x01;
const int HTCAPTION = 0x02;
if (m.Msg == WM_NCHITTEST)
{
this.DefWndProc(ref m);
if (m.Result.ToInt32() == HTCLIENT)
m.Result = new IntPtr(HTCAPTION);
else
base.WndProc(ref m);
}
else
base.WndProc(ref m);
}
//设置位置最上方或者最下方
private void ShoveToBackground()
{
Win32.SetWindowPos((int)this.Handle,
Win32.HWND_BOTTOM,
0, 0, 0, 0,
Win32.SWP_NOMOVE | Win32.SWP_NOSIZE |
Win32.SWP_SHOWWINDOW);
}
private void Form1_Activated(object sender, EventArgs e)
{
ShoveToBackground();
}
private void Form1_Resize(object sender, EventArgs e)
{
ShoveToBackground();
}
}
class Win32
{
[DllImport("user32.dll", EntryPoint = "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 = -1; //最上方
//public const int HWND_BOTTOM = 0x1; //最下方
public const uint SWP_NOSIZE = 0x1;
public const uint SWP_NOMOVE = 0x2;
public const uint SWP_SHOWWINDOW = 0x40;
}