Whenever I run this, and open the color dialog, there are many colors that do not having a proper name, the listbox will show something like "ffff8000"(Orange-Yellow). Is there another way of pushing the proper name? Is there a proper Color Name library I can reference in code?
colorDialog1.ShowDialog();
cl.Add(colorDialog1.Color.Name);
listBox1.Items.AddRange(cl.ToArray());
The .NET framework defines the KnownColor enum, you could use it to convert a color value to a name. It won't be a complete solution, it doesn't have "Orange Yellow". But many of the common colors are present. For example:
public static Color LookupKnownColor(uint c) {
int crgb = (int)(c & 0xffffff);
foreach (KnownColor kc in Enum.GetValues(typeof(KnownColor))) {
Color map = Color.FromKnownColor(kc);
if (!map.IsSystemColor) {
if ((map.ToArgb() & 0xffffff) == crgb)
return map;
}
}
return Color.FromArgb(unchecked((int)(c | 0xff000000)));
}
Usage:
Color c = LookupKnownColor(0xffffff00);
Console.WriteLine(c.Name);
Output: Yellow
Related
I wonder whether it's possible to retrieve custom constant values set in the css file from the java code.
I went through the UIManager.themeConstants (as well as themeProps, you never know :)) but I could not find my custom constants in there.
I tried the following:
#Constants {
--color0: #C4DFE6;
}
int color = UIManager.getInstance().getThemeConstant("--color0", 0);
System.out.println("COLOR0=" + color);
color = UIManager.getInstance().getThemeConstant("color0", 1);
System.out.println("COLOR0=" + color);
color = UIManager.getInstance().getThemeConstant("var(--color0)", 2);
System.out.println("COLOR0=" + color);
color = UIManager.getInstance().getThemeConstant("var(color0)", 3);
System.out.println("COLOR0=" + color);
I was hoping one of them to return my value: 0xC4DFE6.
The -- syntax is a special case for use within the CSS. Try using MyColor in the CSS with the same syntax in the Java side and it should work.
is there any thing got changed for images. Circular button shows different with projections. Button use to display proper circle before. Please see the screenshots for reference. Please advise.
Button b;
Button finished = new Button("");
FontImage.setMaterialIcon(finished, FontImage.MATERIAL_CHECK, 8.0f);
Test.makeBorderRound(finished);
Style bg = finished.getDisabledStyle();
finished.setDisabledStyle(bg);
b = finished;
b.setDisabledStyle(bg);
public static void makeBorderRound(Component cmp) {
makeBorderRound(cmp.getUnselectedStyle());
makeBorderRound(cmp.getSelectedStyle());
makeBorderRound(cmp.getPressedStyle());
makeBorderRound(cmp.getDisabledStyle());
}
public static void makeBorderRound(Style stl) {
stl.setBorder(RoundBorder.create().
rectangle(true).
color(stl.getBgColor()).
opacity(stl.getBgTransparency() & 0xff));
stl.setPaddingUnit(Style.UNIT_TYPE_DIPS);
stl.setPaddingLeft(1);
stl.setPaddingRight(1);
}
That's the icon peaking out from the edges of the round border. We fixed a bug where the background wasn't painted for some cases.
A simple workaround would be:
Button finished = new Button("");
finished.getAllStyles().setBgTransparency(0);
FontImage.setMaterialIcon(finished, FontImage.MATERIAL_CHECK, 8.0f);
finished.getAllStyles().setBgTransparency(255);
Test.makeBorderRound(finished);
By setting the bg transparency to 0 the icon will have transparency, this will then get overwritten by the second line after the icons are created.
I'm using GTK+3 (with the C language) to create a Battleship game, using an array of buttons, but I have some issues related to the color of them. I've already changed the background color of my array, and, now, I want to change the color of the buttons itself. I'm trying to use the gtk_widget_override_color() function to do that, but appears that it doesn't work in my code.
Could you take a look and maybe suggest other functions, which can work?
The code that I'm using is down here:
for(i=0;i<(x[0].n*x[0].n);i++){
gtk_widget_modify_bg(GTK_WIDGET(buttons[i]),GTK_STATE_NORMAL,&color);
gtk_widget_override_color(GTK_WIDGET(buttons[i]),GTK_STATE_NORMAL,&color2);
}
Color variable is of GdkColor type, and it has been defined with gdk_color_parse(), while color2 is of the type struct GdkRGBA, and it has been defined with the following lines:
color2.alpha = 0.8;
color2.blue = 0.819;
color2.red = 0;
color2.green = 0.807;
You should be using CSS for this. Something like:
GtkCssProvider *provider = gtk_css_provider_new ();
gtk_css_provider_load_from_data (provider,
"button { color: #123456; background-color: blue; }", -1, &error);
gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
This will give all your buttons the supplied foreground and background colors.
I have an array of horizontal fields which contains a bitmap and a labelfield each. The whole row should be clickable which is working so far, but how can I set the focus color properly? At the moment the onFocus and onUnfocus functions are being completely ignored.
This is the definition of my array:
for (int i = 0; i < listSize; i++) {
logInDetailManager[i] = new HorizontalFieldManager(
Manager.USE_ALL_WIDTH | Field.FOCUSABLE) {
protected void onFocus(int direction) {
super.onFocus(direction);
background_color = Color.RED;
invalidate();
}
protected void onUnfocus() {
invalidate();
background_color = Color.GREEN;
}
And this is how I add my horizontal fields:
logInDetailManager[i].setChangeListener(this);
logInDetailManager[i].add(dummyIcon[i]);
logInDetailManager[i].add(new LabelField("hello"));
logInDetailManager[i].add(new NullField(Field.FOCUSABLE));
add(logInDetailManager[i]);
Sorry, I couldn't comment to my own post yesterday since I'm new to Stackoverflow ;)
Here's how I solved it:
I removed onFocus() and onUnfocus() from the HFM and set the background color in the paint method so the whole row color is changed when focused:
protected void paint(Graphics graphics) {
graphics.setBackgroundColor(isFocus() ? Color.RED : Color.GREEN);
graphics.clear();
invalidate();
super.paint(graphics);
}
I also found out that if you want to set more complex backgrounds (i.e. with a gradient) you can also use the setBackground(int visual, Background background) method:
Background bg_focus = (BackgroundFactory
.createLinearGradientBackground(Color.GREEN, Color.LIGHTGREEN,
Color.LIGHTGREEN, Color.GREEN));
loginDetailManager[i].setBackground(VISUAL_STATE_FOCUS, bg_focus);
Make sure to delete you're paint method when using the setBackground function like that!
Hi
Im using AutomationFactory from silverlight to create and manipulate Exel worksheet.
And I want to change Color of a cell. If I understand correctly I must change this property
cell.Interior.Color =
However I want to change it to MyObject.Color (whitch is of tzpe Color)
MSDN Says i should use RGB function to assign cell.Interior.Color
But there is no RGB function in silverlight!?
How to change Color to something cell.Interior.Color will understand?
I made RGB function..
internal static int RGB(Color color)
{
string hexaString=color.B.ToString("X2") + color.G.ToString("X2") + color.R.ToString("X2");
int rgb = int.Parse(hexaString, System.Globalization.NumberStyles.HexNumber);
return rgb;
}