Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to output an "up arrow" or "down arrow" character...

Posted on 2014-01-31
11
Medium Priority
?
481 Views
Last Modified: 2014-02-15
Hi Experts...
    I've got a CheckListBox where I'd like to be able to show for each individual item in the list, a character that indicates "ascending" or descending". In other words, I'd like to be able to tack on a character at the end of each of the TString items, that looks like an "up arrow" or a "down arrow"... or a little upwards/downwards pointing triangle would do too. Do you know of any escape character or ALT sequence that would let me output such a character?

Thanks!
    Shawn
0
Comment
Question by:shawn857
  • 6
  • 4
11 Comments
 
LVL 28

Expert Comment

by:Sinisa Vuk
ID: 39825339
Your intention is to move items up/down in list? Can you draw your idea?
May be is solution to add two buttons below/on right of box and this buttons get selected item and moves up/down.
0
 

Author Comment

by:shawn857
ID: 39825889
No no, I don't want to move items in a list.... not at all. I want to know what kind of "escape character" or "escape sequence" to make an image of up arrow or down arrow, or an up triangle or down triangle. Do you see?

Thanks
   Shawn
0
 

Author Comment

by:shawn857
ID: 39827305
I think I better explain more clearly what I'm doing and what I'm asking: In my app, I let the user make some specifications on how to sort a file of data. I use a TChecklistBox to display the various fields of the record, and the user can check off the fields he wishes to use as sort keys. OK, no problem there. What I'd like to be able to let the user also do is to specify whether the sort order of these sort keys be Ascending or Descending. I figured if I could somehow display an indicative "up arrow" or "down arrow" following the name of the sort key shown in the TCheckListBox items, then the user could just double-click an item to toggle this arrow up or down, to mean Ascending or Descending. Alternatively, is there a way to show a image file within an item in a TCheckListBox?

Thanks!
   Shawn
0
Technology Partners: 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 32

Accepted Solution

by:
Ephraim Wangoya earned 2000 total points
ID: 39829244
Use custom draw event of checklist box, here is a simple example using arrows stored in an image list object

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ImgList, StdCtrls, CheckLst;

type
  TForm1 = class(TForm)
    CheckListBox1: TCheckListBox;
    ImageList1: TImageList;
    procedure CheckListBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.CheckListBox1DrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
  DC: HDC;
  Title: string;
  R: TRect;
  ImageIndex: Integer;
  BP: TBitmap;
begin
  DC := TCheckListBox(Control).Canvas.Handle;
  FillRect(DC, Rect, GetStockObject(WHITE_BRUSH));
  Title := TCheckListBox(Control).Items[Index];
  DrawText(DC, PChar(Title), Length(Title), Rect, DT_SINGLELINE or DT_VCENTER or DT_LEFT or DT_END_ELLIPSIS);

  BP := TBitmap.Create;
  try
    ImageList1.GetBitmap(Index MOD 2, BP);
    BitBlt(DC, Rect.Right - 17, Rect.Top + 1, 16, 16, BP.Canvas.Handle, 0, 0, SRCCOPY);
  finally
    BP.Free;
  end;
end;

end.

Open in new window


Form
object Form1: TForm1
  Left = 192
  Top = 114
  Width = 286
  Height = 480
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object CheckListBox1: TCheckListBox
    Left = 72
    Top = 56
    Width = 129
    Height = 169
    ItemHeight = 16
    Items.Strings = (
      'Item 1'
      'Item 2'
      'Item 3'
      'Item 4'
      'Item 5')
    Style = lbOwnerDrawFixed
    TabOrder = 0
    OnDrawItem = CheckListBox1DrawItem
  end
  object ImageList1: TImageList
    Left = 72
    Top = 16
    Bitmap = {
      494C010102000400040010001000FFFFFFFFFF00FFFFFFFFFFFFFFFF424D3600
      0000000000003600000028000000400000001000000001001000000000000008
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      007C000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      007C000000000000000000000000000000000000000000000000000000000000
      007C000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      007C000000000000000000000000000000000000000000000000000000000000
      007C000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      007C00000000000000000000000000000000000000000000000000000000007C
      007C007C00000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      007C00000000000000000000000000000000000000000000000000000000007C
      007C007C00000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      007C0000000000000000000000000000000000000000000000000000007C007C
      007C007C007C0000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000007C007C007C
      007C007C007C007C0000000000000000000000000000000000000000007C007C
      007C007C007C0000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000000000000000000000000007C007C
      007C007C007C0000000000000000000000000000000000000000007C007C007C
      007C007C007C007C000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000000000000000000000000007C007C
      007C007C007C0000000000000000000000000000000000000000000000000000
      007C000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000000000000000000000000000007C
      007C007C00000000000000000000000000000000000000000000000000000000
      007C000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000000000000000000000000000007C
      007C007C00000000000000000000000000000000000000000000000000000000
      007C000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      007C000000000000000000000000000000000000000000000000000000000000
      007C000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      007C000000000000000000000000000000000000000000000000000000000000
      007C000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      007C000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000424D3E000000000000003E000000
      2800000040000000100000000100010000000000800000000000000000000000
      000000000000000000000000FFFFFF00FC7FFEFF00000000FC7FFEFF00000000
      FC7FFC7F00000000FC7FFC7F00000000FC7FF83F00000000FC7FF83F00000000
      E00FF01F00000000E00FF01F00000000F01FE00F00000000F01FE00F00000000
      F83FFC7F00000000F83FFC7F00000000FC7FFC7F00000000FC7FFC7F00000000
      FEFFFC7F00000000FEFFFC7F00000000}
  end
end

Open in new window

0
 

Author Comment

by:shawn857
ID: 39831197
Thanks Ewangoya, I'm going to play with this. Would you happen to have a small green "up arrow" image in the same style as these red arrows?

Alternatively, do you think it might be just simpler to just change the background color of the item to green (for "Ascending" sort order) or red (for "Descending" sort order)? Would that be easier? I'm thinking it might be more straightforward for my users and look less "cluttered"....

Thanks!
    Shawn
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 39831767
Have you tried glyFX library, they have some pretty nice images including arrow images for free.

http://www.glyfx.com/
0
 

Author Comment

by:shawn857
ID: 39852360
Ewangoya, do you have any thoughts on the other comment I asked:

"Alternatively, do you think it might be just simpler to just change the background color of the item to green (for "Ascending" sort order) or red (for "Descending" sort order)? Would that be easier? I'm thinking it might be more straightforward for my users and look less "cluttered"....

Is this even possible?

Thanks!
    Shawn
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 39852827
You are better off working with the arrows. A much smaller image would look better.

With color coding you would have to explain to your users what each color means, so you would need some space to add that label, and using hints just makes the screen look crowded
0
 

Author Comment

by:shawn857
ID: 39854321
But would it be difficult to change the background color of each item? Is there a property for that, or would I still have to "OwnerDraw" each item manually? I would really only use two colors (green and red) so there wouldn't be much explanations needed to my users...

Thanks!
   Shawn
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 39858743
You would still have to draw it yourself, there is no property for that
0
 

Author Closing Comment

by:shawn857
ID: 39861972
Thank you Ewangoya!

Cheers
   Shawn
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Loops Section Overview
Suggested Courses

783 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