Peter Kiers
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
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
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.
to ensure that cursor will be visible use this:
procedure TForm1.Button3Click(Sender
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.Clearscreen1Clic k(Sender: TObject);
begin
// Check current cursor
if (MyDrawingPanelX1.Cursor = crDefault) then
// Clear cursor
MyDrawingPanelX1.Cursor:=c rNone
else
// Reset cursor back to default
MyDrawingPanelX1.Cursor:=c rDefault;
end;
---
Regards,
Russell
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.Clearscreen1Clic
begin
// Check current cursor
if (MyDrawingPanelX1.Cursor = crDefault) then
// Clear cursor
MyDrawingPanelX1.Cursor:=c
else
// Reset cursor back to default
MyDrawingPanelX1.Cursor:=c
end;
---
Regards,
Russell
ASKER
Hi,
procedure TMainForm.Clearscreen1Clic k(Sender: TObject);
begin
// Check current cursor
if (MyDrawingPanelX1.Cursor = crDefault) then
// Clear cursor
MyDrawingPanelX1.Cursor:=c rNone
else
// Reset cursor back to default
MyDrawingPanelX1.Cursor:=c rDefault;
end;
When I test this the cursor doesn't dissapear.
P.
procedure TMainForm.Clearscreen1Clic
begin
// Check current cursor
if (MyDrawingPanelX1.Cursor = crDefault) then
// Clear cursor
MyDrawingPanelX1.Cursor:=c
else
// Reset cursor back to default
MyDrawingPanelX1.Cursor:=c
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
Russell
ASKER
Yes.
Which cursor you want to hide
Peter, do you mean the application's cursor or the little white line/undescore - the command-window-like cursor you set with DrawCursor() ?
ASKER
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.Clearscreen1Clic k(Sender: TObject);
begin
MyDrawingPanelx1.ClearCurs or;
end;
procedure TMyDrawingPanelX.ClearCurs or;
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.
I may have found a solution to hide it
but how can I make it appear again?
To hide it :
procedure TMainForm.Clearscreen1Clic
begin
MyDrawingPanelx1.ClearCurs
end;
procedure TMyDrawingPanelX.ClearCurs
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 ;)
Oh I see dinilud noticed the same possible misunderstanding ;)
It would have helped if "cursor" was better defined in this q.
ASKER
Sorry, my mistake.
change DrawCursor;
procedure TMyDrawingPanelX.DrawCurso r(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;
procedure TMyDrawingPanelX.DrawCurso
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.SetCursor Visible(co nst 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;
procedure TMyDrawingPanelX.SetCursor
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
ASKER
Sorry, ignore my last comment.
It works fine...
Greetings,
Peter Kiers
It works fine...
Greetings,
Peter Kiers
procedure TMainForm.Clearscreen1Clic k(Sender: TObject);
begin
MainForm.MyDrawingPanelx1. CursorFlas hTimer.Ena bled:= not MyDrawingPanelX1.CursorVis ible;
MyDrawingPanelX1.CursorVis ible:=not MyDrawingPanelX1.CursorVis ible;
end;
begin
MainForm.MyDrawingPanelx1.
MyDrawingPanelX1.CursorVis
end;
ASKER
Thank you for all the help.
Peter
Peter
ShowCursor(False)
ziolko.