コード例 #1
0
ファイル: ControlExtensions.cs プロジェクト: S031/MetaStack
        public static T Add <T>(this Control parent) where T : Control
        {
            WinForm wf = parent.GetOwner();

            if (wf == null)
            {
                throw new InvalidOperationException($"Control extensoin method Add<T> may be called only for WinForm child control");
            }
            WinFormItem wfi = new WinFormItem(wf.NewName(typeof(T)))
            {
                PresentationType = typeof(T)
            };

            return((T)AddInternal(parent, wfi));
        }
コード例 #2
0
ファイル: CEdit.cs プロジェクト: S031/MetaStack
        public void Find()
        {
            if (_cd != null)
            {
                _cd.Dispose();
            }
            _cd = new WinForm(WinFormStyle.Dialog)
            {
                Size = new Size(350, Convert.ToInt32(350 / vbo.GoldenRatio)),
                Text = "Найти..."
            };

            _cd.Add <Panel>(WinFormConfig.SinglePageForm);
            TableLayoutPanel tlpRows = _cd.Items["FormRowsPanel"].LinkedControl as TableLayoutPanel;
            TableLayoutPanel p       = tlpRows.Add <TableLayoutPanel>(new WinFormItem("WorkCells")
            {
                CellsSize = new Pair <int>(2, 2)
            });

            p.ColumnStyles[0].SizeType = SizeType.Percent;
            p.ColumnStyles[0].Width    = 100;
            p.ColumnStyles[1].SizeType = SizeType.Absolute;
            p.ColumnStyles[1].Width    = 100;
            ComboBox cbox = p.Add <ComboBox>(new WinFormItem("SearchText")
            {
                PresentationType = typeof(ComboBox),
                DataType         = typeof(string),
                Value            = GetInitialSearchText()
            });

            cbox.Items.AddRange(_searches.ToArray());
            SetAutoComplete(cbox);
            _cd.Activated += new EventHandler((o, e) => { ((WinForm)o).GetControl <ComboBox>("SearchText").Focus(); });
            Button btn = p.Add <Button>("Find");

            btn.Text         = "Найти";
            btn.Click       += new EventHandler(Btn_Click);
            _cd.AcceptButton = btn;
            CheckBox cb = p.Add <CheckBox>(new WinFormItem("MatchCase")
            {
                Value = (_stringComparison != StringComparison.InvariantCultureIgnoreCase), DataType = typeof(bool), PresentationType = typeof(CheckBox)
            });

            cb.Text = "С учетом регистра";
            tlpRows.Add <Label>("Blank");
            _cd.Show(this);
        }
コード例 #3
0
ファイル: OutputWindow.cs プロジェクト: S031/MetaStack
        static OutputWindow()
        {
            _cd = new WinForm(WinFormStyle.Dialog)
            {
                Text = "Окно сообщений"
            };
            _cd.Add <Panel>(WinFormConfig.SinglePageForm);
            _cd.FormClosing += _cd_FormClosing;
            TableLayoutPanel tlpRows = _cd.Items["FormRowsPanel"].LinkedControl as TableLayoutPanel;

            tlpRows.Add(new WinFormItem($"LogView")
            {
                PresentationType = typeof(DataGridView),
                ControlTrigger   = (cdi, ctrl) =>
                {
                    DataGridView grid          = (ctrl as DataGridView);
                    grid.Dock                  = DockStyle.Fill;
                    grid.AllowUserToAddRows    = false;
                    grid.AllowUserToDeleteRows = false;
                    grid.AutoGenerateColumns   = false;
                    grid.VirtualMode           = true;
                    //grid.ScrollBars = ScrollBars.Both;
                    grid.RowHeadersWidth = 30;
                    int i   = grid.Columns.Add("MessageTime", "Время");
                    var col = grid.Columns[i];
                    col.DataPropertyName        = "MessageTime";
                    col.DefaultCellStyle.Format = vbo.FullDateFormat;
                    col.Width = 130;
                    i         = grid.Columns.Add("MessageSource", "Статус");
                    grid.Columns[i].DataPropertyName = "MessageSource";
                    i   = grid.Columns.Add("Message", "Описание события");
                    col = grid.Columns[i];
                    col.DataPropertyName          = "Message";
                    col.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
                    col.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                    var b            = new DataGridViewButtonColumn()
                    {
                        Name       = "BtnView",
                        HeaderText = "",
                        Text       = "***",
                        Width      = 30,
                        UseColumnTextForButtonValue = true
                    };
                    grid.Columns.Add(b);
                    grid.CellClick += Grid_CellClick;
                    _grid           = grid;
                }
            });
            _cd.Size = new Size(Convert.ToInt32(Screen.FromControl(_cd).WorkingArea.Width / vbo.GoldenRatio), Screen.FromControl(_cd).WorkingArea.Height / 3);
            _timer   = new Timer {
                Interval = 1000
            };
            _timer.Tick += (c, e) =>
            {
                int cnt = _queue.Count;
                for (; _queue.TryDequeue(out Tuple <DateTime, string, string> item);)
                {
                    _dt.Rows.Add(item.Item1, item.Item2, item.Item3);
                }
                if (cnt > 0)
                {
                    _grid.Refresh();
                    Application.DoEvents();
                }
            };
            _cd.Disposed += (c, e) =>
            {
                _timer?.Dispose();
            };
            _grid.DataSource = GetDataSource();
        }
