コード例 #1
0
    /////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    /// Initializes UI components of the DetailsForm.
    /// </summary>
    /// <remarks>
    /// Sets the FirstField control and creates ButtonPanel.
    /// </remarks>
    ///
    protected override void InitializeComponents()
    {
        FirstField = MdiForm.Children[0] as Control;

        foreach (var child in MdiForm.Children)
        {
            Control ctrl = child as Control;
            if (ctrl != null && ctrl.TabStop)
            {
                FirstField = ctrl;
                break;
            }
        }

        FirstField.Focus();

        /////////////////////////////////////////////////////////////////////////////////

        if (Em.IsTextUI)
        {
            MdiForm.ForeColor = Color.DarkCyan;
        }

        /////////////////////////////////////////////////////////////////////////////////
        // Buttons

        Button_OK = new MyButton()
        {
            AutoSize = true, TabStop = false
        };
        Button_Locker = new MyButton()
        {
            AutoSize = true, TabStop = false
        };
        Button_Delete = new MyButton()
        {
            AutoSize = true, TabStop = false
        };
        Button_Link = new MyButton()
        {
            AutoSize = true, TabStop = false
        };
        Button_Info = new MyButton()
        {
            AutoSize = true, TabStop = false
        };
        Button_Cancel = new MyButton()
        {
            AutoSize = true, TabStop = false
        };

        /////////////////////////////////////////////////////////////////////////////////

        Button_OK.Click += delegate
        {
            if (ReadOnly)
            {
                QuitForm();
            }
            else
            {
                SaveAndLock();
            }
        };

        Button_Locker.Click += (sender, e) => ToggleReadOnlyMode();
        Button_Delete.Click += (sender, e) => RaiseDeleteClick();
        Button_Link.Click   += (sender, e) => RaiseLinkClick();
        Button_Info.Click   += (sender, e) => RaiseInfoClick();
        Button_Cancel.Click += (sender, e) => QuitForm();

        /////////////////////////////////////////////////////////////////////////////////

        buttonCollection = new MyButton[]
        {
            Button_OK,
            Button_Locker,
            Button_Delete,
            Button_Link,
            Button_Info,
            Button_Cancel,
        };

        /////////////////////////////////////////////////////////////////////////////////

        #if TEXTUI
        MdiForm.DrawFrame(1, MdiForm.Height - 4, MdiForm.Width - 2, 1);
        #else
        MdiForm.Controls.Add(new MyLineSeparator()
        {
            Dock = DockStyle.Bottom
        });

        ButtonPanel = new FlowLayoutPanel()
        {
            Dock    = DockStyle.Bottom, AutoSize = true,
            Padding = new Padding(2 * Em.Width, Em.Height / 2, 0, Em.Height / 2),
            TabStop = false, TabIndex = 10000,
        };

        MdiForm.Controls.Add(ButtonPanel);
        #endif

        /////////////////////////////////////////////////////////////////////////////////

        base.InitializeComponents();
    }
