コード例 #1
0
        private void OpenFile(string FileName)
        {
            object file = STFileLoader.OpenFileFormat(FileName);

            if (file is TreeNode)
            {
                var node = (TreeNode)file;
                treeViewCustom1.Nodes.Add(node);
            }
            else
            {
                STErrorDialog.Show("Invalid file type. Cannot add file to object list.", "Object List", "");
            }
        }
コード例 #2
0
        private void STDataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                bool IsSelected = (e.State & DataGridViewElementStates.Selected) == DataGridViewElementStates.Selected;

                e.Handled = true;

                Rectangle rect = new Rectangle(e.CellBounds.X, e.CellBounds.Y, e.CellBounds.Width - 1, e.CellBounds.Height - 1);

                if (IsSelected)
                {
                    e.Graphics.FillRectangle(new SolidBrush(e.CellStyle.SelectionBackColor), rect);
                }
                else
                {
                    e.Graphics.FillRectangle(new SolidBrush(e.CellStyle.BackColor), rect);
                }

                using (Pen pen = new Pen(GridColor))
                {
                    e.Graphics.DrawRectangle(pen, e.CellBounds.X - 1, e.CellBounds.Y - 1, e.CellBounds.Width, e.CellBounds.Height);
                }

                RadioButtonState state = RadioButtonState.CheckedDisabled;

                if (e.Value != null)
                {
                    var TextCell = Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewTextBoxCell;

                    if (TextCell != null)
                    {
                        // Render the cell text.

                        string cellValue = e.FormattedValue.ToString();

                        // Set the alignment settings. Unfortunately, there's no // straightforward way to get the cell style settings and // convert them to the text alignment values you need here.

                        StringFormat format = new StringFormat(); format.LineAlignment = StringAlignment.Center; format.Alignment = StringAlignment.Near;

                        using (Brush valueBrush = new SolidBrush(e.CellStyle.ForeColor))
                        {
                            e.Graphics.DrawString(cellValue, e.CellStyle.Font, valueBrush, rect, format);
                        }
                    }
                }


                try
                {
                    if (e.Value != null)
                    {
                        var Cell = Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewCheckBoxCell;

                        if (Cell == null)
                        {
                            return;
                        }

                        bool IsChecked    = (bool)(Convert.ToBoolean(Cell.Value) == true);
                        bool IsNotChecked = (bool)(Convert.ToBoolean(Cell.Value) == false);

                        if (IsChecked)
                        {
                            state = RadioButtonState.CheckedNormal;
                        }

                        var size = RadioButtonRenderer.GetGlyphSize(e.Graphics, state);

                        var location = new Point((e.CellBounds.Width - size.Width) / 2,
                                                 ((e.CellBounds.Height - size.Height) / 2) - 1);
                        location.Offset(e.CellBounds.Location);



                        if (IsChecked)
                        {
                            Color checkedColor = FormThemes.BaseTheme.CheckBoxEnabledBackColor;
                            e.Graphics.FillRectangle(new SolidBrush(checkedColor), new Rectangle(location.X, location.Y, 15, 15));
                            e.Graphics.DrawImage(this.TickTock, location.X, location.Y, 12, 12);
                        }
                        else if (IsNotChecked)
                        {
                            //   e.Graphics.FillRectangle(new SolidBrush(this.BoxColor), new Rectangle(location.X, location.Y, 15, 15));
                            e.Graphics.FillRectangle(new SolidBrush(this.BoxColor), new Rectangle(location.X, location.Y, 15, 15));
                        }
                    }
                }
                catch (Exception ex)
                {
                    STErrorDialog.Show("Failed to paint STDataGridView!", "STDataGridView", ex.ToString());
                }
            }

            return;

            /*      using (Pen gridLinePen = new Pen(gridBrush))
             * {
             *    // Erase the cell.
             *    e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
             *
             *    // Draw the grid lines (only the right and bottom lines;
             *    // DataGridView takes care of the others).
             *    e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left,
             *        e.CellBounds.Bottom - 1, e.CellBounds.Right - 1,
             *        e.CellBounds.Bottom - 1);
             *    e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,
             *        e.CellBounds.Top, e.CellBounds.Right - 1,
             *        e.CellBounds.Bottom);
             *
             *
             *    // Draw the text content of the cell, ignoring alignment.
             *    if (e.Value != null)
             *    {
             *        e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,
             *            Brushes.Crimson, e.CellBounds.X + 2,
             *            e.CellBounds.Y + 2, StringFormat.GenericDefault);
             *    }
             *    e.Handled = true;
             */

            /*     e.Paint(e.CellBounds, DataGridViewPaintParts.All & DataGridViewPaintParts.ContentForeground);
             *
             *   RadioButtonState state = RadioButtonState.CheckedDisabled;
             *
             *   var Cell = Rows[e.RowIndex].Cells[e.ColumnIndex];
             *
             *   DataGridViewCheckBoxCell chkchecking = Cell as DataGridViewCheckBoxCell;
             *
             *   bool IsChecked = (bool)(Convert.ToBoolean(chkchecking.Value) == true);
             *
             *   if (IsChecked)
             *       state = RadioButtonState.CheckedNormal;
             *
             *   var size = RadioButtonRenderer.GetGlyphSize(e.Graphics, state);
             *   var location = new Point((e.CellBounds.Width - size.Width) / 2, (e.CellBounds.Height - size.Height) / 2);
             *
             *   //Draw cell
             *   e.Graphics.FillRectangle(new SolidBrush(BackgroundColor), e.CellBounds);
             *
             *   if (IsChecked)
             *   {
             *       e.Graphics.DrawImage(this.TickTock, location.X, location.Y, 12, 12);
             *   }
             *   else
             *   {
             *       //   e.Graphics.FillRectangle(new SolidBrush(this.BoxColor), new Rectangle(location.X, location.Y, 15, 15));
             *       e.Graphics.FillRectangle(new SolidBrush(this.BoxColor), new Rectangle(location.X, location.Y, 15, 15));
             *   }*/
        }