コード例 #4
0
ファイル: CEdit.cs プロジェクト: S031/MetaStack
        public void Replace()
        {
            //Object[] values = InputBox.Show(new WinFormItem("DateOper") { Caption = "Дата операции", DataType = typeof(DateTime), Value = vbo.Date() },
            //	new WinFormItem("Amount") { Caption = "Сумма", DataType = typeof(decimal), Value = 1000000, Format = vbo.CurrencyFormat });

            if (_cd != null)
            {
                _cd.Dispose();
            }
            _cd = new WinForm(WinFormStyle.Dialog)
            {
                Size = new Size(350, Convert.ToInt32(350 / vbo.GoldenRatio)),
                Text = "Найти..."
            };

            _cd.Add <Panel>(WinFormConfig.SinglePageForm);
            TableLayoutPanel tlpRows = _cd.Items["FormRowsPanel"].LinkedControl as TableLayoutPanel;
            TableLayoutPanel p       = tlpRows.Add <TableLayoutPanel>(new WinFormItem("WorkCells")
            {
                CellsSize = new Pair <int>(2, 3)
            });

            p.ColumnStyles[0].SizeType = SizeType.Percent;
            p.ColumnStyles[0].Width    = 100;
            p.ColumnStyles[1].SizeType = SizeType.Absolute;
            p.ColumnStyles[1].Width    = 100;

            ComboBox cbox = p.Add <ComboBox>(new WinFormItem("SearchText")
            {
                PresentationType = typeof(ComboBox),
                DataType         = typeof(string),
                Value            = GetInitialSearchText(),
                CellAddress      = new Pair <int>(0, 0)
            });

            cbox.Items.AddRange(_searches.ToArray());
            SetAutoComplete(cbox);
            _cd.Activated += new EventHandler((o, e) => { ((WinForm)o).GetControl <ComboBox>("SearchText").Focus(); });

            cbox = p.Add <ComboBox>(new WinFormItem("ReplaceText")
            {
                PresentationType = typeof(ComboBox),
                DataType         = typeof(string),
                Value            = _replaceText,
                CellAddress      = new Pair <int>(0, 1)
            });
            cbox.Items.AddRange(_replaces.ToArray());
            SetAutoComplete(cbox);

            CheckBox cb = p.Add <CheckBox>(new WinFormItem("MatchCase")
            {
                Value            = (_stringComparison != StringComparison.InvariantCultureIgnoreCase),
                DataType         = typeof(bool),
                PresentationType = typeof(CheckBox),
                CellAddress      = new Pair <int>(0, 2)
            });

            cb.Text = "С учетом регистра";

            Button btn = p.Add <Button>("Find");

            btn.Text         = "Найти";
            btn.Click       += new EventHandler(Btn_Click);
            _cd.AcceptButton = btn;

            btn        = p.Add <Button>("Replace");
            btn.Text   = "Заменить";
            btn.Click += new EventHandler(Btn_Click);

            btn        = p.Add <Button>("ReplaceAll");
            btn.Text   = "Заменить все";
            btn.Click += new EventHandler(Btn_Click);
            tlpRows.Add <Label>("Blank");

            _cd.Show(this);
        }
