Link to home
Start Free TrialLog in
Avatar of Peter Kiers
Peter KiersFlag for Netherlands

asked on

How to hide the cursor

Dear Experts,

I have made a little example of a telnet-programm
it contains only a main menu and my component.
When you execute it you see only the mainmenu
and a black canvas with a white cursor on it.

But I want to hide the cursor and lock the canvas
when the programm startup or when I choose menu-
item Clear screen.

And show the cursor and unlock the canvas
when I choose menu-item Fill Buffer.

Who can help me? PLEASE.

The example is on my site:
http://members.home.nl/peterkiers/
(Beneath the Under Construction bar you see a floppy-disk)

Greetings,

Peter Kiers
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

try this:
ShowCursor(False)

ziolko.
note that if you call ShowCursor(False) twice and you want cursor visible again you have to call ShowCursor(True) also twice.
to ensure that cursor will be visible use this:

procedure TForm1.Button3Click(Sender: TObject);
var ref: Integer;
begin
  ref := ShowCursor(True);
  while Abs(ref) <> 0 do
    ref := ShowCursor(ref < 0);
end;


ziolko.
Peter,
You might want to only clear the cursor when its over you console like component. If you hide the cursor, then it does it for the whole app (menu items, etc) which may not be desireable.

eg:

procedure TMainForm.Clearscreen1Click(Sender: TObject);
begin

  // Check current cursor
  if (MyDrawingPanelX1.Cursor = crDefault) then
     // Clear cursor
     MyDrawingPanelX1.Cursor:=crNone
  else
     // Reset cursor back to default
     MyDrawingPanelX1.Cursor:=crDefault;

end;

---

Regards,
Russell
Avatar of Peter Kiers

ASKER

Hi,

procedure TMainForm.Clearscreen1Click(Sender: TObject);
begin
  // Check current cursor
  if (MyDrawingPanelX1.Cursor = crDefault) then
     // Clear cursor
     MyDrawingPanelX1.Cursor:=crNone
  else
     // Reset cursor back to default
     MyDrawingPanelX1.Cursor:=crDefault;
end;

When I test this the cursor doesn't dissapear.

P.
Did you bind the OnClick event of the menu item (Clearscreen1) to this procedure? I have tested this, and its the only explanation I can come up with. (place a debug break on the first code line and make sure it gets hit).

Russell
Yes.
Which cursor you want to hide
Avatar of TName
TName

Peter, do you mean the application's cursor or the little white line/undescore -  the command-window-like cursor you set with DrawCursor() ?
The one on my component.

I may have found a solution to hide it
but how can I make it appear again?

To hide it :

procedure TMainForm.Clearscreen1Click(Sender: TObject);
 begin
 MyDrawingPanelx1.ClearCursor;
end;

procedure TMyDrawingPanelX.ClearCursor;
var
  xpos, ypos: integer;
begin
  if (Lastcursorx = -1) or (Lastcursory = -1) then exit;
  xpos := (Lastcursorx * FontWidthPix) - FontWidthPix;
  ypos := (Lastcursory * FontHeightPix) - 1;
  with Canvas do
  begin
    if csrShape = csrUnderLine then
    begin
      Pen.Mode := pmBlack;
      Pen.Color := ColorBlack;
      Brush.Style := bsSolid;
      Brush.Color := ColorBlack;
      MoveTo(xpos, ypos);
      LineTo(xpos + FontWidthPix, ypos);
    end
    else
    begin
      Pen.Mode := pmXor;
      Pen.Color := ColorBlack;
      Brush.Style := bsSolid;
      Brush.Color := ColorBlack;
      Rectangle(xpos, ypos - FontHeightPix + 1, xpos + FontWidthPix, ypos);
    end;
  end;
end;


P.
>Which cursor you want to hide
Oh I see dinilud noticed the same possible misunderstanding ;)
It would have helped if "cursor" was better defined in this q.
Sorry, my mistake.
change DrawCursor;

procedure TMyDrawingPanelX.DrawCursor(x, y: integer);
var
  xpos, ypos: integer;
begin

 if fCursorVisible then
 begin
  xpos := (CsrCol * FontWidthPix) - FontWidthPix;
  ypos := (CsrRow * FontHeightPix) - 1;
  with Canvas do
  begin
      if csrShape = csrUnderLine then
      begin
        Pen.Mode := pmWhite;
        Pen.Color := ColorWhite;
        Brush.Style := bsSolid;
        Brush.Color := ColorWhite;
        MoveTo(xpos, ypos);
        LineTo(xpos + FontWidthPix, ypos);
      end
      else
      begin
        Pen.Mode := pmXor;
        Pen.Color := ColorWhite;
        Brush.Style := bsSolid;
        Brush.Color := ColorWhite;
        Rectangle(xpos, ypos - FontHeightPix + 1, xpos + FontWidthPix, ypos);
      end;
  end;
 end;
 LastcursorX := CsrCol;
 LastcursorY := CsrRow;

end;
Change this also

procedure TMyDrawingPanelX.SetCursorVisible(const Value: boolean);
var
  oldvalue: boolean;
begin
  oldvalue := fCursorVisible;
  if value <> oldvalue then
  begin
    fCursorVisible := Value;
    if value then
      DrawCursor(CsrCol, CsrRow)
    else
      ClearCursor;
  end;
end;
ASKER CERTIFIED SOLUTION
Avatar of dinilud
dinilud
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
WAUW, what help i am getting here.

I have test the application:

The showing and hiding cursor works fine.
But when I choose Connect a Connect-Dialog
screen appears, when i check Blinking cursor
and Cursor type Box I get exactly that after
pressing on the connectbutton, but then when
i choose Clearscreen, the cursor doesn't disappear
this time.

P.
Sorry, ignore my last comment.

It works fine...

Greetings,

Peter Kiers
procedure TMainForm.Clearscreen1Click(Sender: TObject);
begin
   MainForm.MyDrawingPanelx1.CursorFlashTimer.Enabled:=  not MyDrawingPanelX1.CursorVisible;
   MyDrawingPanelX1.CursorVisible:=not MyDrawingPanelX1.CursorVisible;
end;
Thank you for all the help.

Peter