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

  • Home
  • SEARCH
  • 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 1028437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:23:16+00:00 2026-05-16T12:23:16+00:00

I have some specified region on the screen (not on the form, but on

  • 0

I have some specified region on the screen (not on the form, but on the screen), for example, it’s region in the upper-right corner of the screen.

Rectangle specifiedRegion = new Rectangle(*,*,*,*);

I want to implement mouse over and mouse click event for that region. When mouse was over that region, some button or picture appeared in that region. If user clicked that region, mouse click event executed.

How can I do it ? Please, provide some code or good links.

C#, VS 2008, .net 2.0, 3.5

  • 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-16T12:23:16+00:00Added an answer on May 16, 2026 at 12:23 pm

    Just a warning before we get started that the solution isn’t going to be pretty, AFAIK you cannot do this completely within managed code.

    Now then:

    In order to intercept messages to other application you are going to need to make some native calls using User32.dll. If you want to figure all this out the hard way you want to start with SetWindowsHookEx.

    Assuming you aren’t a masochist there is a nice C# library I found on CodeProject that will make life much easier than manually trying to intercept those messages yourself. Setup a callback for the mouse messages with the X and Y coordinates for the mouse position you can determine if it is within the bounds of your Rectangle using its Contains method.

    specifiedRegion.Contains(mouseLocation); //where mouseLocation is a Point
    

    User32 also has the functions you will need to get a Device Context for the screen:

    [DllImport("User32.dll")]
    public static extern IntPtr GetDC(IntPtr hwnd);
    
    [DllImport("User32.dll")]
    public static extern void ReleaseDC(IntPtr dc);
    

    To get the DC for the screen use the following call to GetDC:

    IntPtr screenDC = GetDC(IntPtr.Zero);
    

    With this DC we can get our C# Graphics object and start drawing.

    Graphics g = Graphics.FromHdc(screenDC);
    

    Remember to dispose the Graphics object and release the DC after you finish with it or you will have a memory leak.

    g.Dispose();
    ReleaseDC(screenDC);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some logic in a method that operates on a specified type and
I have plotted a contour map but i need to make some improvements. This
I have seen this question asked previously but can not find a clear explanation
I have some bins with different capacities and some objects with specified size. The
I have some specific id like 1,2,5,11,64589 in solr (int type) I want to
I'm trying to filter some XML in JavaScript using E4X and have some specific
I have some photos in specific drive on a hard disk, these photos all
Details on fonts: When you have some text in specific font, there's a header
I have some code that will change the background color of a specific label
I have some script in my default page that redirects users to language specific

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.