在程序运行期间改变控件大小要用到windowsapi函数
以下是主要的代码
[dllimport("user32.dll", entrypoint="getwindowlong")]
public static extern int getwindowlong (
int hwnd,
int nindex
);
[dllimport("user32.dll", entrypoint="setwindowlong")]
public static extern int setwindowlong (
int hwnd,
int nindex,
int dwnewlong
);
[dllimport("user32.dll", entrypoint="setwindowpos")]
public static extern int setwindowpos (
int hwnd,
int hwndinsertafter,
int x,
int y,
int cx,
int cy,
int wflags
);
public const int gwl_style = (-16);
public const int ws_thickframe = 0x40000;
const int swp_nosize = 0x1;
const int swp_nomove = 0x2;
const int swp_nozorder = 0x4;
const int swp_framechanged = 0x20 ;
private void button1_click(object sender, system.eventargs e)
{
int style = getwindowlong((int)this.textbox1.handle,gwl_style);
style |=ws_thickframe;
setwindowlong((int)this.textbox1.handle,gwl_style,style);
setwindowpos((int)this.textbox1.handle,(int)this.handle,0,0,0,0,swp_nozorder|swp_nosize|swp_nomove|swp_framechanged);
}
