Exemple #1
0
 //cycle through and refresh the tab order of the fields
 void RefreshTabOrder()
 {
     for (int i = 0; i < _fields.Count; i++)
     {
         ConsoleFields cf       = _fields[i];
         int           tabCount = i * 5;
         cf.addRow.TabIndex      = tabCount;
         cf.consoleName.TabIndex = tabCount + 1;
         cf.linkToExe.TabIndex   = tabCount + 2;
         cf.arguments.TabIndex   = tabCount + 3;
         cf.linkToRoms.TabIndex  = tabCount + 4;
     }
 }
Exemple #2
0
        //adds a new empty row at the given row number
        ConsoleFields AddRow(Console console = null, int rowNum = -1)
        {
            //calculate the distance down that the row should be
            int distDown  = _fields.Count;
            int topBuffer = 0;
            int rowHeight = 25;

            //if we are insterting, move all the otehr rows down first
            if (rowNum >= 0)
            {
                //move the rows down
                for (int i = rowNum; i < _fields.Count; i++)
                {
                    _fields[i].addRow.Location      = new Point(_fields[i].addRow.Location.X, _fields[i].addRow.Location.Y + rowHeight);
                    _fields[i].arguments.Location   = new Point(_fields[i].arguments.Location.X, _fields[i].arguments.Location.Y + rowHeight);
                    _fields[i].consoleName.Location = new Point(_fields[i].consoleName.Location.X, _fields[i].consoleName.Location.Y + rowHeight);
                    _fields[i].linkToExe.Location   = new Point(_fields[i].linkToExe.Location.X, _fields[i].linkToExe.Location.Y + rowHeight);
                    _fields[i].linkToRoms.Location  = new Point(_fields[i].linkToRoms.Location.X, _fields[i].linkToRoms.Location.Y + rowHeight);
                }
                distDown = rowNum;
            }

            //create and position the controls
            ConsoleFields cf = new ConsoleFields(console);
            Point         p  = new Point(5, distDown * rowHeight + topBuffer - settingsContainer.VerticalScroll.Value);

            cf.addRow.Text     = "+";
            cf.addRow.Width    = 20;
            cf.addRow.Location = p;

            p.X += cf.addRow.Width;
            p.Y += 15;

            cf.consoleName          = new TextBox();
            cf.consoleName.Width    = 125;
            cf.consoleName.Location = p;

            p.X += cf.consoleName.Width + 5;

            cf.linkToExe          = new TextBox();
            cf.linkToExe.Width    = 220;
            cf.linkToExe.Location = p;

            p.X += cf.linkToExe.Width + 5;

            cf.arguments          = new TextBox();
            cf.arguments.Width    = 220;
            cf.arguments.Location = p;

            p.X += cf.arguments.Width + 5;

            cf.linkToRoms          = new TextBox();
            cf.linkToRoms.Width    = 220;
            cf.linkToRoms.Location = p;

            //add the callbacks
            //insert button callbacks
            cf.addRow.MouseEnter +=
                delegate(object sender, EventArgs e)
            {
                cf.addRow.ForeColor = Color.Black;
            };
            cf.addRow.MouseLeave +=
                delegate(object sender, EventArgs e)
            {
                cf.addRow.ForeColor = Color.Gray;
            };
            cf.addRow.Click +=
                delegate(object sender, EventArgs e)
            {
                AddRow(null, _fields.IndexOf(cf));
            };

            //text field callbacks
            EventHandler textAddedCallback = delegate(object sender, EventArgs e)
            {
                //if the text has changed and it's not gray or empty
                if ((sender as TextBox).Text.Trim() == "")
                {
                    return;
                }

                //then add a new row at the bottom
                if (_fields.Contains(cf) && _fields.IndexOf(cf) == _fields.Count - 1)
                {
                    AddRow();
                }
            };

            cf.consoleName.TextChanged += textAddedCallback;
            cf.linkToExe.TextChanged   += textAddedCallback;
            cf.arguments.TextChanged   += textAddedCallback;
            cf.linkToRoms.TextChanged  += textAddedCallback;

            EventHandler highlightRowOnFocus = delegate(object sender, EventArgs e)
            {
                Color col = Color.FromArgb(235, 255, 235);
                cf.arguments.BackColor   = col;
                cf.consoleName.BackColor = col;
                cf.linkToExe.BackColor   = col;
                cf.linkToRoms.BackColor  = col;
            };

            cf.arguments.GotFocus   += highlightRowOnFocus;
            cf.consoleName.GotFocus += highlightRowOnFocus;
            cf.linkToExe.GotFocus   += highlightRowOnFocus;
            cf.linkToRoms.GotFocus  += highlightRowOnFocus;

            EventHandler dehighlightRowOnUnfocus = delegate(object sender, EventArgs e)
            {
                cf.arguments.BackColor   = Color.White;
                cf.consoleName.BackColor = Color.White;
                cf.linkToExe.BackColor   = Color.White;
                cf.linkToRoms.BackColor  = Color.White;
            };

            cf.arguments.LostFocus   += dehighlightRowOnUnfocus;
            cf.consoleName.LostFocus += dehighlightRowOnUnfocus;
            cf.linkToExe.LostFocus   += dehighlightRowOnUnfocus;
            cf.linkToRoms.LostFocus  += dehighlightRowOnUnfocus;


            //initialize visuals of the insert button
            Font plusFont = new Font("", 14, FontStyle.Regular);

            cf.addRow.ForeColor = Color.Gray;
            cf.addRow.Font      = plusFont;

            //add the controls to the form
            settingsContainer.Controls.Add(cf.addRow);
            settingsContainer.Controls.Add(cf.consoleName);
            settingsContainer.Controls.Add(cf.linkToExe);
            settingsContainer.Controls.Add(cf.arguments);
            settingsContainer.Controls.Add(cf.linkToRoms);

            _fields.Insert(distDown, cf);

            RefreshTabOrder();

            return(cf);
        }