473,786 Members | 2,350 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

check point inside "cirkle" (basketball)

Hi group,

I've got this bit of code (see below) which draws a basketball field in a
picturebox (width:198, height:368)
but now I was wondering what would be the easiest way to check inside the
picturebox mouseup event if I clicked inside or outside the 3point area,
because the 3point area isn't a real cirkle

Any hints or tips are welcome.

Thanks in advance and greetz Peter
Dim myNewBmp As Bitmap
Dim g As Graphics

myNewBmp = New Bitmap(197, 366)
g = Graphics.FromIm age(myNewBmp)
g.Clear(Color.W hite)
'boundry
g.DrawRectangle (Pens.Black, 0, 0, 196, 365)

'division line
g.DrawLine(Pens .Black, 0, 183, 196, 183)

'tipoff cirkel
g.DrawEllipse(P ens.Black, 74, 159, 48, 48)

'basket below
g.DrawLine(Pens .Black, 86, 344, 110, 344)
g.DrawEllipse(P ens.Black, 93, 334, 10, 10)

'basket top
g.DrawLine(Pens .Black, 86, 21, 110, 21)
g.DrawEllipse(P ens.Black, 93, 21, 10, 10)

'bucket below
g.DrawLine(Pens .Black, 74, 289, 122, 289)
g.DrawEllipse(P ens.Black, 74, 265, 48, 48)
g.DrawLine(Pens .Black, 74, 289, 35, 365)
g.DrawLine(Pens .Black, 122, 289, 161, 365)

'bucket top
g.DrawLine(Pens .Black, 74, 76, 122, 76)
g.DrawEllipse(P ens.Black, 74, 52, 48, 48)
g.DrawLine(Pens .Black, 74, 76, 35, 0)
g.DrawLine(Pens .Black, 122, 76, 161, 0)

'3point line
'g.DrawArc(Pens .Black, 17, 365, 179, 102, 180, 180)
g.DrawEllipse(P ens.Black, 17, 263, 162, 200)

'3point line
'g.DrawArc(Pens .Black, 17, 365, 179, 102, 180, 180)
g.DrawEllipse(P ens.Black, 17, -98, 162, 200)
g.Dispose()
PictureBox1.Ima ge = myNewBmp

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)
Feb 15 '06 #1
3 1663

Peter Proost wrote:
Hi group,

I've got this bit of code (see below) which draws a basketball field in a
picturebox (width:198, height:368)
but now I was wondering what would be the easiest way to check inside the
picturebox mouseup event if I clicked inside or outside the 3point area,
because the 3point area isn't a real cirkle


Define a GraphicsPath that is made up of the border of the 3point area.
Define a Region based on this GraphicsPath. Vary as necessary the
following sample to see if a point is within the Region:

(code from MSDN, topic titled "Hit Testing with a Region")
The purpose of hit testing is to determine whether the cursor is over a
given object, such as an icon or a button. The following example
creates a plus-shaped region by forming the union of two rectangular
regions. Assume that the variable point holds the location of the most
recent click. The code checks to see whether point is in the
plus-shaped region. If the point is in the region (a hit), the region
is filled with an opaque red brush. Otherwise, the region is filled
with a semitransparent red brush.

[Visual Basic]
Dim point As New Point(60, 10)

' Assume that the variable "point" contains the location of the
' most recent mouse click.
' To simulate a hit, assign (60, 10) to point.
' To simulate a miss, assign (0, 0) to point.

Dim solidBrush As New SolidBrush(Colo r.Black)
Dim region1 As New [Region](New Rectangle(50, 0, 50, 150))
Dim region2 As New [Region](New Rectangle(0, 50, 150, 50))

' Create a plus-shaped region by forming the union of region1 and
region2.
' The union replaces region1.
region1.Union(r egion2)

If region1.IsVisib le(point, e.Graphics) Then
' The point is in the region. Use an opaque brush.
solidBrush.Colo r = Color.FromArgb( 255, 255, 0, 0)
Else
' The point is not in the region. Use a semitransparent brush.
solidBrush.Colo r = Color.FromArgb( 64, 255, 0, 0)
End If

e.Graphics.Fill Region(solidBru sh, region1)


--
Larry Lard
Replies to group please

Feb 15 '06 #2
Thanks for the reply Larry I'll check it out

Thanks again

Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"Larry Lard" <la*******@hotm ail.com> schreef in bericht
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .

Peter Proost wrote:
Hi group,

I've got this bit of code (see below) which draws a basketball field in a
picturebox (width:198, height:368)
but now I was wondering what would be the easiest way to check inside the picturebox mouseup event if I clicked inside or outside the 3point area,
because the 3point area isn't a real cirkle


