2018년 11월 22일 목요일

[C#] ToolStrip Example



1. ToolStrip Example

1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Windows.Forms;

namespace CsLib
{
    class CsToolBar
    {
        ToolStrip toolbar;

        public CsToolBar()
        {
            toolbar = new ToolStrip();
            toolbar.Items.Clear();
        }

        public ToolStrip get()
        {
            return toolbar;
        }


        public ToolStripButton addToolbarButton(String text, EventHandler handler)
        {
            ToolStripButton button = new ToolStripButton();
            button.Name = text;
            button.Text = text;
            if (handler != null)
            {
                button.Click += handler;
            }
            toolbar.Items.Add(button);
            return button;
        }

        public ToolStripTextBox addToolbarTextBox(String text, KeyEventHandler handler)
        {
            ToolStripTextBox textbox = new ToolStripTextBox();
            textbox.Name = text;
            textbox.Text = "";
            textbox.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left;
            textbox.Dock = DockStyle.Fill;
            if (handler != null)
            {
                textbox.KeyDown += handler;
            }
            toolbar.Items.Add(textbox);
            return textbox;
        }
        /*
        private void addrHandler(object source, KeyEventArgs e) {
            if (e.KeyCode == Keys.Enter) {
                web.Navigate(addr.Text);
            }
        }
        */

        public void addToolItem(String name, EventHandler handler)
        {
            ToolStripItem item = new ToolStripMenuItem();
            item.Tag = "toolitem";
            item.Name = name;
            item.Text = name;
            if (handler != null)
            {
                item.Click += handler;
            }
            toolbar.Items.Add(item);
        }
    }
}

댓글 없음:

댓글 쓰기