c#函数名和windows api为啥不兼容一下啊,

解决方案 »

  1.   

    From1.Location = new Point(x, y);
      

  2.   

    using System;
    using System.Drawing;
    using System.Windows.Forms;class Form1 : Form
    {
      Random rand = new Random();
      
      Form1()
      {
        Text = "单击窗体客户区,则窗体会随机移动,很有趣吧!";
      }
      
      protected override void OnClick(EventArgs e)
      {
        Location = new Point(rand.Next(800), rand.Next(600));
      }
      
      static void Main()
      {
        Application.Run(new Form1());
      }
    }
      

  3.   

    [DllImport("user32.dll",EntryPoint="MoveWindow")]
    public static extern int MoveWindow(int hwnd, int x, int y, int nWidth, int nHeight, int bRepaint) 
      

  4.   

    using System;
    using System.Drawing;
    using System.Windows.Forms;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);
      }
      
      protected override void OnClick(EventArgs e)
      {
        Location = new Point(rand.Next(800), rand.Next(600));
        Size = new Size(rand.Next(50,500), rand.Next(50,500));
        base.OnClick(e);
      }
      
      static void Main()
      {
        Application.Run(new Form1());
      }
    }
      

  5.   

    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());
      }
    }
      

  6.   

    To wuyi8808 (空军)这帖子推荐什么?就因为你回答出现在这里吗?!!
      

  7.   

    "单击窗体客户区,\r\n则窗体会随机移动\r\n并改变大小,\r\n很有趣吧"
    是很有趣~!
      

  8.   

    IBM dW精华技术,开发者必看 
      

  9.   

    dingd  ding   ding  ding   ding  ding  
      

  10.   

    using System;
    using System.Drawing;
    using System.Windows.Forms;class Form1 : Form
    {
      Random rand = new Random();
      
      Form1()
      {
        Text = "单击窗体客户区,则窗体会随机移动,很有趣吧!";
      }
      
      protected override void OnClick(EventArgs e)
      {
        Location = new Point(rand.Next(800), rand.Next(600));
      }
      
      static void Main()
      {
        Application.Run(new Form1());
      }
      

  11.   

    直接改变this.location 不就行了.非要api吗
      

  12.   

    直接改变this.location 不就行了.非要api吗
      

  13.   

    直接改变this.location 不就行了.非要api吗
      

  14.   

    c#函数名和windows api为啥不兼容,人家当初是要和平台无关的(通过中间语言机制)
      

  15.   

    movewindow是面向过程
    C#是面向对象