|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
check point inside "cirkle" (basketball)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.FromImage(myNewBmp) g.Clear(Color.White) 'boundry g.DrawRectangle(Pens.Black, 0, 0, 196, 365) 'division line g.DrawLine(Pens.Black, 0, 183, 196, 183) 'tipoff cirkel g.DrawEllipse(Pens.Black, 74, 159, 48, 48) 'basket below g.DrawLine(Pens.Black, 86, 344, 110, 344) g.DrawEllipse(Pens.Black, 93, 334, 10, 10) 'basket top g.DrawLine(Pens.Black, 86, 21, 110, 21) g.DrawEllipse(Pens.Black, 93, 21, 10, 10) 'bucket below g.DrawLine(Pens.Black, 74, 289, 122, 289) g.DrawEllipse(Pens.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(Pens.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(Pens.Black, 17, 263, 162, 200) '3point line 'g.DrawArc(Pens.Black, 17, 365, 179, 102, 180, 180) g.DrawEllipse(Pens.Black, 17, -98, 162, 200) g.Dispose() PictureBox1.Image = 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) Peter Proost wrote:
> Hi group, Define a GraphicsPath that is made up of the border of the 3point area.> > 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 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 agiven 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(Color.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(region2) If region1.IsVisible(point, e.Graphics) Then ' The point is in the region. Use an opaque brush. solidBrush.Color = Color.FromArgb(255, 255, 0, 0) Else ' The point is not in the region. Use a semitransparent brush. solidBrush.Color = Color.FromArgb(64, 255, 0, 0) End If e.Graphics.FillRegion(solidBrush, region1) >> -- Larry Lard Replies to group please Thanks for the reply Larry I'll check it out
Thanks again Greetz Peter -- Show quoteHide quoteProgramming 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" <larryl***@hotmail.com> schreef in bericht news:1140016529.404839.259750@o13g2000cwo.googlegroups.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(Color.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(region2) > > If region1.IsVisible(point, e.Graphics) Then > ' The point is in the region. Use an opaque brush. > solidBrush.Color = Color.FromArgb(255, 255, 0, 0) > Else > ' The point is not in the region. Use a semitransparent brush. > solidBrush.Color = Color.FromArgb(64, 255, 0, 0) > End If > > e.Graphics.FillRegion(solidBrush, region1) > >> > > -- > Larry Lard > Replies to group please > 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.FromImage(myNewBmp) g.Clear(Color.White) 'boundry g.DrawRectangle(Pens.Black, 0, 0, 196, 365) 'division line g.DrawLine(Pens.Black, 0, 183, 196, 183) 'tipoff cirkel g.DrawEllipse(Pens.Black, 74, 159, 48, 48) 'basket below g.DrawLine(Pens.Black, 86, 344, 110, 344) g.DrawEllipse(Pens.Black, 93, 334, 10, 10) 'basket top g.DrawLine(Pens.Black, 86, 21, 110, 21) g.DrawEllipse(Pens.Black, 93, 21, 10, 10) 'bucket below g.DrawLine(Pens.Black, 74, 289, 122, 289) g.DrawEllipse(Pens.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(Pens.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.AddEllipse(17, 263, 162, 200) driePuntRegO = New Region(DriePuntPathO) g.DrawEllipse(Pens.Black, 17, 263, 162, 200) '3point line top 'g.DrawArc(Pens.Black, 17, 365, 179, 102, 180, 180) g.DrawEllipse(Pens.Black, 17, -98, 162, 200) DriePuntPathB = New GraphicsPath DriePuntPathB.AddEllipse(17, -98, 162, 200) driePuntRegB = New Region(DriePuntPathB) g.Dispose() PictureBox1.Image = myNewBmp Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp If e.Button = MouseButtons.Left Then If driePuntRegB.IsVisible(e.X, e.Y) Then MsgBox("two") Else If driePuntRegO.IsVisible(e.X, e.Y) Then MsgBox("two") Else MsgBox("three") End If End If End If End Sub -- Show quoteHide quoteProgramming 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" <pproost@nospam.hotmail.com> schreef in bericht news:#0#swZkMGHA.1832@TK2MSFTNGP11.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" <larryl***@hotmail.com> schreef in bericht > news:1140016529.404839.259750@o13g2000cwo.googlegroups.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(Color.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(region2) > > > > If region1.IsVisible(point, e.Graphics) Then > > ' The point is in the region. Use an opaque brush. > > solidBrush.Color = Color.FromArgb(255, 255, 0, 0) > > Else > > ' The point is not in the region. Use a semitransparent brush. > > solidBrush.Color = Color.FromArgb(64, 255, 0, 0) > > End If > > > > e.Graphics.FillRegion(solidBrush, region1) > > >> > > > > -- > > Larry Lard > > Replies to group please > > > >
Exposing properties of a class within a class
Unresponsive UI during lengthy operation ? extending BackgroundWorker ProgressChangedEventArgs Invoking a PictureBox click ? MethodInfo or MethodBase? ThreadPool.QueueUserWorkItem console.write listview checkbox column - toggle image Noob Question - Best Control for a TV Guide? Registering 2005 dll for COM |
|||||||||||||||||||||||