Define a GraphicsPath that is made up of the border of the 3point area.
Define a Region based on this GraphicsPath. Vary as necessary the
following sample to see if a point is within the Region:

(code from MSDN, topic titled "Hit Testing with a Region")
The purpose of hit testing is to determine whether the cursor is over a
given object, such as an icon or a button. The following example
creates a plus-shaped region by forming the union of two rectangular
regions. Assume that the variable point holds the location of the most
recent click. The code checks to see whether point is in the
plus-shaped region. If the point is in the region (a hit), the region
is filled with an opaque red brush. Otherwise, the region is filled
with a semitransparent red brush.

[Visual Basic]
Dim point As New Point(60, 10)

' Assume that the variable "point" contains the location of the
' most recent mouse click.
' To simulate a hit, assign (60, 10) to point.
' To simulate a miss, assign (0, 0) to point.

Dim solidBrush As New SolidBrush(Colo r.Black)
Dim region1 As New [Region](New Rectangle(50, 0, 50, 150))
Dim region2 As New [Region](New Rectangle(0, 50, 150, 50))

' Create a plus-shaped region by forming the union of region1 and
region2.
' The union replaces region1.
region1.Union(r egion2)

If region1.IsVisib le(point, e.Graphics) Then
' The point is in the region. Use an opaque brush.
solidBrush.Colo r = Color.FromArgb( 255, 255, 0, 0)
Else
' The point is not in the region. Use a semitransparent brush.
solidBrush.Colo r = Color.FromArgb( 64, 255, 0, 0)
End If

e.Graphics.Fill Region(solidBru sh, region1)


--
Larry Lard
Replies to group please

Feb 15 '06 #3
Hi again, this is how I implemented Larry's tip, and it works ok for me

Thanks again to Larry

At the top:

Private DriePuntPathB As GraphicsPath
Private driePuntRegB As Region
Private DriePuntPathO As GraphicsPath
Private driePuntRegO As Region
Dim myNewBmp As Bitmap
Dim g As Graphics

myNewBmp = New Bitmap(197, 366) '196,365 zijn de echte maten
g = Graphics.FromIm age(myNewBmp)
g.Clear(Color.W hite)
'boundry
g.DrawRectangle (Pens.Black, 0, 0, 196, 365)

'division line
g.DrawLine(Pens .Black, 0, 183, 196, 183)

'tipoff cirkel
g.DrawEllipse(P ens.Black, 74, 159, 48, 48)

'basket below
g.DrawLine(Pens .Black, 86, 344, 110, 344)
g.DrawEllipse(P ens.Black, 93, 334, 10, 10)

'basket top
g.DrawLine(Pens .Black, 86, 21, 110, 21)
g.DrawEllipse(P ens.Black, 93, 21, 10, 10)

'bucket below
g.DrawLine(Pens .Black, 74, 289, 122, 289)
g.DrawEllipse(P ens.Black, 74, 265, 48, 48)
g.DrawLine(Pens .Black, 74, 289, 35, 365)
g.DrawLine(Pens .Black, 122, 289, 161, 365)

'bucket top
g.DrawLine(Pens .Black, 74, 76, 122, 76)
g.DrawEllipse(P ens.Black, 74, 52, 48, 48)
g.DrawLine(Pens .Black, 74, 76, 35, 0)
g.DrawLine(Pens .Black, 122, 76, 161, 0)

'3point line bottom
'g.DrawArc(Pens .Black, 17, 365, 179, 102, 180, 180)

DriePuntPathO = New GraphicsPath
DriePuntPathO.A ddEllipse(17, 263, 162, 200)
driePuntRegO = New Region(DriePunt PathO)
g.DrawEllipse(P ens.Black, 17, 263, 162, 200)

'3point line top
'g.DrawArc(Pens .Black, 17, 365, 179, 102, 180, 180)
g.DrawEllipse(P ens.Black, 17, -98, 162, 200)
DriePuntPathB = New GraphicsPath
DriePuntPathB.A ddEllipse(17, -98, 162, 200)
driePuntRegB = New Region(DriePunt PathB)
g.Dispose()
PictureBox1.Ima ge = myNewBmp