コード例 #2
0
ファイル: TestClient_TUI.cs プロジェクト: complabs/TextUI
        /////////////////////////////////////////////////////////////////////////////////

        // Constructs sample application form.
        //
        public TestClient_TUI()
            : base(100, 40)
        {
            this.Text = applicationTitle;

            this.WindowUnloaded += new EventHandler(EH_WindowUnloaded);

            /////////////////////////////////////////////////////////////////////////////
            // Client Area default text

            MdiClient.Border = false;
            MdiClient.SetSize(Width, Height - 3);
            --MdiClient.Left;
            --MdiClient.Top;

            MdiClient.ForeColor = Color.DarkCyan;
            MdiClient.FillRectangle(0, 0, MdiClient.Width, MdiClient.Height, '▒');

            MdiClient.DrawFrame(0, 0, MdiClient.Width, MdiClient.Height);

            MdiClient.BackColor = BackColor;
            MdiClient.ForeColor = ForeColor;
            MdiClient.SetCursorPosition(60, 3);
            MdiClient.WriteLine("Text User Interface Test Suite\r\n");
            MdiClient.WriteLine("▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");
            MdiClient.WriteLine("ABCDEFGHIJKLMNOPQRSTUVWXYZÖÅÄÉ\r\n"
                                + "abcdefghijklmnopqrstuvwxyzåäöé\n"
                                + "\b\b\b«☺»"
                                + "\r0123456789");
            MdiClient.WriteLine("▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");

            MdiClient.SetColors(60, 5, 30, 5, Color.Black, Color.DarkGray);

            /////////////////////////////////////////////////////////////////////////////
            // Application main menu

            Menu.MenuItems.Add(new MenuItem("-"));     // test invalid separator

            MenuItem miEditor = new MenuItem("&Editor");

            miEditor.ToolTipText = "Sets editor window in focus";
            Menu.MenuItems.Add(miEditor);
            miEditor.Click += new EventHandler(EH_SetEditorInFocus);

            Menu.MenuItems.Add(new MenuItem("-"));     // test invalid separator
            Menu.MenuItems.Add(new MenuItem("-"));     // test invalid separator

            MenuItem miRed = new MenuItem("&Red");

            miRed.ToolTipText = "Sets red window in focus.";
            Menu.MenuItems.Add(miRed);
            miRed.Click += new EventHandler(EH_SetRedInFocus);

            MenuItem miCyan = new MenuItem("&Cyan");

            miCyan.ToolTipText = "Sets cyan window in focus.";
            Menu.MenuItems.Add(miCyan);
            miCyan.Click += new EventHandler(EH_SetCyanInFocus);

            MenuItem miSubmenu = new MenuItem("&Misc...");

            miSubmenu.ToolTipText =
                "Grid test, button test and message box tests are here...";
            Menu.MenuItems.Add(miSubmenu);

            Menu.MenuItems.Add(new MenuItem("-"));     // test invalid separator

            /////////////////////////////////////////////////////////////////////////////
            // Client window: Moveable

            winMoveable = new ButtonBase()
            {
                Name            = "winMoveable",
                Left            = 50, Top = 15, Width = 25, Height = 11, Border = true,
                BorderForeColor = Color.Yellow,
                BackColor       = Color.DarkBlue, ForeColor = Color.Gray,
            };

            winMoveable.DrawContents += new DrawEventHandler(EH_winMoveable_DrawContents);

            /////////////////////////////////////////////////////////////////////////////
            // Client window: Cyan and SubCyan

            winCyan = new ButtonBase()
            {
                Name            = "winCyan", TabStop = true,
                Left            = 54, Top = 20, Width = 22, Height = 7, Border = true,
                BorderForeColor = Color.Green,
                BackColor       = Color.DarkBlue, ForeColor = Color.Gray,
                Text            = "Cyan Window:"
            };

            textBoxSubCyan = new TextBox()
            {
                Name           = "winSubCyan", Parent = winCyan, Multiline = false,
                Left           = 1, Top = 2, Width = 20, Height = 1,
                BackColor      = Color.DarkMagenta, ForeColor = Color.Cyan,
                ForeColorInact = Color.Gray,
                ToolTipText    = "Cyan Window; Tests single-line text box with validation..."
            };

            textBoxSubCyan.KeyDown  += new KeyEventHandler(EH_winSubCyan_KeyDown);
            textBoxSubCyan.GotFocus += new EventHandler(EH_winSubCyan_GotFocus);

            checkBoxSubCyan = new CheckBox()
            {
                Name           = "checkBoxSubCyan", Parent = winCyan,
                Left           = 1, Top = 4, Width = 20, Height = 1,
                BackColor      = Color.DarkMagenta, ForeColor = Color.Cyan,
                ForeColorInact = Color.Gray,
                Text           = "Check box",
                ToolTipText    = "Cyan Window; Checkbox to test..."
            };

            checkBoxSubCyan.KeyDown += new KeyEventHandler(EH_winSubCyan_KeyDown);

            textBoxSubCyan.Validating += new CancelEventHandler(EH_textBoxSubCyan_Validating);

            /////////////////////////////////////////////////////////////////////////////
            // Client window: Buffered

            drawBox = new MdiForm(21, 15)
            {
                Name = "winBuf", TabStop = false,
                Left = MdiClient.Width - 23, Top = MdiClient.Height - 17, Border = true
            };

            drawBox.Write("Draw Box");

            drawBox.ForeColor = Color.DarkMagenta;
            drawBox.DrawFrame(3, 3, 15, 10, BoxLines.NotJoined);
            drawBox.DrawFrame(3, 5, 15, 1, BoxLines.Joined);
            drawBox.DrawFrame(5, 3, 1, 10, BoxLines.Joined);

            drawBox.ForeColor  = Color.Green;
            drawBox.CursorTop  = 4;
            drawBox.CursorLeft = 8;
            drawBox.Write(" Test ");

            /////////////////////////////////////////////////////////////////////////////
            // Client window: Red

            winRead = new ButtonBase()
            {
                Name        = "winRed", TabStop = true,
                ToolTipText = "Red Window; Shift+Arrows moves only draw box, "
                              + "Control+Arrows resizes draw box",
                Left               = 75, Top = 18, Width = 20, Height = 10, Border = true,
                BackColor          = Color.DarkRed, ForeColor = Color.Yellow,
                BackColorInact     = Color.DarkRed, ForeColorInact = Color.DarkYellow,
                Text               = "Red Window:",
                ForwadKeysToParent = true
            };

            winRead.KeyDown   += new KeyEventHandler(EH_winRed_KeyDown);
            winRead.GotFocus  += new EventHandler(EH_winRed_GotFocus);
            winRead.LostFocus += new EventHandler(EH_winRed_LostFocus);

            /////////////////////////////////////////////////////////////////////////////
            // Client window: Editor

            textBoxEditor = new TextBox()
            {
                Name              = "winEditor", Multiline = true,
                ToolTipText       = "Press F2 to load file 'VRO-test.txt' or AppKey for ListBox ...",
                Left              = 5, Top = 5, Width = 40, Height = 15,
                VerticalScrollBar = true, Border = true,
                Caption           = "TextBox as Editor",
                Text              = "0 Editor\r\n"
                                    + "1\r\n"
                                    + "2\r\n"
                                    + "3\r\n"
                                    + "4\r\n"
                                    + "5\r\n"
                                    + "6 234567890123456789012345678901234567890123456789\r\n"
                                    + "7\r\n"
                                    + "8\r\n"
                                    + "9\r\n"
                                    + "10 sdfasdfasdfasfasfasdf1\r\n"
                                    + "11\r\n"
                                    + "12\r\n"
                                    + "1\b3 backspace\r\n"
                                    + "tabs\ta\tab\tabc\tabcd\tabcde\tabcdef\r\n"
                                    + "15\r\n"
                                    + "16\r\n"
                                    + "17\r\n"
                                    + "18\r\n"
                                    + "19\r\n"
            };

            textBoxEditor.KeyDown += new KeyEventHandler(EH_winEditor_KeyDown);

            /////////////////////////////////////////////////////////////////////////////
            // List box

            listBox = new ListBox()
            {
                Name = "listBox",
                Left = 5, Top = 5, Width = 40, Height = 15,
                VerticalScrollBar = true, Border = true,
                CaptionForeColor  = Color.Red, Caption = "List Box (copied from TextBox)",
                Header            = new string[]
                {
                    string.Empty,
                    "     Header",
                    string.Empty,
                    ListBoxBase.WideDivider,
                },
                Footer = new string []
                {
                    ListBoxBase.WideDivider,
                    "     Footer",
                }
            };

            listBox.KeyDown += new KeyEventHandler(EH_listBox_KeyDown);

            /////////////////////////////////////////////////////////////////////////////
            // Vertical submenu

            miSubmenu.MenuItems.Add(new MenuItem("-"));     // test invalid sep.

            MenuItem miShowGrid = new MenuItem("Show &grid window");

            miShowGrid.ToolTipText = "Shows a lots of windows in a grid...";
            miSubmenu.MenuItems.Add(miShowGrid);
            miShowGrid.Click += new EventHandler(EH_ShowGridWindow);

            miSubmenu.MenuItems.Add(new MenuItem("-"));

            MenuItem m13 = new MenuItem("Test &Error Recovery");

            m13.ToolTipText = "Throws exception";
            miSubmenu.MenuItems.Add(m13);

            m13.Click += delegate
            {
                throw new Exception("Error Recovery Test");
            };

            miSubmenu.MenuItems.Add(new MenuItem("-"));

            MenuItem miTestButton = new MenuItem(
                "&&Long submenu item that && opens test &button (& multiple &&s) ");

            miTestButton.ToolTipText =
                "&&Long submenu item that && opens test &button (& multiple &&s) ";
            miSubmenu.MenuItems.Add(miTestButton);
            miTestButton.Click += new EventHandler(EH_SetTestButtonInFocus);

            miSubmenu.MenuItems.Add(new MenuItem("-"));     // test invalid sep.

            /////////////////////////////////////////////////////////////////////////////
            // Button

            buttonTest = new Button()
            {
                Name = "buttonTest", Border = true,
                Left = 5, Top = 10, AutoSize = true,
                HorizontalPadding = 2, // VerticalPadding = 1,
                Text        = "Test Button\nwith very long line\nand the third line",
                ToolTipText = "Press ENTER to hide the button..."
            };

            buttonTest.Click += new EventHandler(EH_buttonTest_Click);

            buttonTest2 = new Button()
            {
                Name = "buttonTest2", Border = true,
                Left = 5 + buttonTest.Width + 2, Top = 10, AutoSize = true,
                HorizontalPadding = 2, // VerticalPadding = 1,
                Text        = "Test Button 2\nwith very long line\nand the third line",
                ToolTipText = "Press ENTER to hide the button...",
                TextAlign   = TextAlign.Right
            };

            buttonTest2.Click += new EventHandler(EH_buttonTest_Click);
        }