0

私はC#について少ししか知りません。私のコードのほとんどはグーグルから離れています。私がしようとしているのは、ウィンドウを移動することですSetWindowPos. ただし、ウィンドウを部分的に画面の外に出したいのですが、Microsoft Windows では許可されていません。以下のコードは、これまでに取得したものです。もちろん、私はグーグルで答えを検索し、答えを見つけました。私が知らないのは、これを私のプログラムに入れる方法だけです。

これをアプリケーションにどのように組み込むかを誰かに説明してもらえますか?

Google の回答:ウィンドウを画面の上部から部分的に移動します

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Data;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace WindowMover
{

    static class Logic
    {

        [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
        public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);

        public static void Main()
        {
            const short SWP_NOSIZE = 1;
            const short SWP_NOZORDER = 0X4;
            const int SWP_NOACTIVATE = 0x0010;

            Process[] processes = Process.GetProcesses("DeviceEmulator");
            foreach (var process in processes)
            {
                if (process.ProcessName == "DeviceEmulator")
                {
                    var handle = process.MainWindowHandle;
                    SetWindowPos(handle, 0, 0, 0, -100, -100, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
                }
            }
        }
    }
}
4

1 に答える 1

0
  1. 定数をクラス スコープに移動し、publicそれらの修飾子を追加します。

  2. クラスMain()から削除Logic

  3. .csファイルに保存する

  4. ファイルをプロジェクトに追加します。

  5. メイン フォーム クラスが であると仮定Form1.csし、上部に行を追加します。

    using WindowMover;

  6. Form1フォーム デザイナーでダブルクリックすると、Loadイベント ハンドラーが追加され、コード編集モードに入ります。

  7. で呼び出しSetWindowPosthis.Handle後者のパラメーターは要件によって異なります

于 2013-02-21T23:18:46.063 に答える