コード例 #1
0
        public void updateDisplayColor()
        {
            Color newColor = Color.FromArgb(_bytAlpha.Value, _bytRed.Value, _bytGreen.Value, _bytBlue.Value);

            rctColor.Fill = new SolidColorBrush(newColor);
            UnselectAllColors();
            SelectColor(newColor);
            HTMLColor selectedColor;

            selectedColor = PickColorFromList();
            if (selectedColor.IsCustomColor)
            {
                selectedColor = SelectWebSafeColor();
            }
            else
            {
                SelectWebSafeColor();
            }
            if (selectedColor.IsCustomColor)
            {
                selectedColor           = new HTMLColor(newColor.R, newColor.G, newColor.B);
                selectedColor.ColorName = _CustomColor.ColorName;
                selectedColor.A         = newColor.A;
            }

            tbColorNameBlack.Text = selectedColor.ColorName;
            tbColorNameWhite.Text = selectedColor.ColorName;



            HTMLColor colorForFields = new HTMLColor(selectedColor.R, selectedColor.G, selectedColor.B);

            colorForFields.A = newColor.A;
            FillTextFields(colorForFields);
        }
コード例 #2
0
        private void txtHex_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)   // Handles txtHex.KeyUp
        {
            if (!_GoodHexKeys.Contains(e.Key))
            {
                //delete last char
                txtHex.Text = txtHex.Text.Substring(0, txtHex.Text.Length - 1);
            }

            string textToUse = txtHex.Text;

            if (textToUse.Length > 0 && textToUse[0] == '0')
            {
                textToUse = textToUse.Substring(1);
            }
            if (textToUse.Length == 0)
            {
                textToUse = "0";
            }
            if (textToUse.Length < 3)
            {
                byte newByte = HTMLColor.FromHex(textToUse);
                Value = newByte;
                VisualStateManager.GoToState(txtHex, "Valid", true);
                txtHex.SelectionStart = txtHex.Text.Length;
            }
            else
            {
                VisualStateManager.GoToState(txtHex, "InvalidUnfocused", true);
            }
            //If e.Key = Key.Tab Then
            //    tabWasPressed = True
            //    Parent.tabOff(sender, Me)
            //}
        }
コード例 #3
0
        private void SetText(byte value)
        {
            string newText = HTMLColor.MakeSureIsTwo(HTMLColor.Hex(value));

            //If newText.Length < 2 Then newText = "0" & newText
            txtHex.Text = newText;
            txtDec.Text = value.ToString();
        }
コード例 #4
0
 //public void unselectAllWebSafeButtons()
 //    foreach (obj As Object In grdWebSafeColors.Children
 //        If obj.GetType Is GetType(Button)) {
 //            btn As Button = CType(obj, Button)
 //            //VisualStateManager.GoToState(btn, "", False)
 //            VisualStateManager.GoToState(btn, "Notselected", False)
 //        }
 //    }
 //}
 private void FillNamedColorsList()
 {
     _NamedColors = new List <HTMLColor>();
     foreach (KeyValuePair <string, string> nColor in _ColorsNamed)
     {
         HTMLColor hColor = new HTMLColor(nColor.Value);
         hColor.ColorName = nColor.Key;
         _NamedColors.Add(hColor);
     }
 }
コード例 #5
0
        } // Function

        private void btnWebSafeColor_Click(object sender, EventArgs e)
        {
            Button    btn    = (Button)sender;
            HTMLColor hColor = (HTMLColor)btn.Tag;

            ValueSlider.IgnoreChangeEvent = true;
            vSldAlpha.Value = hColor.A;
            vSldRed.Value   = hColor.R;
            vSldGreen.Value = hColor.G;
            vSldBlue.Value  = hColor.B;
            ValueSlider.IgnoreChangeEvent = false;
            updateDisplayColor();
        }
コード例 #6
0
        private void cmbColorNames_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)   //Handles cmbColorNames.SelectionChanged
        {
            HTMLColor selectedItem = (HTMLColor)cmbColorNames.SelectedItem;

            if (!selectedItem.IsCustomColor)
            {
                Color selectedColor = ((SolidColorBrush)selectedItem.Foreground).Color;

                ValueSlider.IgnoreChangeEvent = true;
                vSldAlpha.Value = selectedColor.A;
                vSldRed.Value   = selectedColor.R;
                vSldGreen.Value = selectedColor.G;
                vSldBlue.Value  = selectedColor.B;
                ValueSlider.IgnoreChangeEvent = false;
            }
            updateDisplayColor();
        }