コード例 #5
0
ファイル: WinFormStyles.cs プロジェクト: S031/MetaStack
 public static WinFormItem StdButtons(string OKCaption = "&Запись", string CancelCaption = "&Отмена") =>
 new WinFormItem("FormRowsBottomPanel",
                 new WinFormItem("StdButtonsCells",
                                 new WinFormItem("OK")
 {
     PresentationType = typeof(Button),
     Value            = OKCaption,
     CellAddress      = new Pair <int>(1, 0),
     ControlTrigger   = (i, c) =>
     {
         Button btn = (c as Button);
         btn.Height = WinForm.ButtonHeight;
         btn.Width  = WinForm.ButtonWidth;
         btn.Click += (o, e) =>
         {
             Button b = (o as Button);
             if (b.GetSTDAction("click"))
             {
                 WinForm parent = b.Tag().WinForm;
                 if (!parent.ContinuousEditing)
                 {
                     parent.DialogResult = DialogResult.OK;
                     if (!parent.Modal)
                     {
                         parent.Close();
                     }
                 }
             }
         };
         btn.Tag().WinForm.AcceptButton = btn;
     }
 },
                                 new WinFormItem("Cancel")
 {
     PresentationType = typeof(Button),
     Value            = CancelCaption,
     CellAddress      = new Pair <int>(2, 0),
     ControlTrigger   = (i, c) =>
     {
         Button btn = (c as Button);
         btn.Height = WinForm.ButtonHeight;
         btn.Width  = WinForm.ButtonWidth;
         btn.Click += (o, e) =>
         {
             Button b = (o as Button);
             if (b.GetSTDAction("click"))
             {
                 WinForm parent      = b.Tag().WinForm;
                 parent.DialogResult = DialogResult.Cancel;
                 if (!parent.Modal)
                 {
                     parent.Close();
                 }
             }
         };
         btn.Tag().WinForm.CancelButton = btn;
     }
 })
 {
     PresentationType = typeof(TableLayoutPanel),
     CellsSize        = new Pair <int>(3, 1),
     ControlTrigger   = (i, c) =>
     {
         TableLayoutPanel cells = (c as TableLayoutPanel);
         cells.Dock             = DockStyle.Bottom;
         cells.CellBorderStyle  = WinForm.CellBorderStyle;
         cells.ColumnStyles[0]  = new ColumnStyle(SizeType.Percent, 100);
         cells.ColumnStyles[1]  = new ColumnStyle(SizeType.Absolute, WinForm.ButtonWidth);
         cells.ColumnStyles[2]  = new ColumnStyle(SizeType.Absolute, WinForm.ButtonWidth);
         cells.RowStyles[0]     = new RowStyle(SizeType.Absolute, WinForm.ButtonHeight);
         cells.ControlAdded    += (ctrl, e) =>
         {
             (ctrl as TableLayoutPanel)?.RowStyles.Add(new RowStyle(SizeType.AutoSize, 100));
         };
     }
 })
 {
     PresentationType = typeof(TableLayoutPanel),
     CellsSize        = new Pair <int>(1, 1),
     ControlTrigger   = (i, c) =>
     {
         TableLayoutPanel tlpRows = (c as TableLayoutPanel);
         tlpRows.Dock            = DockStyle.Bottom;
         tlpRows.CellBorderStyle = WinForm.CellBorderStyle;
         tlpRows.ColumnCount     = 1;
         tlpRows.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));
         tlpRows.ControlAdded += (ctrl, e) =>
         {
             (ctrl as TableLayoutPanel)?.RowStyles.Add(new RowStyle(SizeType.AutoSize, 100));
         };
         tlpRows.Height = WinForm.ButtonHeight + 20;
     }
 };
