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 8617699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:55:29+00:00 2026-06-12T05:55:29+00:00

I have created a windows application control in C#.net to show some objects in

  • 0

I have created a windows application control in C#.net to show some objects in graphical mode.
To do so I created a rectangles depend on number of items I got in list and plot it over control by using Control OnPaint event.

Now I want to highlight that rectangle if mouse hovering on it.

Please check attached image for more clarity & suggest me how can I achieve it .

enter image description here

  • 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-06-12T05:55:30+00:00Added an answer on June 12, 2026 at 5:55 am

    Did you check the classical DrawCli example? It shows how a basic application should manage objects and tools.

    In short you should re-enumerate your list inside MouseMove event, get the item’s rect and set its IsFocused property to true if mouse pointer is inside that rect. Then redraw if something changed. You may even do that inside your OnPaint (check current mouse position) but then you have to always redraw everything inside MouseMove (and it’s a very bad idea).

    Kind of pseudo-code to explain what I mean:

    protected override void OnPaint(PaintEventArgs e)
    {
       foreach (GraphicalObject obj in Objects)
       {
          if (!obj.IsVisible)
                continue;
    
          Rectangle rect = obj.GetBounds(e.Graphics);
          if (!rect.Intersects(e.ClipRectangle))
             continue;
    
          obj.Draw(e.Graphics);
       }
    }
    

    GraphicalObject is the base type for all objects you can put on the screen. Objects is a property that contains the collection of them (GraphicalObjectCollection, for example). Now you code may be like this (note that this is far aways from true code, it’s just an example of a general technique):

    protected override OnMouseMove(MouseMoveEventArgs e)
    {
       bool needToRedraw = false;
    
       using (Graphics g = CreateGraphics())
       {
          foreach (GraphicalObject obj in Objects)
          {
             if (!obj.IsVisible)
                   continue;
    
             Rectangle rect = obj.GetBounds(e.Graphics);
             if (rect.Contains(e.Location))
             {
                if (!obj.IsFocused)
                {
                   obj.IsFocused = true;
                   needToRedraw = true;
                }
             }
             else
             {
                if (obj.IsFocused)
                {
                   obj.IsFocused = false;
                   needToRedraw = true;
                }
             }
    
             obj.Draw(e.Graphics);
          }
       }
    
       if (needToRedraw)
          Invalidate();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're writing an application for Windows tablet PCs. I have created a custom control
hello i have created one windows application in c# .net and its working fine
Im using c# .net windows application form. I have created many databases with many
I have created .Net usercontrol in C#. it is graphical control with a text
I have created Windows Application. In this, I have multiple tables in dataset, now
I have created a windows mobile application in Visual Studio. I want to templatize
I have created two forms in my Windows Application. One Form acts as a
We have created a simple wix project for a basic windows application. Everything builds
I have created blank C#/XAML Windows 8 application. Add simple XAML code: <Page x:Class=Blank.MainPage
I have created a Windows Phone 7.5 Silverlight application. Most of the design and

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.