コード例 #7
0
 private void FillColors()
 {
     _CustomColor               = new HTMLColor(0, 0, 0);
     _CustomColor.ColorName     = "Custom";
     _CustomColor.IsCustomColor = true;
     _CustomColor.A             = 0;
     cmbColorNames.Items.Add(_CustomColor);
     cmbColorNames.SelectedItem = _CustomColor;
     foreach (HTMLColor hColor in _NamedColors)
     {
         cmbColorNames.Items.Add(hColor);
     }
     SetLinkage(vSldRed, _bytRed, this);
     SetLinkage(vSldGreen, _bytGreen, this);
     SetLinkage(vSldBlue, _bytBlue, this);
     SetLinkage(vSldAlpha, _bytAlpha, this);
     vSldAlpha.Value = 255;
 }
コード例 #8
0
        private void sldValue_ValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs <Double> e) // Handles sldValue.ValueChanged
        {
            byte val = (byte)sldValue.Value;

            tbPercent.Text = String.Format("{1:##%}\r\n{0}\r\n{2:X2}", val, (val / 255.0), val);
            if (LinkedValue != null)
            {
                LinkedValue.Value = val;
            }
            if (txtHex.Text != HTMLColor.Hex(val) || txtDec.Text != sldValue.Value.ToString())
            {
                SetText(val);
                //SetBackColor(val)
            }
            if (!IgnoreChangeEvent && Parent != null)
            {
                Parent.updateDisplayColor();
            }
        }
コード例 #9
0
        private HTMLColor PickColorFromList()
        {
            HTMLColor colorFound = null;

            foreach (HTMLColor hColor in cmbColorNames.Items)
            {
                if (hColor.IsSelected)
                {
                    colorFound = hColor;
                    break;
                }
            }
            if (colorFound == null)
            {
                colorFound = _CustomColor;
            }
            cmbColorNames.SelectedItem = colorFound;
            return(colorFound);
        } // Function
コード例 #10
0
        private void SelectColor(Color newColor)
        {
            uint UIntColor = HTMLColor.GetUint(newColor.R, newColor.G, newColor.B);

            foreach (HTMLColor hColor in _NamedColors)
            {
                if (hColor.AsUInt == UIntColor && hColor.A != 0)
                {
                    hColor.IsSelected = true;
                    break;
                }
            }
            foreach (HTMLColor hColor in _WebSafeColors)
            {
                if (hColor.AsUInt == UIntColor && hColor.A != 0)
                {
                    hColor.IsSelected = true;
                    break;
                }
            }
        }
コード例 #11
0
        private HTMLColor SelectWebSafeColor()
        {
            HTMLColor foundColor = _CustomColor;

            foreach (object obj in grdWebSafeColors.Children)
            {
                if (obj.GetType() == typeof(Button))
                {
                    Button    btn    = (Button)obj;
                    HTMLColor hColor = (HTMLColor)btn.Tag;
                    if (hColor.IsSelected)
                    {
                        foundColor = hColor;
                        VisualStateManager.GoToState(btn, "Selected", false);
                    }
                    else
                    {
                        VisualStateManager.GoToState(btn, "Unselected", false);
                    }
                }
            }
            return(foundColor);
        } // Function
コード例 #12
0
        private void FillTextFields(HTMLColor col)
        {
            txtHexValue.Text          = "#" + col.AsHex();
            txtHexWithAlphaValue.Text = "#" + HTMLColor.AsHex(col.A) + col.AsHex();
            txtARGBValue.Text         = String.Format("argb({0},{1},{2},{3})", col.A, col.R, col.G, col.B);
            txtRGBAValue.Text         = String.Format("rgba({1},{2},{3},{0})", (col.A / 255).ToString("#.##"), col.R, col.G, col.B);

            string aShort     = HTMLColor.AsHex(col.A);
            string rShort     = HTMLColor.AsHex(col.R);
            string gShort     = HTMLColor.AsHex(col.G);
            string bShort     = HTMLColor.AsHex(col.B);
            bool   canBeShort = true;

            canBeShort = canBeShort && rShort[0] == rShort[1];
            canBeShort = canBeShort && gShort[0] == gShort[1];
            canBeShort = canBeShort && bShort[0] == bShort[1];
            if (canBeShort)
            {
                txtHexShortValue.Text = String.Format("#{0}{1}{2}", rShort[0], gShort[0], bShort[0]);
            }
            else
            {
                txtHexShortValue.Text = txtHexValue.Text;
            }


            canBeShort = canBeShort && aShort[0] == aShort[1];
            if (canBeShort)
            {
                txtHexWithAlphaShortValue.Text = String.Format("#{0}{1}{2}{3}", aShort[0], rShort[0], gShort[0], bShort[0]);
            }
            else
            {
                txtHexWithAlphaShortValue.Text = txtHexWithAlphaValue.Text;
            }
        }