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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:45:52+00:00 2026-06-06T16:45:52+00:00

I am currently working on a sort of image processing tool that will contain

  • 0

I am currently working on a sort of image processing tool that will contain certain selection tools.
In order to show the current selection to the user (for example a circle) three events are used (all inside a certain canvas):

public MainWindow()
{        
    InitializeComponent();
}

private Ellipse _ellip = new Ellipse();
private Point _p = new Point();
private bool _mouse = false;
private double _xcor, _ycor;

private void mouseDown(object sender, MouseButtonEventArgs e)
{
    _p = Mouse.GetPosition(canvas1);
    _xcor = _p.X;
    _ycor = _p.Y;
    _mouse = true;
}

private void newPos(object sender, MouseEventArgs e)
{

    if (mouse)
    {
        _ellip.Visibility = Visibility.Visible;
        _p = Mouse.GetPosition(canvas1);
        _ellip.Margin = new Thickness((_xcor + _p.X) / 2 - Math.Sqrt((_xcor - _p.X) * (_xcor - _p.X) + (_ycor - _p.Y) * (_ycor - _p.Y)) / 2, (_ycor + _p.Y) / 2 - Math.Sqrt((_xcor - _p.X) * (_xcor - _p.X) + (_ycor - _p.Y) * (_ycor - _p.Y)) / 2, 0, 0);
        ellip.Height = Math.Sqrt((_xcor - _p.X) * (_xcor - _p.X) + (_ycor - _p.Y) * (_ycor - _p.Y));
        ellip.Width = Math.Sqrt((_xcor - _p.X) * (_xcor - _p.X) + (_ycor - _p.Y) * (_ycor - _p.Y));
    }

    InvalidateVisual();
}

private void mouseUp(object sender, MouseButtonEventArgs e)
{
    mouse = false;
    ellip.Visibility = Visibility.Hidden;
}

This works all fine under one condition: There is some kind of shape behind the circle. Somehow the events MouseLeftButtonDown/Up and MouseMove are not raised if used on empty area in the canvas1. Once I e.g. create a rectangle filling out the canvas, everything works just fine. But that brings with it another problem: If the rectangle is bigger than the canvas it basically goes out of the canvas and the events also work outside of the canvas (as long it is on top of the rectangle).
I really don’t understand what is going wrong 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-06T16:45:53+00:00Added an answer on June 6, 2026 at 4:45 pm

    Mouse button actions are recognized by WPF only if hit testing indicates that there is “something” under the mouse pointer. Therefore, you should implement HitTestCore(PointHitTestParameters) on your canvas.

    Here is an explanation how to override default hit testing: http://msdn.microsoft.com/en-us/library/ms752097.aspx#overriding_default_hit_testing .

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

Sidebar

Related Questions

I'm working on a program that will sort files based on extension I currently
I’m currently working on a website that will enable users to upload certain types
I'm currently working on a website that needs a sort of sticky footer, but
Im currently working on an RMI client that will talk to an RMI server
I'm currently working on a script that will allow users to drag decoration images
I'm currently working on a web application that's sort of similar to Google Reader
Currently working with converting SQLException error messages into messages that are more useful for
Im currently working on a game that uses multi touch to apply zoom to
I am currently working on a game engine that needs to move values between
I am currently working on a site that is being built on codeigniter, I

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.