Exemplo n.º 1
0
        /// <summary>Initialize the controls.</summary>
        private void InitializeControls()
        {
            label = new VisualLabel
            {
                Text     = @"Enter your input: ",
                Size     = new Size(90, 25),
                Location = new Point(BodyContainer.X, BodyContainer.Y)
            };

            textBox = new VisualTextBox
            {
                Text      = string.Empty,
                Watermark =
                {
                    Visible = true,
                    Text    = "Enter your input..."
                },
                Location = new Point(label.Right, BodyContainer.Y + 2),
                Size     = new Size(200, 23)
            };

            textBox.TextBoxWidth = textBox.GetTextBoxWidth();
            textBox.TextChanged += TextBox_TextChanged;

            button = new VisualButton
            {
                Text     = @"OK",
                Size     = ButtonSize,
                Location = new Point(textBox.Right - ButtonSize.Width, textBox.Bottom + 5),
                Enabled  = false
            };

            button.Click += Button_Click;

            Controls.Add(label);
            Controls.Add(textBox);
            Controls.Add(button);
        }
Exemplo n.º 2
0
        private void ParseFormat(string format)
        {
            _DateInputGroup.Items.Clear();

            if (_ShowCheckBox)
            {
                LockUpdateCheckBox checkBox = new LockUpdateCheckBox();
                _DateInputGroup.Items.Add(checkBox);
                checkBox.CheckedChanged += new EventHandler(LockCheckedChanged);
            }

            if (format.Length == 0) return;

            StringBuilder inputStack = new StringBuilder(format.Length);
            bool quote = false;
            Stack<VisualGroup> groupStack = new Stack<VisualGroup>();
            VisualGroup currentGroup = _DateInputGroup;

            for (int i = 0; i < format.Length; i++)
            {
                if (format[i] == '\'') // Trigger/Exit quote mode
                {
                    if (quote)
                        quote = false;
                    else
                        quote = true;
                    continue;
                }

                if (quote) // Quote mode adds everything under the quotes
                {
                    inputStack.Append(format[i]);
                    continue;
                }

                string s = format.Substring(i, Math.Min(4, format.Length - i));
                bool match = false;
                if (s == "dddd") // The full day-of-week name or three-character day-of-week abbreviation.
                {
                    DayLabelItem dayLabel = new DayLabelItem();
                    currentGroup.Items.Add(dayLabel);
                    i += 3;
                    match = true;
                }
                else if (s == "MMMM") // Full month name
                {
                    MonthNameInput month = new MonthNameInput();
                    currentGroup.Items.Add(month);
                    i += 3;
                    match = true;
                }
                else if (s == "yyyy") // 4 digit year
                {
                    NumericYearInput year = new NumericYearInput();
                    currentGroup.Items.Add(year);
                    i += 3;
                    match = true;
                }

                if (!match)
                {
                    s = format.Substring(i, Math.Min(3, format.Length - i));
                    if (s == "ddd") // The three-character day-of-week abbreviation.
                    {
                        DayLabelItem dayLabel = new DayLabelItem();
                        dayLabel.UseAbbreviatedNames = true;
                        currentGroup.Items.Add(dayLabel);
                        i += 2;
                        match = true;
                    }
                    else if (s == "MMM") // The three-character month abbreviation.
                    {
                        MonthNameInput month = new MonthNameInput();
                        month.UseAbbreviatedNames = true;
                        currentGroup.Items.Add(month);
                        i += 2;
                        match = true;
                    }
                    else if (s == "jjj") // The three-digit day of year...
                    {
                        NumericDayOfYearInput day = new NumericDayOfYearInput();
                        day.DisplayFormat = "000";
                        currentGroup.Items.Add(day);
                        i += 2;
                        match = true;
                    }
                }

                if (!match)
                {
                    s = format.Substring(i, Math.Min(2, format.Length - i));
                    if (s == "dd") // The two-digit day. Single-digit day values are preceded by a 0.
                    {
                        NumericDayInput day = new NumericDayInput();
                        day.DisplayFormat = "00";
                        currentGroup.Items.Add(day);
                        i += 1;
                        match = true;
                    }
                    else if (s == "hh") // The two-digit hour in 12-hour format. Single digit values are preceded by a 0. 
                    {
                        NumericHourInput hour = new NumericHourInput();
                        hour.DisplayFormat = "00";
                        hour.Is24HourFormat = false;
                        currentGroup.Items.Add(hour);
                        i += 1;
                        match = true;
                    }
                    else if (s == "HH") // The two-digit hour in 24-hour format. Single digit values are preceded by a 0.
                    {
                        NumericHourInput hour = new NumericHourInput();
                        hour.DisplayFormat = "00";
                        hour.Is24HourFormat = true;
                        currentGroup.Items.Add(hour);
                        i += 1;
                        match = true;
                    }
                    else if (s == "mm") // The two-digit minute. Single digit values are preceded by a 0. 
                    {
                        NumericMinuteInput minute = new NumericMinuteInput();
                        minute.DisplayFormat = "00";
                        currentGroup.Items.Add(minute);
                        i += 1;
                        match = true;
                    }
                    else if (s == "MM") // The two-digit month number. Single digit values are preceded by a 0. 
                    {
                        NumericMonthInput month = new NumericMonthInput();
                        month.DisplayFormat = "00";
                        currentGroup.Items.Add(month);
                        i += 1;
                        match = true;
                    }
                    else if (s == "ss") // The two-digit seconds. Single digit values are preceded by a 0. 
                    {
                        NumericSecondInput second = new NumericSecondInput();
                        second.DisplayFormat = "00";
                        currentGroup.Items.Add(second);
                        i += 1;
                        match = true;
                    }
                    else if (s == "tt") // The two-letter A.M./P.M. abbreviation (A.M. is displayed as "AM").
                    {
                        HourPeriodInput period = new HourPeriodInput();
                        currentGroup.Items.Add(period);
                        i += 1;
                        match = true;
                    }
                    else if (s == "yy") // The last two digits of the year (2001 is displayed as "01"). 
                    {
                        NumericYearInput year = new NumericYearInput();
                        year.YearDisplayFormat = eYearDisplayFormat.TwoDigit;
                        currentGroup.Items.Add(year);
                        i += 1;
                        match = true;
                    }
                }

                if (!match)
                {
                    s = format[i].ToString();
                    if (s == "d") // The one- or two-digit day. 
                    {
                        NumericDayInput day = new NumericDayInput();
                        currentGroup.Items.Add(day);
                        match = true;
                    }
                    else if (s == "h") // The one- or two-digit hour in 12-hour format.
                    {
                        NumericHourInput hour = new NumericHourInput();
                        hour.Is24HourFormat = false;
                        currentGroup.Items.Add(hour);
                        match = true;
                    }
                    else if (s == "H") //The one- or two-digit hour in 24-hour format. 
                    {
                        NumericHourInput hour = new NumericHourInput();
                        hour.Is24HourFormat = true;
                        currentGroup.Items.Add(hour);
                        match = true;
                    }
                    else if (s == "m") // The one- or two-digit minute. 
                    {
                        NumericMinuteInput minute = new NumericMinuteInput();
                        currentGroup.Items.Add(minute);
                        match = true;
                    }
                    else if (s == "M") // The one- or two-digit month number. 
                    {
                        NumericMonthInput month = new NumericMonthInput();
                        currentGroup.Items.Add(month);
                        match = true;
                    }
                    else if (s == "s") // The one- or two-digit seconds. 
                    {
                        NumericSecondInput second = new NumericSecondInput();
                        currentGroup.Items.Add(second);
                        match = true;
                    }
                    else if (s == "t") // The one-letter A.M./P.M. abbreviation (A.M. is displayed as "A"). 
                    {
                        HourPeriodInput period = new HourPeriodInput();
                        period.UseSingleLetterLabel = true;
                        currentGroup.Items.Add(period);
                        match = true;
                    }
                    else if (s == "y") // The one-digit year (2001 is displayed as "1"). 
                    {
                        NumericYearInput year = new NumericYearInput();
                        year.YearDisplayFormat = eYearDisplayFormat.OneDigit;
                        currentGroup.Items.Add(year);
                        match = true;
                    }
                    else if (s == "j") // The three-digit day of year...
                    {
                        NumericDayOfYearInput day = new NumericDayOfYearInput();
                        currentGroup.Items.Add(day);
                        match = true;
                    }
                    else if (s == "{") // Begins the group of data entries
                    {
                        if (inputStack.Length > 0)
                        {
                            VisualLabel label = new VisualLabel();
                            label.Text = inputStack.ToString();
                            currentGroup.Items.Add(label);
                            inputStack = new StringBuilder(format.Length);
                        }
                        DateTimeGroup group = new DateTimeGroup();
                        currentGroup.Items.Add(group);
                        groupStack.Push(currentGroup);
                        currentGroup = group;
                        match = true;
                    }
                    else if (s == "}") // Ends the group of data entries
                    {
                        currentGroup = groupStack.Pop();
                        match = true;
                    }
                }

                if (match)
                {
                    if (inputStack.Length > 0)
                    {
                        VisualLabel label = new VisualLabel();
                        label.Text = inputStack.ToString();
                        //label.TextPadding = new DevComponents.DotNetBar.Padding(0, 1, 0, 0);
                        currentGroup.Items.Insert(currentGroup.Items.Count - 1, label);
                        inputStack = new StringBuilder(format.Length);
                    }
                }
                else
                    inputStack.Append(format[i]);
            }

            if (inputStack.Length > 0)
            {
                VisualLabel label = new VisualLabel();
                label.Text = inputStack.ToString();
                currentGroup.Items.Add(label);
            }

            if (_ShowUpDown)
            {
                VisualUpDownButton upDownButton = new VisualUpDownButton();
                upDownButton.Alignment = eItemAlignment.Right;
                upDownButton.AutoChange = eUpDownButtonAutoChange.FocusedItem;
                _DateInputGroup.Items.Add(upDownButton);
            }

            RecreateButtons();

            if (_ShowCheckBox)
                this.LockUpdateCheckBox.Checked = _LockUpdateChecked;
        }