[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to get column and width coordinates of mouse on mouseclick

Posted on 2004-11-15
5
Medium Priority
?
522 Views
Last Modified: 2012-05-05
Let me first introduce what the object is:
I want to create a dataset, which consists of datapoints set using the mouse(with a click), with the points- in between the points set in this way -interpolated. The last thing I think I can do, my problem is with using the mouseclick, so:

I have a TStringDrawGrid object.
Now, what I want to do is get the column and width coordinates(in the TStringDrawGrid object)  of the location at which is clicked with the mouse.
I have been looking around to find some information but I can't get it to work. What I found:


type
  TForm1 = class(TForm)
    DrawDataForm: TDrawGrid;
    BitBtn1: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;


procedure TForm1.BitBtn1Click(Sender: TObject);
var
  X, Y : integer;
  Column, Row: Longint;

begin

  Form1.DrawDataForm.MouseToCell(X, Y, Column, Row);
  showmessage('Col ' + IntToStr(Column) +
    ',Row ' + IntToStr(Row));

end;

But this just returns -1, -1 all the time.

Furthermore, I was only able to set an event to a button(in the delphi editor->DrawDataForm->events), not to any procedure I created myself. How can I do this?

Help MUCH appreciated :)

0
Comment
Question by:reynaerde
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:Imthiyaz_ph
ID: 12583077
hai reynaerde

just place the above code into OnMouseUp event of the grid, then u will get the exact row and column index where the mouse was clicked.

to get the width of the column, use ColWidths property:

property ColWidths[Index: Longint]: Integer
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 1200 total points
ID: 12583081
?? usual in your sample x,y are not initialized and the values are randomly

should be more like


procedure TForm1.BitBtn1Click(Sender: TObject);
var
  p : TPoint;
  Column, Row: Longint;

begin
  GetCursorPos(p);  //or was it p := GetCurosrPos;
  p := Form1.DrawDataForm.screentoClient(p);
  Form1.DrawDataForm.MouseToCell(p.X, p.Y, Column, Row);
  showmessage('Col ' + IntToStr(Column) +
    ',Row ' + IntToStr(Row));

end;

just from head

about your other question you should explain more

meikl ;-)
0
 

Author Comment

by:reynaerde
ID: 12583275
Wow, that's excellent! Thanks!
(just didn't know anything about mouse events etc.)

Regarding my second question:

I would like to have a procedure like 'addpoint(Sender: TObject);' instead of 'TForm1.BitBtn1Click(Sender: TObject);'
Now, when I go to the Object Inspector(of the DrawDataForm: TDrawGrid; object) in the Delphi environment(using Delphi 7), there are 2 tabs:
'properties' and 'events'. When I go to the 'events' tab, I can select one of the events like 'onMouseClick' etc.
This gives me a dropdown menu. Now the problem is I can only select the 'BitBtn1Click' there, so my guess is I should declare the procedure somewhere, but I don't know where since it's not an object like the button is
(type
  TForm1 = class(TForm)
    DrawDataForm: TDrawGrid;
    BitBtn1: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
)
and I can't get a forward declaration.
Hope this explains what I mean, I really think it's something simple I'm missing here..

Regards,
reynaerde
0
 
LVL 27

Assisted Solution

by:kretzschmar
kretzschmar earned 1200 total points
ID: 12583300
>'properties' and 'events'. When I go to the 'events' tab, I can select one of the events >like 'onMouseClick'

you can one declared event on the dropdownmenu or create a new event-procedure by doubleclicking the empty evententry

meikl ;-)
0
 

Author Comment

by:reynaerde
ID: 12583361
Great, thanks :)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Loops Section Overview
Suggested Courses
Course of the Month18 days, 14 hours left to enroll

834 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