Textbox background and text color not changing

hi

how to change the color of (n's)



a=50;
b=2;
ttt= a/b ; 
procedure SetOrigin(x0, y0) {
	global _x0, _y0;
	_x0 = x0; _y0 = y0;
}

procedure GfxSetColors(fgColor, bgColor) {
	GfxSetTextColor(fgColor); GfxSetBkColor(bgColor); 
	GfxSelectPen(fgColor); GfxSelectSolidBrush(bgColor);
}
procedure GfxFrame(titl,hheight, x, y, width, height, textColor, bgColor) {
	global _x0, _y0;
	x = x+_x0; y = y+_y0;
	GfxSetColors(textColor, bgColor);
    GfxRoundRect(x, y+0.5*hheight, x+width, y+height, 5, 5);
    if (titl != "") {
		w = GfxGetTextWidth(titl)*0.68; m = x+width*0.5;
		// GfxRectangle(m-w, y+1, m+w, y+hheight-1); 
		GfxRoundRect(m-w, y+1, m+w, y+hheight-1, 5, 5); 
		GfxDrawText(titl, x, y, x+width, y+hheight, 1|4|32);
		
    }
}

// Gui* part - Edit control
function SetNumber(idEdit, Value, x, y, width, height, textColor, bgColor) {
    global _x0, _y0;
	local rc;
	
    x = x+_x0; y = y+_y0;
    rc = GuiEdit( idEdit, x, y, width, height, 0); 
    GuiSetValue(idEdit, Value ); 
    GuiSetColors( idEdit, idEdit, 1, textColor, bgColor, textColor);
   
    return Value;
}
/*
Then modify all lines (replace EditNumber by SetNumber) starting from n3:
	n3 = SetNumber(3, (n2+n)/2, 180, 150, 80, 25, colorBlue, colorYellow);
// etc
*/
function EditNumber(idEdit, initialValue, x, y, width, height, textColor, bgColor) {
    global _x0, _y0;
	local rc;
	
    x = x+_x0; y = y+_y0;
    rc = GuiEdit( idEdit, x, y, width, height, 0); 
    if( rc == guiNew ) GuiSetValue(idEdit, initialValue ); 
    GuiSetColors( idEdit, idEdit, 1, textColor, bgColor, textColor);
   
    
    return GuiGetValue(idEdit);
}


 DT_VCENTER = 4 | 32; 
// format: 0 left, 1 center, 2 right
procedure GfxLabel(text, x, y, width, height, format) {
	global _x0, _y0;
	x = x+_x0; y = y+_y0;
	GfxDrawText( text, x, y, x+width, y+height, format | DT_VCENTER ); 
}

procedure GuiDemos(x,y) {
	local n,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,
	      n12,n13,n14,n15,n16,n17,n18,n19,n20
	      ,n21,n22,txt,textColor , bgColor;
	      
	// GfxSelectFont("Arial", 9); GuiSetFont("Arial", 10);
	SetOrigin(x,y);
	GfxFrame(" Third Of Tidal Trading System", 30, 0, 30, 600, 600, colorWhite, colorblack); // 30, 0, 30, 700, 180, colorWhite, colorblack(30, 0, 30, WITDTH, HIGHT, colorWhite, colorblack )
	SetOrigin(x+20,y+30);
	
	n = SetNumber(1, ttt, 10, 70, 30, 25, IIf(ttt> 10,colorBlue,colorDefault), IIf(ttt> 10,colorBlue,colorDefault));//textbox # , formula , LIFT / RIGHT , HIGHT/LOW , WIDTH OF THE TEXT BOX , HIGHT OF THE TEXT BOX.
	n1 = SetNumber(2, (10)/2, 50, 70, 30, 25, colorBlue, colorYellow);
	n2 = SetNumber(3, (10)/2, 90, 70, 30, 25, colorBlue, colorYellow);
	n3 = SetNumber(4, (10)/2, 130, 70, 30, 25, colorBlue, colorYellow);
	
	n4 = SetNumber(5, (12)/2, 170, 40, 30, 25, colorBlue, colorYellow);
	
	n5 = SetNumber(6, (10)/2, 210, 70, 30, 25, colorBlue, colorYellow);
    n6 = SetNumber(7, (10)/2, 250, 70, 30, 25, colorBlue, colorYellow);                                                                
	n7 = SetNumber(8, (10)/2, 290, 70, 30, 25, colorBlue, colorYellow);
	n8 = SetNumber(9, (10)/2, 330, 70, 30, 25, colorBlue, colorYellow);
	
 GfxLabel(" ......................................................................................................... ", 20, 100, 140, 30, 1);

	n9 = SetNumber(10,(14)/2,  10, 150, 30, 25, colorBlue, colorYellow);
	n10 = SetNumber(11,(14)/2, 50, 150, 30, 25, colorBlue, colorYellow);
	n11 = SetNumber(12,(14)/2, 90, 150, 30, 25, colorBlue, colorYellow);
	n12 = SetNumber(13,(14)/2, 130, 150, 30, 25, colorBlue, colorYellow);
	
	n13 = SetNumber(14, (16)/2, 170, 130, 30, 25, colorBlue, colorYellow);
	
	
	n14 = SetNumber(15, (14)/2, 210, 150, 30, 25, colorBlue, colorYellow);
	n15 = SetNumber(16, (14)/2, 250, 150, 30, 25, colorBlue, colorYellow);
	n16 = SetNumber(17, (14)/2, 290, 150, 30, 25, colorBlue, colorYellow);
	n17 = SetNumber(18, (14)/2, 330, 150, 30, 25, colorBlue, colorYellow);
	
	
	
}




x = Param("x_origin", 20, 0, 1980, 20);
y = Param("y_origin", 20, 0, 1024, 20);
demo = ParamToggle("Show Demo", "No|Yes", 1);

if (demo) {
	
	GuiDemos(x+80, y+80);
	
}

thank you

this what i mean

n = SetNumber(1, ttt, 10, 70, 30, 25, IIf(ttt> 10,colorBlue,colorDefault), IIf(ttt> 10,colorBlue,colorDefault));

it is not changing

thank you

AFL Function Reference - GUISETCOLORS (amibroker.com)

it clearly says
"Please note that currently only buttons support custom colors and custom border As for v6.21 Edit fields always use system look"

1 Like

hi

so it can be done or not

can i change the color based on the result of the formula
even i try to center the number in the box using ( GfxSetTextAlign ) but not working.

thank you

@ need for help: NO.

You are using edit fields in the code you posted, so at the moment, you cannot change their color with the functions provided.
The same for the alignment which for edit fields is also controlled by the system settings.

I suggest you study the documentation of the Gfx functions, starting from very basic examples of the dedicated tutorial, until you understand exactly how they work; then do the same for the GUI controls to see if you actually need them or not.

Attempts to adapt parts of an advanced formula such as @alligator's 'GfxToolkit.afl' (generously shared in the AFL library) without having a solid understanding of low-level features and Gui controls, in my opinion, it's a bad choice, which will likely result in hours of frustration.

1 Like

you are right i need simple GUI that I can control the size and the color .
I need to create design to add my formula.

i will try again .

thank you for explanation .

this the kind that i need

https://forum.amibroker.com/t/add-x-y-to-change-location-in-chart/32384/7?u=needhelp

Hello,
@beppe 's answer is perfect. However in case somebody would like to color borders of a Gui* control it's possible to fill the background using the very simple trick below:

// Quick hack: GuiEdit() with a border color

function ColoredEdit(id, x, y, width, height, color, init) {
	local vpad, hpad;
	vpad = hpad = 3;
	
	GfxFillSolidRect(x-hpad, y-vpad, x+width+hpad, y+height+vpad, color);
	rc = GuiEdit(id, x, y, width, height, notifyEditChange);
	if (rc == guiNew) GuiSetText(init, id);

	return GuiGetText(id);
}

function ColoredEditRange(id, x, y, width, height, a, b, init) {
	local vpad, hpad, color;
	vpad = hpad = 3; 
	color = colorRed;
	
	rc = GuiEdit(id, x, y, width, height, notifyEditChange);
	if (rc == guiNew) GuiSetText(""+init, id);
	res = StrToNum(StrTrim(GuiGetText(id), ""));
	if (!IsNan(res)) {
		if ((res >= a) && (res <= b)) color = colorGreen; else res = init;
	} else res = init;
	GfxFillSolidRect(x-hpad, y-vpad, x+width+hpad, y+height+vpad, color);
	
	return res;
}

/// Demo
GfxDrawText("Second Box: Please type a number between 1 and 10 incl.", 300, 50, 1000, 80);
text = ColoredEdit(1, 10, 50, 100, 30, colorAqua, "Yo!");
val = ColoredEditRange(2, 150, 50, 100, 30, 1, 10, -1);
Title = "First: ["+text+"]   Second:["+val+"]";

The second function/box shows how to use different colors for (in/)valid content. It works because GuiEdit() is always drawn on top.

Regards

2 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.