ツールバー(ToolStrip)の使い方

ツールバー(ToolStrip)を使うには
ToolStripコントロールをFormにドロップして配置します。

toolbar

これだけで、Form上でツールバーが表示されます。
上の画像でもわかるように▼ボタンをクリックすると
ツールバーに追加可能なコントロールの一覧が表示されます。

ここでは簡単なButtonコントロールを選んでみます。
ButtonのアイコンはButtonのImageプロパティーで適当な画像ファイルを指定します。

toolbar_open

Buttonをクリックされたら
処理を行うサンプルコードは次のようになります。

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

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

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            // ここにOpenFileDialogを使ってファイルを開く処理を記述します
            // 詳しくは別節OpenFileDialogを参照ください
        }
    }
}

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)