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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:34:40+00:00 2026-05-26T00:34:40+00:00

I have a custom UserControl that I am drawing using the GDI+. It is

  • 0

I have a custom UserControl that I am drawing using the GDI+. It is a transparent control which draws small shapes on top of the parent control.

All the parent window does is creates the control, gives it a Rectangle in which to draw itself, and then it receives events if the user clicks on the non-transparent areas.

The drawing part works perfectly, but right now what I need to do is to as seamlessly as possible forward all MouseMove, MouseClick, etc. events to the parent control IF those events occurred outside the shapes.

The shapes are drawn using GraphicsPath, and I am already able to detect if the mouse position is over a shape using GraphicsPath.IsVisible().

I want to do this in a way that requires zero or minimal extra code on the parent. The parent should not necessarily know whether the MouseMove event was forwarded from the child control or not, it should treat them all equally.

Do I have to pinvoke/SendMessage() to do this? Or is there an easier way using the .NET framework?

  • 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-26T00:34:40+00:00Added an answer on May 26, 2026 at 12:34 am

    This is possible in the winapi, the WM_NCHITTEST message is sent by the window manager to ask what part of the control the mouse is on top of. What you can do is return HTTRANSPARENT and it will ask the parent window. Here’s a sample UserControl that implements this. Catching the message requires overriding WndProc():

    public partial class UserControl1 : UserControl {
        public UserControl1() {
            InitializeComponent();
            paths = new List<GraphicsPath>();
            GraphicsPath example = new GraphicsPath();
            example.AddEllipse(new Rectangle(10, 10, 50, 30));
            paths.Add(example);
        }
        List<GraphicsPath> paths;
    
        protected override void OnPaint(PaintEventArgs e) {
            foreach (var path in paths) e.Graphics.FillPath(Brushes.Blue, path);
            base.OnPaint(e);
        }
    
        protected override void WndProc(ref Message m) {
            base.WndProc(ref m);
            // Trap WM_NCHITTEST on the client area
            if (m.Msg == 0x84 && m.Result == (IntPtr)1) {
                Point pos = new Point(m.LParam.ToInt32());
                pos = this.PointToClient(pos);
                bool oncurve = false;
                foreach (var path in paths)
                    if (path.IsVisible(pos)) oncurve = true;
                if (!oncurve) m.Result = (IntPtr)(-1);  // HTTRANSPARENT
            }
        }
    }
    

    Test code in the form:

        private void userControl11_MouseMove(object sender, MouseEventArgs e) {
            Console.WriteLine("On shape {0}", e.Location);
        }
    
        private void Form1_MouseMove(object sender, MouseEventArgs e) {
            Console.WriteLine("On form  {0}", e.Location);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom templated control(toolbar) that contains a custom usercontrol(button) The button uses
I have an custom control that extend System.Web.UI.UserControl. Is it possible to inherit user
I have a C# UserControl that hosts a TextBox. When the custom control is
I have a custom UserControl that have a StatusStrip. So, I resize this control
i have created a custom user control which im using on my main xaml
I have a custom user control in XAML that creates a ItemsControl which ItemsPanel
I have a custom user control that contains asp:ValidationSummary . It is placed on
I have a custom UserControl that I created as a navigation menu that parses
I have a Custom usercontrol that I want to enlarge. I tested this whit
How to Bring (form_x) to the front. I have a custom usercontrol which opens

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.