static View GetFrontmostChildAt(ViewGroup viewGroup, int x, int y) { var locArray = new int[2]; for (int i = viewGroup.ChildCount - 1; i >= 0; i--) { var child = viewGroup.GetChildAt(i); child.GetLocationOnScreen(locArray); var frame = new AG.Rect( locArray [0], locArray [1], locArray [0] + child.Width, locArray [1] + child.Height); if (!frame.Contains(x, y)) { continue; } var childGroup = child as ViewGroup; if (childGroup != null) { var grandChild = GetFrontmostChildAt(childGroup, x, y); if (grandChild != null) { return(grandChild); } } return(child); } return(null); }
private bool IsHit(Droppable droppable, int x, int y) { Rect hitRect = new Rect(0, 0, droppable.View.Width, droppable.View.Height); OffsetDescendantRectToMyCoords(droppable.View, hitRect); return hitRect.Contains(x, y); }
private bool IsInIgnoredView(MotionEvent ev) { var rect = new Rect(); foreach (var v in _ignoredViews) { v.GetHitRect(rect); if (rect.Contains((int) ev.GetX(), (int) ev.GetY())) return true; } return false; }
bool OnDown (MotionEvent motionEvent) { if (_paused) { return false; } var rect = new Rect (); int childCount = _listView.ChildCount; var listViewCoords = new int[2]; _listView.GetLocationOnScreen (listViewCoords); int x = (int)motionEvent.RawX - listViewCoords [0]; int y = (int)motionEvent.RawY - listViewCoords [1]; View child; for (int i = 0; i < childCount; i++) { child = _listView.GetChildAt (i); child.GetHitRect (rect); if (rect.Contains (x, y)) { _downView = child; break; } } if (_downView != null) { mDownX = motionEvent.RawX; mDownY = motionEvent.RawY; _downPosition = _listView.GetPositionForView (_downView); if (_dismissCommand.CanExecute (_downPosition)) { _velocityTracker = VelocityTracker.Obtain (); _velocityTracker.AddMovement (motionEvent); } else { _downView = null; } } return false; }
public override bool OnTouchEvent(MotionEvent ev) { var hist = 0.0f; var deltaY = 0.0f; var listY = 0.0f; _historyEvent = ev; vT.AddMovement(ev); if (_overscrolling) { var firstOverscroll = _firstOverscroll; _firstOverscroll = false; if (ev.Action == MotionEventActions.Move && ev.HistorySize >= 1) { hist = ev.GetHistoricalY(0, 0); deltaY = ev.GetY() - hist; listY = _listView.GetY(); if (_header != null) { var headerY = _header.GetY(); if (deltaY > 0) { if ((int)Math.Ceiling(headerY) == (0)) { return _listView.DispatchTouchEvent(ev); } if (headerY + deltaY <= (0)) { UpdateHeaderPosition(deltaY); _listView.SetY(_listView.GetY() + deltaY); _listView.LayoutParameters.Height = (int)Math.Ceiling(_listView.LayoutParameters.Height + deltaY); _listView.Invalidate(); return true; } if (headerY + deltaY > 0) { deltaY = 0 - headerY; UpdateHeaderPosition(0 - headerY); _listView.SetY(_listView.GetY() + deltaY); _listView.LayoutParameters.Height = (int)Math.Ceiling(_listView.LayoutParameters.Height + deltaY); _listView.Invalidate(); return true; } } if (deltaY < 0) { _overscrolling = false; } } if (listY + deltaY <= 0) { deltaY = 0 - listY; _overscrolling = false; } else if (deltaY > 0) { deltaY *= 0.4f; } Log.Info("OverScrollingIntercept", "{0}", deltaY); _listView.SetY(_listView.GetY() + deltaY); _lastHistory = ev.HistorySize; } else if (ev.Action == MotionEventActions.Up) { _overscrolling = false; _lastHistory = 0; _listView.Animate().Y(_header != null ? _header.Height : 0.0f).SetDuration(250).Start(); } Log.Info("Interceptor", "Overscrolling True"); return true; } var hitRect = new Rect(); _header.GetHitRect(hitRect); if (hitRect.Contains((int)Math.Ceiling(ev.GetX()), (int)Math.Ceiling(ev.GetY()))) { return _header.DispatchTouchEvent(ev); } else { if (_header != null ) { var headerY = _header.GetY(); if (ev.Action == MotionEventActions.Move && ev.HistorySize >= 1) { hist = ev.GetHistoricalY(0, 0); deltaY = ev.GetY() - hist; if (deltaY < 0) { if ((int) Math.Ceiling(headerY) == (0 - _header.Height)) { return _listView.DispatchTouchEvent(ev); } if (headerY + deltaY >= (0 - _header.Height)) { UpdateHeaderPosition(deltaY); _listView.SetY(_listView.GetY()+deltaY); _listView.LayoutParameters.Height = (int)Math.Ceiling(_listView.LayoutParameters.Height - deltaY); _listView.RequestLayout(); return true; } else if (headerY + deltaY < (0 - _header.Height)) { deltaY = 0 - ( headerY + _header.Height); UpdateHeaderPosition(deltaY); _listView.SetY(_listView.GetY() + deltaY); _listView.LayoutParameters.Height = (int)Math.Ceiling(_listView.LayoutParameters.Height - deltaY); _listView.RequestLayout(); _listView.DispatchTouchEvent(ev); return true; } } _listView.DispatchTouchEvent(ev); return true; } else if(ev.Action == MotionEventActions.Up || ev.Action == MotionEventActions.Cancel) { vT.ComputeCurrentVelocity(1); long duration = Math.Abs((long)Math.Ceiling(Math.Abs(_header.Height) / vT.GetYVelocity(0))); if (duration < 750) { _header.Animate() .Y(0 - _header.Height) .SetDuration(duration) .SetInterpolator(new DecelerateInterpolator(1.0f)) .Start(); _listView.Animate() .Y(0) .SetDuration(duration) .SetInterpolator(new DecelerateInterpolator(1.0f)) .Start(); } return _listView.DispatchTouchEvent(ev); } } return _listView.DispatchTouchEvent(ev); } }
public override View GetSampleContent (Android.Content.Context con) { dlgAlert = new AlertDialog.Builder(con); dlgAlert.SetTitle("Results"); dlgAlert.SetPositiveButton("OK", (object sender, DialogClickEventArgs e) => { }); dlgAlert.SetCancelable(true); Title.Add ("Software"); Title.Add ("Banking"); Title.Add ("Media"); Title.Add ("Medical"); spinners = new Spinner(con); spinners.DropDownWidth = 500; spinners.SetBackgroundColor(Color.Gray); ArrayAdapter<String> dataAdapter = new ArrayAdapter<String> (con, Android.Resource.Layout.SimpleSpinnerItem, Experience); dataAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); spinners.Adapter = dataAdapter; Country.Add ("UAE"); Country.Add ("Uruguay"); Country.Add ("United States"); Country.Add ("United Kingdom"); Country.Add ("Ukraine"); Experience.Add ("1"); Experience.Add ("2"); autoComplete1 = new SfAutoComplete(con); autoComplete2 = new SfAutoComplete(con); text1s = new TextView(con); text2s = new TextView(con); text3s = new TextView(con); text4s = new TextView(con); text6s = new TextView(con); text11 = new TextView(con); text22 = new TextView(con); text33 = new TextView(con); text44 = new TextView(con); text55 = new TextView(con); text66 = new TextView(con); text77 = new TextView(con); text88 = new TextView(con); buttons = new Button(con); buttons.SetWidth(ActionBar.LayoutParams.MatchParent); buttons.SetHeight(40); buttons.Text = "Search"; buttons.SetTextColor(Color.White); buttons.SetBackgroundColor(Color.Gray); buttons.Click += (object sender, EventArgs e) => { GetResult(); //dlgAlert.SetMessage(count + " Jobs Found"); dlgAlert.SetMessage (cc + " Jobs Found"); dlgAlert.Create ().Show (); }; text11.SetHeight(10); text22.SetHeight(30); text33.SetHeight(10); text44.SetHeight(30); text55.SetHeight(10); text66.SetHeight(30); text77.SetHeight(10); text88.SetHeight(30); text1s.Text = "Job Search"; text1s.TextSize = 30; text1s.Typeface = Typeface.DefaultBold; text2s.Text = "Country"; text2s.TextSize = 16; text3s.Text = "Job Field"; text3s.TextSize = 16; text4s.Text = "Experience"; text4s.TextSize = 16; text6s.SetHeight(40); ArrayAdapter<String> adapters = new ArrayAdapter<String>(con, Android.Resource.Layout.SimpleListItem1, new Countrylist().Country); autoComplete1.LayoutParameters = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, 60); autoComplete1.SetAutoCompleteSource(adapters); autoComplete1.SuggestionMode = SuggestionMode.StartsWith; autoComplete1.MaximumDropDownHeight = 200; autoComplete1.Watermark = "Enter a country name"; ArrayAdapter<String> adapters1 = new ArrayAdapter<String>(con, Android.Resource.Layout.SimpleListItem1, Title); autoComplete2.SetAutoCompleteSource(adapters1); autoComplete2.LayoutParameters = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, 60); autoComplete2.SuggestionMode = SuggestionMode.Contains; autoComplete2.MaximumDropDownHeight = 200; autoComplete2.Watermark = "Starts with ’S’, ‘M’ or ‘B’"; ArrayAdapter<String> adapters2 = new ArrayAdapter<String>(con, Android.Resource.Layout.SimpleListItem1, Experience); spinners.Adapter = adapters2; spinners.LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, 60); LinearLayout linearLayout = new LinearLayout(con); linearLayout.SetPadding(20, 20, 20, 30); linearLayout.SetBackgroundColor(Color.Rgb(236, 236, 236)); linearLayout.LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); linearLayout.Orientation = Orientation.Vertical; linearLayout.AddView(text1s); linearLayout.AddView(text6s); linearLayout.AddView(text2s); linearLayout.AddView(text11); linearLayout.AddView(autoComplete1); linearLayout.AddView(text22); linearLayout.AddView(text3s); linearLayout.AddView(text33); linearLayout.AddView(autoComplete2); linearLayout.AddView(text44); linearLayout.AddView(text4s); linearLayout.AddView(text55); linearLayout.AddView(spinners); linearLayout.AddView(text66); linearLayout.AddView(text88); linearLayout.AddView(buttons); linearLayout.Touch+= (object sender, View.TouchEventArgs e) => { //if(autoComplete1.IsFocused || autoComplete2.IsFocused ){ Rect outRect = new Rect(); autoComplete1.GetGlobalVisibleRect(outRect); autoComplete2.GetGlobalVisibleRect(outRect); if (!outRect.Contains((int)e.Event.RawX, (int)e.Event.RawY)) { autoComplete1.ClearFocus(); autoComplete2.ClearFocus(); } hideSoftKeyboard((Activity)con); //} }; return linearLayout; }
public override bool DispatchTouchEvent(MotionEvent event1) { if (event1.Action == MotionEventActions.Down) { View v = this.CurrentFocus; if ( v is EditText) { Rect outRect = new Rect(); v.GetGlobalVisibleRect(outRect); if (!outRect.Contains((int)event1.GetX(), (int)event1.GetY())) { v.ClearFocus(); InputMethodManager imm = (InputMethodManager) GetSystemService(Context.InputMethodService); imm.HideSoftInputFromWindow(v.WindowToken, 0); } } } return base.DispatchTouchEvent( event1 ); }
private int GetSelectedBarIndex ( int x, int y) { var result = -1; var index = 0; foreach (var item in rows) { var area = new Rect (); item.BarView.GetHitRect (area); area.Top -= rowMargin; area.Bottom += rowMargin; area.Right = Right; if ( area.Contains ( x, y)) { result = index; } index++; } return result; }
//Java.Lang.Object.Locale localinfo; public override View GetSampleContent (Context con) { Context localcontext = con; int width = con.Resources.DisplayMetrics.WidthPixels -40; FrameLayout frameLayout = new FrameLayout(con); FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent, GravityFlags.FillVertical); frameLayout.LayoutParameters = layoutParams; LinearLayout layout=new LinearLayout(con); layout.LayoutParameters=new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent); layout.SetGravity(GravityFlags.FillVertical); layout.Orientation=Orientation.Vertical; TextView dummy0 = new TextView(con); dummy0.Text="Simple Interest Calculator"; dummy0.Gravity=GravityFlags.Center; dummy0.TextSize=24; layout.AddView(dummy0); TextView dummy7 = new TextView(con); layout.AddView(dummy7); TextView dummy = new TextView(con); dummy.Text="The formula for finding simple interest is:"; dummy.TextSize=18; layout.AddView(dummy); layout.FocusableInTouchMode=true; SpannableStringBuilder builder = new SpannableStringBuilder(); TextView dummy1 = new TextView(con); String str= "Interest"; SpannableString strSpannable= new SpannableString(str); strSpannable.SetSpan(new ForegroundColorSpan(Color.ParseColor("#66BB6A")), 0, str.Length, 0); builder.Append(strSpannable); builder.Append(" = Principal * Rate * Time"); dummy1.SetText(builder, TextView.BufferType.Spannable); dummy1.TextSize=18; layout.AddView(dummy1); TextView dummy8 = new TextView(con); layout.AddView(dummy8); /* Principal amount Stack */ LinearLayout principalStack = new LinearLayout(con); TextView txtPricipal = new TextView(con); txtPricipal.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100); txtPricipal.Text="Principal"; principalamount =new SfNumericTextBox(con); principalamount.FormatString="C"; principalamount.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100); principalamount.Value=1000; principalamount.AllowNull = true; principalamount.Watermark = "Principal Amount"; principalamount.MaximumNumberDecimalDigits=2; var culture = new Java.Util.Locale("en","US"); principalamount.CultureInfo = culture; principalamount.ValueChangeMode=ValueChangeMode.OnKeyFocus; principalStack.Orientation = Orientation.Horizontal; principalStack.AddView(txtPricipal); principalStack.AddView(principalamount); layout.AddView(principalStack); TextView dummy3 = new TextView(con); layout.AddView(dummy3); /* Interest Input Box */ LinearLayout InterestcalStack = new LinearLayout(con); TextView txtInterest = new TextView(con); txtInterest.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100); txtInterest.Text="Interest Rate"; Interestvalue =new SfNumericTextBox(con); Interestvalue.FormatString="P"; Interestvalue.PercentDisplayMode=PercentDisplayMode.Compute; Interestvalue.MaximumNumberDecimalDigits=2; Interestvalue.ValueChangeMode=ValueChangeMode.OnKeyFocus; Interestvalue.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100); Interestvalue.Value=0.1f; Interestvalue.Watermark = "Rate of Interest"; Interestvalue.AllowNull = true; Interestvalue.CultureInfo = culture; InterestcalStack.Orientation=Orientation.Horizontal; InterestcalStack.AddView(txtInterest); InterestcalStack.AddView(Interestvalue); layout.AddView(InterestcalStack); TextView dummy2 = new TextView(con); layout.AddView(dummy2); /* Period Input TextBox */ LinearLayout periodStack = new LinearLayout(con); TextView period = new TextView(con); period.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100); period.Text="Term"; periodValue =new SfNumericTextBox(con); periodValue.FormatString=" years"; periodValue.MaximumNumberDecimalDigits=0; periodValue.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100); periodValue.Value=20; periodValue.Watermark = "Period (in years)"; periodValue.ValueChangeMode=ValueChangeMode.OnKeyFocus; periodValue.CultureInfo = culture; periodValue.AllowNull = true; periodStack.Orientation=Orientation.Horizontal; periodStack.AddView(period); periodStack.AddView(periodValue); layout.AddView(periodStack); /* OutPut values */ LinearLayout outputStack = new LinearLayout(con); TextView outputtxt = new TextView(con); outputtxt.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100); outputtxt.Text="Interest"; outputtxt.SetTextColor(Color.ParseColor("#66BB6A")); OutputNumbertxtBox =new SfNumericTextBox(con); OutputNumbertxtBox.FormatString="c"; OutputNumbertxtBox.MaximumNumberDecimalDigits=0; OutputNumbertxtBox.AllowNull=true; OutputNumbertxtBox.CultureInfo = culture; OutputNumbertxtBox.Watermark="Enter Values"; OutputNumbertxtBox.Clickable=false; OutputNumbertxtBox.Value = (float)(1000 * 0.1 * 20); OutputNumbertxtBox.Enabled=false; OutputNumbertxtBox.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100); OutputNumbertxtBox.ValueChangeMode=ValueChangeMode.OnLostFocus; outputStack.Orientation=Orientation.Horizontal; outputStack.AddView(outputtxt); outputStack.AddView(OutputNumbertxtBox); layout.AddView(outputStack); TextView dummy4 = new TextView(con); layout.SetPadding(20, 20, 10, 20); layout.AddView(dummy4); principalamount.ValueChanged+= (object sender, SfNumericTextBox.ValueChangedEventArgs e) => { if(!e.P1.ToString().Equals("")&&!periodValue.Value.ToString().Equals("")&&!Interestvalue.Value.ToString().Equals("")) OutputNumbertxtBox.Value=e.P1 * periodValue.Value * Interestvalue.Value; }; periodValue.ValueChanged+= (object sender, SfNumericTextBox.ValueChangedEventArgs e) => { if(!e.P1.ToString().Equals("")&&!principalamount.Value.ToString().Equals("")&&!Interestvalue.Value.ToString().Equals("")) OutputNumbertxtBox.Value=e.P1* principalamount.Value*Interestvalue.Value; }; Interestvalue.ValueChanged+= (object sender, SfNumericTextBox.ValueChangedEventArgs e) => { if(!e.P1.ToString().Equals("")&&!principalamount.Value.ToString().Equals("")&&!periodValue.Value.ToString().Equals("")) OutputNumbertxtBox.Value=e.P1 * principalamount.Value * periodValue.Value; }; layout.Touch+= (object sender, View.TouchEventArgs e) => { if(OutputNumbertxtBox.IsFocused || Interestvalue.IsFocused ||periodValue.IsFocused || principalamount.IsFocused){ Rect outRect = new Rect(); OutputNumbertxtBox.GetGlobalVisibleRect(outRect); Interestvalue.GetGlobalVisibleRect(outRect); periodValue.GetGlobalVisibleRect(outRect); principalamount.GetGlobalVisibleRect(outRect); if (!outRect.Contains((int)e.Event.RawX, (int)e.Event.RawY)) { if(!OutputNumbertxtBox.Value.ToString().Equals("")) OutputNumbertxtBox.ClearFocus(); if(!Interestvalue.Value.ToString().Equals("")) Interestvalue.ClearFocus(); if(!periodValue.Value.ToString().Equals("")) periodValue.ClearFocus(); if(!principalamount.Value.ToString().Equals("")) principalamount.ClearFocus(); } hideSoftKeyboard((Activity)localcontext); } }; frameLayout.AddView(layout); ScrollView scrollView = new ScrollView(con); scrollView.AddView(frameLayout); return scrollView; }
/** * Duplicate touch events to child views. * We want to dispatch a down motion event and the move events to * child views, but calling dispatchTouchEvent() causes StackOverflowError. * Therefore we do it manually. * * @param ev motion event to be passed to children * @param pendingEvents pending events like ACTION_DOWN. This will be passed to the children before ev */ private void DuplicateTouchEventForChildren(MotionEvent ev, params MotionEvent[] pendingEvents) { if (ev == null) { return; } for (int i = ChildCount - 1; 0 <= i; i--) { View childView = GetChildAt(i); if (childView != null) { Rect childRect = new Rect(); childView.GetHitRect(childRect); MotionEvent event2 = MotionEvent.ObtainNoHistory(ev); if (!childRect.Contains((int)event2.GetX(), (int)event2.GetY())) { continue; } float offsetX = -childView.Left; float offsetY = -childView.Top; bool consumed = false; if (pendingEvents != null) { foreach (MotionEvent pe in pendingEvents) { if (pe != null) { MotionEvent peAdjusted = MotionEvent.ObtainNoHistory(pe); peAdjusted.OffsetLocation(offsetX, offsetY); consumed |= childView.DispatchTouchEvent(peAdjusted); } } } event2.OffsetLocation(offsetX, offsetY); consumed |= childView.DispatchTouchEvent(event2); if (consumed) { break; } } } }
public override bool OnTouchEvent(MotionEvent e) { CreateVelocityTracker(e); int curScrollX = this.ScrollX; // 检查触摸点是否在滑动布局(内容content)中,如果不是则返回false,即本View不处理该事件 if (mContent != null && isTouchFinished) { Rect rect = new Rect(); mContent.GetHitRect(rect); if (!rect.Contains((int)e.GetX() + curScrollX, (int)e.GetY())) { return false; } } float x = e.GetX(); //取得本次event的X坐标 switch (e.Action) { case MotionEventActions.Down: mDownX = x; mLastX = x; isTouchFinished = false; // Log.v(TAG, "(Down)mDownX: " + x); // Log.v(TAG, "(Down)mLastX: " + x); break; case MotionEventActions.Move: // Log.v(TAG, "(Move)mLastX: " + x); int deltaX = (int)(mLastX - x); if ((curScrollX + deltaX) < -mMaxScrollX) { deltaX = -mMaxScrollX - curScrollX; } if ((curScrollX + deltaX) > 0) { deltaX = -curScrollX; } if (deltaX != 0) { ScrollBy(deltaX, 0); } mLastX = x; // Log.v(TAG, "(Move)x: " + x); break; case MotionEventActions.Up: // Log.v(TAG, "(Up)x: " + x); // Log.v(TAG, "(Up)mDownX: " + mDownX); // Log.v(TAG, "(Up)curScrollX: " + curScrollX); int velocityX = GetScrollVelocity(); int offsetX = (int)(x - mDownX); //成立表明移动距离已经达到被判断为滑动的最低标准 //不成立表明不被判断为滑动,则认为是单一的点击,则关闭menu if (Math.Abs(offsetX) >= mTouchSlop) { //成立表明手指移动速度达标,则进行自动滑动; //不成立表明速度不达标,但仍然需要判断当前SlideLayout的位置 //如果已经超过一半,则继续自动完成剩下的滑动,如果没有超过一半,则反向滑动 if (Math.Abs(velocityX) >= SNAP_VELOCITY) { if (velocityX > 0) { OpenMenu(); } else if (velocityX < 0) { CloseMenu(); } } else { if (curScrollX >= -mMaxScrollX / 2) { CloseMenu(); } else { OpenMenu(); } } } else { CloseMenu(); } RecycleVelocityTracker(); isTouchFinished = true; break; } return true; }
/** * If the motion event was relative to the view * which in ignored view list,return true; * * @param ev * @return */ private bool isInIgnoredView(MotionEvent ev) { Rect rect = new Rect(); foreach (View v in ignoredViews) { v.GetGlobalVisibleRect(rect); if (rect.Contains((int)ev.GetX(), (int)ev.GetY())) return true; } return false; }
/** * Returns the child {@link android.view.View} that was touched, by performing a hit test. * * @param motionEvent the {@link android.view.MotionEvent} to find the {@code View} for. * * @return the touched {@code View}, or {@code null} if none found. */ //@Nullable private View findDownView(MotionEvent motionEvent) { Rect rect = new Rect(); int childCount = mListViewWrapper.getChildCount(); int x = (int)motionEvent.GetX(); int y = (int)motionEvent.GetY(); View downView = null; for (int i = 0; i < childCount && downView == null; i++) { View child = mListViewWrapper.getChildAt(i); if (child != null) { child.GetHitRect(rect); if (rect.Contains(x, y)) { downView = child; } } } return downView; }
static bool IsWithinCircularBounds(Rect hit, Rect bounds) { if (!bounds.Contains(hit)) return false; // Forumula for a circle: (x-a)2 + (y-b)2 = r2 var centerX = bounds.ExactCenterX() - bounds.Left; var centerY = bounds.ExactCenterY() - bounds.Top; var radius = centerX; double x = hit.Left - bounds.Left, y = hit.Top - bounds.Top, r2 = radius * radius, xx = (x - centerX); var yy = Math.Sqrt(r2 - xx*xx) + 0.5; var upperBound = centerY - yy; var lowerBound = centerY + yy; var result = !Double.IsNaN (y) && y > upperBound && y < lowerBound; return result; }