Solved

Change EditBox color

Posted on 2003-11-28
13
309 Views
Last Modified: 2010-04-05
Var
    Hcol: HDC;

Begin
 Hcol:=GetWindowDC(HandleOfEditBox);
 SetBkColor(HCol,RGB(255,0,0));
 SetTextColor(Hcol,RGB(255,0,0));
End;

Ok any idea why this does not work?
0
Comment
Question by:craig_capel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
13 Comments
 

Accepted Solution

by:
Brr earned 50 total points
ID: 9838280
Dont know - but you can use the Color and Font.Color properties of the editbox
0
 
LVL 2

Author Comment

by:craig_capel
ID: 9838313
I am not using the VCL, i need to use windows API
0
 
LVL 3

Assisted Solution

by:JDuncan
JDuncan earned 50 total points
ID: 9838532
It may be that you are not drawing to the edit box eith the nex settings because this chages the text.

procedure TForm1.Button1Click(Sender: TObject);
Var
  Hcol: HDC;
  mystr : array [0..5] of char;
Begin
 mystr:='abcdef';
 Hcol:=GetWindowDC(Edit1.Handle);
 label1.caption:=inttohex(hcol,8);
 SetBkColor(HCol,RGB(0,100,0));
 SetTextColor(Hcol,RGB(128,0,0));
 TextOut(Hcol,0,0,myStr,5);
 ReleaseDC(Edit1.Handle,Hcol);
end;

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:craig_capel
ID: 9838585
I see what that's doing but it's not changing all of the edit box to a different color, just the text, but hey it's something to go on thanks....

i will keep trying...
0
 
LVL 2

Author Comment

by:craig_capel
ID: 9838590
Chances are i am going about it the wrong way, maybe it's a different call :O
0
 
LVL 3

Expert Comment

by:JDuncan
ID: 9838604
get the text and re draw it, you could maybe use the invalidaterect call to force a redraw or just do this

 Hcol:=GetWindowDC(Edit1.Handle);
 SetBkColor(HCol,RGB(0,100,0));
 SetTextColor(Hcol,RGB(128,0,0));
 GetWindowText(Hcol,myStr,6);
 TextOut(Hcol,0,0,myStr,5);
 ReleaseDC(Edit1.Handle,Hcol);
0
 
LVL 3

Expert Comment

by:JDuncan
ID: 9838721
This is strange , when you set the backgroud color the systems reports it as changed to
the new value .

It looks like you are only changing the windows context and this may be causing the delphi edit box to re paint to the original settings.

You amy have to create the edit box using windows calls instead of delphi calls to do what you want to do.


0
 
LVL 2

Author Comment

by:craig_capel
ID: 9840333
I use CreateWindowEx to make my edit control, there are no params to set the color of the edit box, you should be able to take the handle of the edit box (from any application) and with nothing more than the handle change the edit color box like doing...

EditBox1.Color:=$FF00FF;

That's all i am trying to do but in Win32 API
0
 
LVL 3

Expert Comment

by:JDuncan
ID: 9845336
What operating system are you using <=win98 or >=2000
0
 
LVL 2

Author Comment

by:craig_capel
ID: 9846824
Win2K
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 356
Comparing dates in Delphi. Greater than/ Less than 3 295
Delphi selector screen 2 92
Correct Component for Shopping Cart. 2 121
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question