示例#1
0
 protected override bool FindEditColor(Color clr)
 {
     if (Properties.ShowSystemColors)
     {
         for (int i = 0; i < ColorListBoxViewInfo.SystemColors.Length; i++)
         {
             if (ColorListBoxViewInfo.SystemColors[i].Equals(clr))
             {
                 TabControl.OnSelectPageByCaption(Localizer.Active.GetLocalizedString(StringId.ColorTabSystem));
                 (TabControl.SelectedTabPage.Controls[0] as ColorListBox).SetSelectedIndex(i);
                 return(true);
             }
         }
     }
     if (Properties.ShowWebColors)
     {
         for (int i = 0; i < ColorListBoxViewInfo.WebColors.Length; i++)
         {
             if (ColorListBoxViewInfo.WebColors[i].Equals(clr))
             {
                 TabControl.OnSelectPageByCaption(Localizer.Active.GetLocalizedString(StringId.ColorTabWeb));
                 (TabControl.SelectedTabPage.Controls[0] as ColorListBox).SetSelectedIndex(i);
                 return(true);
             }
         }
     }
     if (Properties.ShowCustomColors)
     {
         TabControl.OnSelectPageByCaption(Localizer.Active.GetLocalizedString(StringId.ColorTabCustom));
         PWColorCellsControl ctl = TabControl.SelectedTabPage.Controls[0] as PWColorCellsControl;
         //PWColorCellsControlEx ctl = TabControl.SelectedTabPage.Controls[0] as PWColorCellsControlEx;
         for (int i = 0; i < PWColorCellsControlViewInfo.CellColorsRGB.Length; i++)
         {
             if (PWColorCellsControlViewInfo.CellColorsRGB[i] == clr)
             {
                 ctl.SelectedCellIndex = i;
                 return(true);
             }
         }
         PWColorCellsControlViewInfo vi = ctl._ViewInfo as PWColorCellsControlViewInfo;
         for (int i = 0; i < vi.CustomColors.Length; i++)
         {
             if (vi.CustomColors[i] == clr)
             {
                 ctl.SelectedCellIndex = i + PWColorCellsControlViewInfo.CellColorsRGB.Length;
                 return(true);
             }
         }
         ctl.SelectedCellIndex = PWColorCellsControlViewInfo.CellColorsRGB.Length;
     }
     TabControl.SelectedTabPageIndex = 0;
     return(false);
 }
 public PWColorCellsControl(PopupBaseForm shadowForm, int columnCount, int rowCount)
 {
     if (columnCount * rowCount > 64)
     {
         throw new Exception("Incorrect cells count.");
     }
     SetStyle(ControlStyles.UserMouse, false);
     this.shadowForm = shadowForm;
     viewInfo        = new PWColorCellsControlViewInfo(this, columnCount, rowCount);
     painter         = new PWColorCellsControlPainter(columnCount * rowCount);
     properties      = null;
     lockFocus       = false;
     SetStyle(ControlStyles.AllPaintingInWmPaint | ControlConstants.DoubleBuffer, true);
 }
        protected override void DrawContent(ControlGraphicsInfoArgs info)
        {
            //PWColorCellsControlViewInfo vi = info.ViewInfo as PWColorCellsControlViewInfo;
            //vi.PaintAppearance.DrawBackground(info.Cache, vi.ClientRect);
            //for (int i = 0; i < cellsCount; i++)
            //{
            //    Rectangle cellBounds = vi.GetCellRect(i);
            //    info.Graphics.FillRectangle(new SolidBrush(vi.GetCellColor(i)), cellBounds);
            //    vi.CellBorderPainter.DrawObject(new BorderObjectInfoArgs(info.Cache, cellBounds, null, ObjectState.Pressed));
            //    if (i == vi.SelectedCellIndex)
            //        ControlPaint.DrawFocusRectangle(info.Graphics, Rectangle.Inflate(cellBounds, 2, 2));
            //}
            PWColorCellsControlViewInfo vi = info.ViewInfo as PWColorCellsControlViewInfo;

            vi.PaintAppearance.DrawBackground(info.Cache, vi.ClientRect);
            for (int i = 0; i < cellsCount; i++)
            {
                Rectangle cellBounds = vi.GetCellRect(i);
                info.Graphics.FillRectangle(new SolidBrush(vi.GetCellColor(i)), cellBounds);
                vi.CellBorderPainter.DrawObject(new BorderObjectInfoArgs(info.Cache, cellBounds, null, ObjectState.Pressed));
                if (i == vi.SelectedCellIndex)
                {
                    ControlPaint.DrawFocusRectangle(info.Graphics, Rectangle.Inflate(cellBounds, 2, 2));
                }
            }
            Rectangle r = vi.ContentRect;
            float     x = ColorCellsControlViewInfo.CellsInternval;
            float     y = vi.GetCellRect(0).Height * 7 + ColorCellsControlViewInfo.CellsInternval;

            DevExpress.Skins.Skin        currentSkin;
            DevExpress.Skins.SkinElement element;
            string elementName;

            currentSkin = DevExpress.Skins.CommonSkins.GetSkin(vi.LookAndFeel);
            elementName = DevExpress.Skins.CommonSkins.SkinTextBorder;
            element     = currentSkin[elementName];
            Color skinBorderColor = element.Border.All;

            elementName = DevExpress.Skins.CommonSkins.SkinGroupPanel;
            element     = currentSkin[elementName];
            Color skinBackColor = element.Color.BackColor;

            info.Graphics.DrawLine(new Pen(skinBorderColor), x, y + 1, 8 * vi.GetCellRect(0).Width + (8) * ColorCellsControlViewInfo.CellsInternval, y + 1);
            Rectangle stringRect = new Rectangle(0, (int)y + 2, 8 * (vi.GetCellRect(0).Width + ColorCellsControlViewInfo.CellsInternval + ColorCellsControlViewInfo.CellsInternval), vi.GetCellRect(0).Height);

            info.Graphics.FillRectangle(new SolidBrush(skinBackColor), stringRect);
            info.Graphics.DrawString("Right Click to Define Custom Color", vi.PaintAppearance.Font, vi.PaintAppearance.GetForeBrush(info.Cache), x, y + 2, vi.PaintAppearance.GetStringFormat(vi.DefaultTextOptions));
        }
示例#4
0
        PWColorCellsControl CreateColorCellsControl()
        {
            PWColorCellsControl control = new PWColorCellsControl(null, 8, 8);

            viewInfo = new PWColorCellsControlViewInfo(control, 8, 8);
            rItem    = new DevExpress.XtraEditors.Repository.RepositoryItemColorEdit();
            rItem.ShowColorDialog  = true;
            control.PopupContainer = container;
            control.Properties     = rItem;

            control.Properties.ShowCustomColors = false;
            control.EnterColor += new EnterColorEventHandler(OnEnterColor);
            //control.MouseUp += new MouseEventHandler(control_MouseUp);

            return(control);
        }
示例#5
0
        private int GetNearestBestClientHeight(int height, ColorListBox OwnerControl)
        {
            ColorListBoxViewInfo viewInfo = null;

            try
            {
                viewInfo = (ColorListBoxViewInfo)typeof(ColorListBox).InvokeMember("ViewInfo",
                                                                                   BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Instance,
                                                                                   null, OwnerControl, null);
            }
            catch
            {
                throw new Exception("ColorListBox doesn't contain 'ViewInfo' property");
            }
            int rowHeight = viewInfo.ItemHeight;
            int rows      = height / rowHeight;

            if (rows * rowHeight == height)
            {
                return(height);
            }
            return((rows + 1) * rowHeight);
        }