首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

movewindow api在c#中对应的函数是什么?解决方案

2012-02-12 
movewindow api在c#中对应的函数是什么?c#函数名和windows api为啥不兼容一下啊,[解决办法]C# codeFrom1.L

movewindow api在c#中对应的函数是什么?
c#函数名和windows api为啥不兼容一下啊,

[解决办法]

C# code
From1.Location = new Point(x, y);
[解决办法]
C# code
[DllImport("user32.dll",EntryPoint="MoveWindow")]public static extern int MoveWindow(int hwnd, int x, int y, int nWidth, int nHeight, int bRepaint)
[解决办法]
C# code
using System;using System.Drawing;using System.Windows.Forms;using System.Runtime.InteropServices;class Form1 : Form{  Random rand = new Random();    protected override void OnPaint(PaintEventArgs e)  {    e.Graphics.DrawString    (      "单击窗体客户区,\r\n则窗体会随机移动\r\n并改变大小,\r\n很有趣吧!",      new Font("Arial", 16),      new SolidBrush(Color.Blue),      0,      0    );    base.OnPaint(e);  }    [DllImport("user32.dll",EntryPoint="MoveWindow")]  public static extern int MoveWindow(IntPtr hwnd, int x, int y, int nWidth, int nHeight, bool bRepaint);  // 这是使用 API 的版本  protected override void OnClick(EventArgs e)  {    int x       = rand.Next(800);    int y       = rand.Next(600);    int nWidth  = rand.Next(50, 500);    int nHeight = rand.Next(50, 500);    MoveWindow(Handle, x, y, nWidth, nHeight, true);    base.OnClick(e);  }  /*  // 这是不使用 API 的版本  protected override void OnClick(EventArgs e)  {    Left   = rand.Next(800);    Top    = rand.Next(600);    Width  = rand.Next(50, 500);    Height = rand.Next(50, 500);    base.OnClick(e);  }  */    static void Main()  {    Application.Run(new Form1());  }} 

热点排行