コード例 #6
0
ファイル: ControlExtensions.cs プロジェクト: S031/MetaStack
        static object AddInternal(Control parent, WinFormItem winFormItem)
        {
            parent.SuspendLayout();
            WinForm wf = parent.GetOwner();

            wf.OnItemAdd(winFormItem);
            if (wf == null)
            {
                throw new InvalidOperationException($"Control extensoin method Add<T> may be called only for WinForm child control");
            }
            Type t        = winFormItem.PresentationType;
            var  instance = (Control)Activator.CreateInstance(t);

            instance.Tag = new WinFormRef()
            {
                WinForm = wf, WinFormItem = winFormItem
            };
            instance.Name = $"{t.Name}_{winFormItem.Name}";
            if (instance is Splitter)
            {
                instance.Dock = DockStyle.Right;
            }
            else
            {
                instance.Dock = DockStyle.Fill;
            }


            wf.Items.Add(winFormItem.Name, winFormItem);
            if (winFormItem.Value != null)
            {
                instance.Text = winFormItem.Value.ToString();
            }
            winFormItem.LinkedControl = instance;
            var cellAddress = winFormItem.CellAddress;

            TextBuX tbux = instance as TextBuX;

            void dataChanged(object c, EventArgs e)
            {
                (c as Control)?.GetOwner().OnDataChanged(new DataChangedEventArgs(c as Control));
            }

            if (instance is TextBoxBase || tbux != null)
            {
                instance.TextChanged += new EventHandler(dataChanged);
                instance.GotFocus    += TextBox_GotFocus;
                instance.KeyDown     += Enter_KeyDown;
                if (tbux != null)
                {
                    tbux.Click            += CmdTB_Click;
                    tbux.TextBox.GotFocus += TextBox_GotFocus;
                    if (winFormItem.DataType.IsNumeric(NumericTypesScope.All))
                    {
                        tbux.TextAlign = HorizontalAlignment.Right;
                        tbux.KeyPress += new KeyPressEventHandler(Num_KeyPress);
                    }
                    else if (winFormItem.DataType == typeof(string) && winFormItem.SuperForm == WinForm.StrViewFormList)
                    {
                        //tbux.TextBox.Enabled = false;
                        tbux.TextBox.Multiline = true;
                        tbux.TextBox.WordWrap  = false;
                        tbux.TextBox.MaxLength = winFormItem.DataSize;
                    }
                }
                else if (instance is TextBox && winFormItem.DataType.IsNumeric(NumericTypesScope.All))
                {
                    TextBox tb = (instance as TextBox);
                    tb.TextAlign = HorizontalAlignment.Right;
                    tb.KeyPress += new KeyPressEventHandler(Num_KeyPress);
                    if (!winFormItem.Format.IsEmpty())
                    {
                        tb.Text        = string.Format("{0:" + winFormItem.Format + "}", winFormItem.Value);
                        tb.Validating += (sender, e) =>
                        {
                            TextBox tbo = (sender as TextBox);
                            if (tbo == null || !tbo.GetSTDAction("Validating"))
                            {
                                return;
                            }
                            else
                            {
                                WinFormItem wfi = tbo.GetItem();
                                tbo.Text = string.Format("{0:" + wfi.Format + "}", tbo.Text.ToObjectOf(wfi.DataType));
                            }
                        };
                    }
                }
            }
            else if (typeof(ListControl).IsInstanceOfType(instance) || instance is CheckBox || instance is TabControl || instance is DateTimePicker)
            {
                instance.TextChanged += new EventHandler(dataChanged);
                instance.KeyDown     += Enter_KeyDown;
                ListControl lc = (instance as ListControl);
                if (lc != null)
                {
                    lc.SelectedValueChanged += new EventHandler(dataChanged);
                }
            }
            else if (instance is ICSharpCode.TextEditor.TextEditorControlBase)
            {
                instance.TextChanged += new EventHandler(dataChanged);
            }
            else if (instance is TableLayoutPanel && parent is TableLayoutPanel)
            {
                TableLayoutPanel tp      = instance as TableLayoutPanel;
                TableLayoutPanel tparent = parent as TableLayoutPanel;

                tparent.RowCount++;
                tp.CellBorderStyle = WinForm.CellBorderStyle;
                tp.Dock            = DockStyle.Fill;
                tp.AutoSize        = true;
                if (winFormItem.CellsSize != null)
                {
                    for (int i = 0; i < winFormItem.CellsSize.X; i++)
                    {
                        tp.ColumnCount++;
                        tp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
                    }
                    for (int i = 0; i < winFormItem.CellsSize.Y; i++)
                    {
                        tp.RowCount++;
                        tp.RowStyles.Add(new RowStyle(SizeType.AutoSize, WinForm.CellsRowHieght));
                    }
                }
            }

            if (cellAddress == WinFormItem.CellAddressDefault)
            {
                parent.Controls.Add(instance);
            }
            else
            {
                (parent as TableLayoutPanel)?.Controls.Add(instance, cellAddress.X, cellAddress.Y);
            }
            winFormItem.ControlTrigger?.Invoke(winFormItem, instance);
            foreach (WinFormItem item in winFormItem)
            {
                if (item.PresentationType != null && typeof(Control).IsAssignableFrom(item.PresentationType))
                {
                    AddInternal(instance, item);
                }
            }
            if (winFormItem.ReadOnly)
            {
                instance.Enabled = false;
            }
            parent.ResumeLayout();
            wf.OnItemAdded(winFormItem);
            return(instance);
        }