程序运行过程中动态改变控件大小的方法

王朝c#·作者佚名  2006-12-17
窄屏简体版  字體: |||超大  

在程序运行期间改变控件大小要用到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);

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航