プロが教える店舗&オフィスのセキュリティ対策術

前略
・C#の初心者です。
・タスクバーは下記のプログラムで非表示とすることができますが、同時にタイトルバーも消えてしまいます。タスクバーは非表示で、右端に閉じる・最大化・最小化アイコン("X"、 "□"、"_")のないタイトルバーを表示したいのですが、その方法をおしえてください。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace noTaskbar
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

this.FormBorderStyle = FormBorderStyle.None;//タイトルバー&タスクバー非表示
this.WindowState = FormWindowState.Maximized;//
}
}
}


以上、よろしくお願いします

A 回答 (2件)

「タスクバーを表示しない」だったんですね。


「タスクバーに表示しない」と勘違いしてました。要はフルスクリーンモードにしたいということですよね。

APIを使用して、
(1)「タスクバーを自動的に隠す」に設定にする。
(2) タスクバーを非表示にする。
(3) フォームを最大表示にする。

とするとタイトルバーありの状態でタスクバーを非表示にできるようです。

using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, IntPtr lpWindowName);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

private const int SW_HIDE = 0;
private const int SW_NORMAL = 1;

[StructLayout(LayoutKind.Sequential)]
struct APPBARDATA
{
public int cbSize;
public IntPtr hwnd;
public uint uCallbackMessage;
public uint uEdge;
public Rectangle rc;
public int lParam;
};

private const int ABM_SETSTATE = 10;
private const int ABS_AUTOHIDE = 1;
private const int ABS_ALWAYSONTOP = 2;

[DllImport("shell32.dll")]
static extern int SHAppBarMessage(int msg, ref APPBARDATA pbd );

public Form1()
{
InitializeComponent();

// 「タスクバーを自動的に隠す」
APPBARDATA abd = new APPBARDATA();
abd.cbSize = Marshal.SizeOf(abd);
abd.lParam = ABS_AUTOHIDE;
SHAppBarMessage(ABM_SETSTATE, ref abd);

// タスクバーを非表示
ShowWindow(FindWindow("Shell_TrayWnd", IntPtr.Zero), SW_HIDE);

// コントロールボックスを非表示
this.ControlBox = false;

// 最大表示
this.WindowState = FormWindowState.Maximized;
}

private void button1_Click(object sender, EventArgs e)
{
// タスクバーを常に表示
APPBARDATA abd = new APPBARDATA();
abd.cbSize = Marshal.SizeOf(abd);
abd.lParam = ABS_ALWAYSONTOP;
SHAppBarMessage(ABM_SETSTATE, ref abd);

// タスクバーを表示
ShowWindow(FindWindow("Shell_TrayWnd", IntPtr.Zero), SW_NORMAL);

// フォームを閉じる
this.Close();
}
}
}
    • good
    • 0
この回答へのお礼

前略
・希望通りの、タスクバー非表示、タイトルバー表示となるプログラムであることを確認しました。
 大変感謝しております。

以上 

お礼日時:2012/04/15 23:50

public Form1()


{
InitializeComponent();

this.ControlBox = false;
this.ShowInTaskbar = false;
}

でどうでしょうか。
    • good
    • 0
この回答へのお礼

前略
・さっそく 回答ありがとうございます。
・回答のコードではタスクバーは消えません。tsukasa-12rさんは実際に実行して
 消えたのでしょうか? 
 

お礼日時:2012/04/15 21:36

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!