起因
2024-08-28 19:40:20
colorDialog 打开出现的
位置控制不了
鸽子 2024-08-28 20:06:06
你是可以控制的
0:00:47
试了下没用,可能是系统 问题吧
代码
位置的设置
SetWindowPos(hWnd, IntPtr.Zero, 0, 0, 0, 0, 1);
核心代码
protected override IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
{
if (msg == WM_ACTIVATE)
SetWindowPos(hWnd, IntPtr.Zero, 0, 0, 0, 0, 1);
return base.HookProc(hWnd, msg, wparam, lparam);
}
全部代码
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
ColorDialog2 c2 = new ColorDialog2();
c2.ShowDialog();
}
private class ColorDialog2 : System.Windows.Forms.ColorDialog
{
[DllImport("user32.dll")]
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndlnsertAfter, int X, int Y, int cx, int cy, uint Flags);
const UInt32 WM_ACTIVATE = 0x0006;
protected override IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
{
if (msg == WM_ACTIVATE)
SetWindowPos(hWnd, IntPtr.Zero, 0, 0, 0, 0, 1);
return base.HookProc(hWnd, msg, wparam, lparam);
}
}
}