我通过override WndProc对非客户区进行重绘,自己在最小化按钮的旁边画了一个按钮,但位置是用的this.Width - 95,不知道怎么取到最小化按钮的Location,望高手指点!ps:用SystemInfomation.CaptionButtonSize.Width * 3 + SystemInfomation.Border3DSize.Width需要在win2000的界面模式,连Xp都不支持,而且取出来的偏移量也是有误差的。
调试欢乐多
相似例子自己看
4页的回复我全看了,没有获取minimizeButton位置的啊,非客户区绘图我也可以了,我是想紧挨着最小化按钮,如果估计一个位置,不同的操作系统下岂不是会乱?谢谢了!
public partial class Form1 : Form
{
const int WM_NCCALCSIZE = 0x83;
const int WM_NCPAINT = 0x0085;
const int WM_NCACTIVATE = 0x0086;
const int WM_NCMOUSEMOVE = 0x00A0;
const int WM_NCLBUTTONDOWN = 0x00A1;
const int WM_NCLBUTTONDBLCLK = 0x00A3;
const int WM_SIZE = 0x0005;
const int WM_PAINT = 0x000F;
const int WM_WINDOWPOSCHANGING = 0x0046; Brush b;
public Form1()
{
InitializeComponent();
b = Brushes.Red;
} [DllImport("user32")]
public static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport("user32")]
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch (m.Msg)
{
case WM_NCPAINT:
case WM_NCACTIVATE:
IntPtr hdc = GetWindowDC(this.Handle);
Graphics g = Graphics.FromHdc(hdc);
g.FillRectangle(b, 60, 5, 80, 16);
g.Dispose();
ReleaseDC(this.Handle, hdc);
break;
}
}
}
首先谢谢 楼上兄弟的回复,我就是这么写的,问题在于,g.FillRectangle(b, 60, 5, 80, 16);这一句,60,5这些数字不都是自己写的么?怎么知道minimizeButton的位置,然后紧挨着它画一个按钮?不要告诉我要所有按钮都自己重画!!我不是要做windows的皮肤,只想加个按钮而已,就这么难么?
用SystemInformation.CaptionButtonSize.width * 3就大概差不多了,但这是在未使用主题(或者说使用类似2000的经典主题)的情况下,使用主题后就不对了。相差甚大,很难看
期待高人出现。。