Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7510751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:19:11+00:00 2026-05-29T23:19:11+00:00

I’m wondering how can I achieve horizontal (or vertical) snapping the mouse cursor to

  • 0

I’m wondering how can I achieve horizontal (or vertical) snapping the mouse cursor to a line. For example, on the Facebook timeline feature, when you hover the mouse over the line down the center, it snaps the cursor to the center. Bringing the mouse close to the line snaps it too.

I’d like to wrap this inside of a single custom control, rather than controls of a form. There will be either a vertical or horizontal line, and it must snap the mouse cursor to it when it gets anywhere close. I will be adding events which return the position of the line which was clicked. This control will also have a scrollbar, either vertical or horizontal, parallel to this line, and both scrollbars will never show at the same time. There’s a master property whether to display this line vertical or horizontal.

The mouse should not actually move position, but just the display of the cursor should somehow be tweaked to show it in the center of this line, while the actual X (or Y) position never changes. I don’t want to move the cursor, I want to display the cursor in the center of this line if it gets anywhere close. While the cursor is in this snapped position, it will display another custom cursor instead of the standard (or default) arrow.

All I need to know is how to handle, within this control, the event of a mouse pointer coming in the vicinity of this line and tweak the display of the cursor to be in the center of this line.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:19:12+00:00Added an answer on May 29, 2026 at 11:19 pm

    Snapping requires you to snap something.

    • in AutoCAD the “cursor” is actually a horizontal and vertical line intersecting where the “cursor” is
    • Photoshop uses the Windows mouse, but snaps the effect to guidelines
    • Facebook snaps a little + sign to a spot on the timeline

    You need to track the mouse’s position (i.e. OnMouseMove) and if the cursor is “close enough” you can then decide what to do.

    Here’s a little sample program where i have an imaginary vertical line at 150px from the left. If i get close enough to that line, a little Facebook + appears:

    enter image description here

    const
        centerLine = 150; //"line" is at 150px from the left
        tolerance = 15; //15px on either size is about good.
    
    procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    begin
        if IsMouseNearLine(x, y) then
        begin
            //We're on the centerline-ish. React by...
            //...changing the cursor to a <->
            Self.Cursor := crSizeWE;
    
            //and maybe let's put a "+" there, like Facebook
            if (FPlusLabel = nil) then
            begin
                FPlusLabel := TLabel.Create(Self);
                FPlusLabel.Parent := Self;
                FPlusLabel.Caption := '+';
                FPlusLabel.Alignment := taCenter;
                FPlusLabel.Font.Color := $00996600; //Windows UX "Main Instruction" color
                FPlusLabel.Font.Style := FPlusLabel.Font.Style + [fsBold];
            end;
    
            FPlusLabel.Left := centerLine-(FPlusLabel.Width div 2);
            FPlusLabel.Top := Y-(FPlusLabel.Height div 2);
            FPlusLabel.Visible := True;
        end
        else
        begin
            Self.Cursor := crDefault;
            if Assigned(FPlusLabel) then
                FPlusLabel.Visible := False;
        end;
    end;
    
    function TForm1.IsMouseNearLine(X, Y: Integer): Boolean;
    begin
        if (x >= (centerLine-tolerance)) and (x <= (centerLine+tolerance)) then
        begin
            //we're close-ish to the line
            Result := true;
        end
        else
            Result := False;
    end;
    

    Things start to get hairy when you have other controls, each needing to play along with the MouseMove messages. But it’s not too bad if you forward them all to a single handler; performing client-to-screen-to-formClient before you do.

    Note: Any code is released into the public domain. No attribution required.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
i got an object with contents of html markup in it, for example: string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.