12

画面の左下隅 (スタート ボタン) にフォームを配置しようとしています。これを実行しようとする次のコードがありますが、画面の作業領域のみを考慮に入れるため、フォームが配置されます。スタートボタンのすぐ上:

int x = Screen.PrimaryScreen.WorkingArea.Left + this.Width;
int y = Screen.PrimaryScreen.WorkingArea.Bottom - this.Height;
this.Location = new Point(x, y);

私がやろうとしていることをさらに示すために、デモ/画面を以下に示します。

【デモ画面】(http://i.stack.imgur.com/9mTjj.png)

4

4 に答える 4

11

Screen.PrimaryScreen.Boundsプロパティを使用して設定しthis.TopMost = trueます。これは機能します:

int y = Screen.PrimaryScreen.Bounds.Bottom - this.Height;
this.Location = new Point(0, y);
this.TopMost = true;
于 2012-09-09T10:25:12.747 に答える
4

通常、作業領域には、タスク バー、ドッキングされたウィンドウ、およびドッキングされたツールバーは含まれません。を使用するScreen.PrimaryScreen.Boundsと、画面の完全な高さと幅が得られます。

サンプルコードは次のとおりです。

public Form1()
        {
            InitializeComponent();
            Rectangle r = Screen.PrimaryScreen.WorkingArea;
            this.StartPosition = FormStartPosition.Manual;
            this.Location = new Point(0, Screen.PrimaryScreen.Bounds.Height - this.Height);
            this.TopMost = true;
        }

通常、タスクバーはデフォルトで一番上に設定されているため、これはおそらくタスクバーの下に表示されます。Windows XP でそのオプションをオフにするオプションがあったことを覚えていますが、確かではありません。

編集:

Windows XP では、タスクバーをウィンドウの背後に移動させることができます。リンクをたどってください:常に一番上のタスクバーに

Ria が指摘したように、this.TopMostを true に設定すると、より適切なオプションになります。

于 2012-09-09T10:23:28.137 に答える
0

Ria の答えは正しいですが、タスクバーの高さは追加されませんでした。
表示されている画像とまったく同じものが必要な場合は、次のコードを使用する必要があります。

int nTaskBarHeight = Screen.PrimaryScreen.Bounds.Bottom - 
                                            Screen.PrimaryScreen.WorkingArea.Bottom;
Rectangle workingArea = Screen.GetWorkingArea(this);
this.Location = new Point(0, workingArea.Bottom - Size.Height + nTaskBarHeight);
this.TopMost = true;
于 2012-09-09T11:20:40.500 に答える
0

このコードで試すことができます

Rectangle workingArea = Screen.GetWorkingArea(this);
this.Location = new Point(0, 
                          workingArea.Bottom - Size.Height);
于 2012-09-09T10:19:40.860 に答える