Private Sub PictureBox1_Mou seUp(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles PictureBox1.Mou seUp
If e.Button = MouseButtons.Le ft Then
If driePuntRegB.Is Visible(e.X, e.Y) Then
MsgBox("two")
Else
If driePuntRegO.Is Visible(e.X, e.Y) Then
MsgBox("two")
Else
MsgBox("three")
End If
End If
End If
End Sub

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"Peter Proost" <pp*****@nospam .hotmail.com> schreef in bericht
news:#0******** ******@TK2MSFTN GP11.phx.gbl...
Thanks for the reply Larry I'll check it out

Thanks again

Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"Larry Lard" <la*******@hotm ail.com> schreef in bericht
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .

Peter Proost wrote:
Hi group,

I've got this bit of code (see below) which draws a basketball field in
a
picturebox (width:198, height:368)
but now I was wondering what would be the easiest way to check inside the picturebox mouseup event if I clicked inside or outside the 3point

area, because the 3point area isn't a real cirkle


Define a GraphicsPath that is made up of the border of the 3point area.
Define a Region based on this GraphicsPath. Vary as necessary the
following sample to see if a point is within the Region:

(code from MSDN, topic titled "Hit Testing with a Region")
>

The purpose of hit testing is to determine whether the cursor is over a
given object, such as an icon or a button. The following example
creates a plus-shaped region by forming the union of two rectangular
regions. Assume that the variable point holds the location of the most
recent click. The code checks to see whether point is in the
plus-shaped region. If the point is in the region (a hit), the region
is filled with an opaque red brush. Otherwise, the region is filled
with a semitransparent red brush.

[Visual Basic]
Dim point As New Point(60, 10)

' Assume that the variable "point" contains the location of the
' most recent mouse click.
' To simulate a hit, assign (60, 10) to point.
' To simulate a miss, assign (0, 0) to point.

Dim solidBrush As New SolidBrush(Colo r.Black)
Dim region1 As New [Region](New Rectangle(50, 0, 50, 150))
Dim region2 As New [Region](New Rectangle(0, 50, 150, 50))

' Create a plus-shaped region by forming the union of region1 and
region2.
' The union replaces region1.
region1.Union(r egion2)

If region1.IsVisib le(point, e.Graphics) Then
' The point is in the region. Use an opaque brush.
solidBrush.Colo r = Color.FromArgb( 255, 255, 0, 0)
Else
' The point is not in the region. Use a semitransparent brush.
solidBrush.Colo r = Color.FromArgb( 64, 255, 0, 0)
End If

e.Graphics.Fill Region(solidBru sh, region1)
>


--
Larry Lard
Replies to group please


Feb 15 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
12617
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second method was a piece of C code which turned out to be incorrect and incomplete but by modifieing it would still be usuable. The first method was this piece of text:
4
4589
by: Brian Basquille | last post by:
Hello all, Quick question! How would i keep a point inside a region? For example, the mouse pointer. You should be able to move the mouse around in this region but not anywhere outside it. How would i go about doing this?
1
1072
by: Jensen bredal | last post by:
Hello, I have the task of showing PP slides in my aspx page. I'm not quiet sure how to deal with this when it comes to viewing the slides on my page. Assuming, i have uploaded the slides in my database. How can i view it. Is it possible to control how long it should be viewed ? Any comments or sample code will be highly appreciated.
1
1619
by: questionit | last post by:
How to create and display check-boxes as values in a Combo-Box ? Thanks
3
9811
by: illusion.admins | last post by:
I am trying to code something to tell me if a selected point is in a particular ellipse. For the ellipse I know how it was constructed (know the x,y, and width, height). But if I just check to see if the point is in the rectangle making up the ellipse wouldn't that possibly give me a false answer? Eg if the point is the upper left coordinate of the rectangle...this point is in the rectangle making up ellipse but NOT the ellipse itself. ...
0
1392
by: =?Utf-8?B?YmJn?= | last post by:
Hi all, here might not be best place to ask this but, Does anyone know how to rollback to particular check point not back to start of transaction? We are handling a socket connection as a single transaction and during a socket communication, many packets can be received and contents of them will be written to database many times. At the start of socket communication, oracle database connection is opened and at the end, all writes to...
0
2395
by: Venky K Shankar | last post by:
On Sunday 20 July 2008 12:08:49 am Lamonte Harris wrote: you can execute OS system call. here i execute ps -ef and grep the required process name (or you can grep by pid on that particular column using awk) import os os.system("ps -ef | grep -v grep | grep <proc_name>")
14
3695
ddtpmyra
by: ddtpmyra | last post by:
Hi below is my script displaying all the information inside the table. Pupose: pupose of this php page is to display all the information on my table and have a check box at the last column that will allow the user to approved the member. Problem: I don't how to insert a checkbox on a loop condition. <?php
2
4340
by: vikvikash | last post by:
how to check if a point is inside a polygon or not using sql server 2008 in .net???
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9492
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10360
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9960
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.