Jump to content


Photo

Draw custom preview on TNXSpinEdit


  • Please log in to reply
3 replies to this topic

#1 array81

array81

    Senior Member

  • Members
  • PipPip
  • 290 posts
  • Gender:Male

Posted 15 February 2014 - 05:39 PM

I have a TNXSpinEdit. I have set it to accept only interger (from 1 to 5). Now I need show the preview box.
I want show a different color of preview box for any value of TNXSpinEdit, so when the user change the TNXSpinEdit value I need draw the preview box with a simple rectangle with different color.

I have try this code but NOT work:

procedure TMyForm.mySpinEditCustomPreviewDraw(Sender: TObject;
  PreviewRect: TRect);
var
  colIndex: Integer;
  col: TColor;
  r: TRect;
begin
  if (sneNome.Value > -1) and (sneNome.Value < 6) then
    begin
	  colIndex := StrToInt(sneNome.AsString);
	  if colIndex > 0 then
	    begin
		  col := GetBoxColor(colIndex);
		  r := PreviewRect;
		  InflateRect(r, -2, -2);
		  with mySpinEdit.Canvas do
		    begin
			  Brush.Color := col;
			  FillRect(r);
		    end;
	    end;
    end;
end;

Note TNXSpinEdit doesn't have DrawingOptions property...

#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 16 February 2014 - 07:04 PM

Hi,

You need to draw on EditInfo.Canvas:

                  with mySpinEdit.EditInfo.Canvas do
                        begin
                          Brush.Color := col;
                          FillRect(r);
                        end;

This should work now.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 array81

array81

    Senior Member

  • Members
  • PipPip
  • 290 posts
  • Gender:Male

Posted 19 February 2014 - 12:42 AM

Hi,

You need to draw on EditInfo.Canvas:

with mySpinEdit.EditInfo.Canvas do
begin
Brush.Color := col;
FillRect(r);
end;

This should work now.


Thank you, this work.
However I have a problem. Now the Preview Box is update only when user exit from TNXSpinEdit. I'd like change color when use change TNXSpinEdit value by keybord or buttons.

#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 21 February 2014 - 12:33 AM

You will need to call EditInfo.Invalidate every time you change value (onchange or OnEdit events)
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users