How difficult can it be to draw a circle and a couple of lines in VS 2005
VB.net???????

It was so much easier when I could just select a tool and draw them at
design time!

This has got me really frustrated, and feeling pretty stupid. All I want to
do is to display a circle on a pocket PC screen (WM5) have it intersected
with a horizontal and vertical line so that it looks like the cross hairs on
a gun sight. I then want a smaller crosshair in the middle that can be
moved around by means of four buttons, one each for up, down, left and
right. Each time a button is clicked I want the small crosshair to move
.01mm in the corrosponding direction. The large crosshair will always
remain stationary, thus referencing the centre of the circle

I'm a real novice programmer and this is driving me mad. My simple programs
have never really needed any sort of graphics before. It used to be so
easy.

Can anyone help me out please.

Many thanks

Jem

Re: Aaaaarghhh!!! Drawing a circle? by Jem

Jem
Thu Jan 11 14:06:12 CST 2007

Quick edit to my original posting...

"Jem" <xxxxxxxxxx> wrote in message
news:kvudnWQfK-x2CjvYnZ2dnUVZ8surnZ2d@pipex.net...
> How difficult can it be to draw a circle and a couple of lines in VS 2005
> VB.net???????
>
> It was so much easier when I could just select a tool and draw them at
> design time!
>
> This has got me really frustrated, and feeling pretty stupid. All I want
> to do is to display a circle on a pocket PC screen (WM5) have it
> intersected with a horizontal and vertical line so that it looks like the
> cross hairs on a gun sight. I then want a smaller crosshair in the middle
> that can be moved around by means of four buttons, one each for up, down,
> left and right. Each time a button is clicked I want the small crosshair
> to move .01mm in the corrosponding direction. The large crosshair will
> always

Oop's - clarification required!
When I say .01mm, it doesn't have to be that exact measurement to scale on
the screen. That is a value that I will pass to the rest of the program for
calculation purposes.

> remain stationary, thus referencing the centre of the circle
>
> I'm a real novice programmer and this is driving me mad. My simple
> programs have never really needed any sort of graphics before. It used to
> be so easy.
>
> Can anyone help me out please.
>
> Many thanks
>
> Jem
>



Re: Aaaaarghhh!!! Drawing a circle? by ctacke/>

ctacke/>
Thu Jan 11 15:15:18 CST 2007

It's quite simple - override OnPaint (and probably OnPaintBackground) and
paint the circle and lines. There are lots of web tutorials for this type
of thing.


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--




"Jem" <xxxxxxxxxx> wrote in message
news:kvudnWQfK-x2CjvYnZ2dnUVZ8surnZ2d@pipex.net...
> How difficult can it be to draw a circle and a couple of lines in VS 2005
> VB.net???????
>
> It was so much easier when I could just select a tool and draw them at
> design time!
>
> This has got me really frustrated, and feeling pretty stupid. All I want
> to do is to display a circle on a pocket PC screen (WM5) have it
> intersected with a horizontal and vertical line so that it looks like the
> cross hairs on a gun sight. I then want a smaller crosshair in the middle
> that can be moved around by means of four buttons, one each for up, down,
> left and right. Each time a button is clicked I want the small crosshair
> to move .01mm in the corrosponding direction. The large crosshair will
> always remain stationary, thus referencing the centre of the circle
>
> I'm a real novice programmer and this is driving me mad. My simple
> programs have never really needed any sort of graphics before. It used to
> be so easy.
>
> Can anyone help me out please.
>
> Many thanks
>
> Jem
>



Re: Aaaaarghhh!!! Drawing a circle? by Jem

Jem
Thu Jan 11 15:45:07 CST 2007

Ahhhh ha... It's like everything - It's quite simple when you know how to do
it. I don't even know how to override OnPaint! :-(

All the web tutorials i've tried to follow don't work for me for some reason
or other. I know i'm doing something wrong, but believe me i've spent ages
on this and am now at the point of sheer frustration.

Hellllllllllp!!!!

Ta

Jem

"<ctacke/>" <ctacke[@]opennetcf[dot]com> wrote in message
news:unKUdWcNHHA.448@TK2MSFTNGP04.phx.gbl...
> It's quite simple - override OnPaint (and probably OnPaintBackground) and
> paint the circle and lines. There are lots of web tutorials for this type
> of thing.
>
>
> --
> Chris Tacke
> OpenNETCF Consulting
> Managed Code in the Embedded World
> www.opennetcf.com
> --
>
>
>
>
> "Jem" <xxxxxxxxxx> wrote in message
> news:kvudnWQfK-x2CjvYnZ2dnUVZ8surnZ2d@pipex.net...
>> How difficult can it be to draw a circle and a couple of lines in VS 2005
>> VB.net???????
>>
>> It was so much easier when I could just select a tool and draw them at
>> design time!
>>
>> This has got me really frustrated, and feeling pretty stupid. All I want
>> to do is to display a circle on a pocket PC screen (WM5) have it
>> intersected with a horizontal and vertical line so that it looks like the
>> cross hairs on a gun sight. I then want a smaller crosshair in the
>> middle that can be moved around by means of four buttons, one each for
>> up, down, left and right. Each time a button is clicked I want the small
>> crosshair to move .01mm in the corrosponding direction. The large
>> crosshair will always remain stationary, thus referencing the centre of
>> the circle
>>
>> I'm a real novice programmer and this is driving me mad. My simple
>> programs have never really needed any sort of graphics before. It used
>> to be so easy.
>>
>> Can anyone help me out please.
>>
>> Many thanks
>>
>> Jem
>>
>
>



Re: Aaaaarghhh!!! Drawing a circle? by ctacke/>

ctacke/>
Thu Jan 11 16:04:34 CST 2007

It's like overriding any method. Understanding this is basic OOP and you
need to understand it to move forward programming.

You need to create a project, drop on a Form, the override that Form's
OnPaint. Once you do that and make sure it's calling into OnPaint, then
create a brush and draw a circle.


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--



"Jem" <xxxxxxxxxx> wrote in message
news:PMSdnQAkO7x-MjvYnZ2dnUVZ8qqlnZ2d@pipex.net...
> Ahhhh ha... It's like everything - It's quite simple when you know how to
> do it. I don't even know how to override OnPaint! :-(
>
> All the web tutorials i've tried to follow don't work for me for some
> reason or other. I know i'm doing something wrong, but believe me i've
> spent ages on this and am now at the point of sheer frustration.
>
> Hellllllllllp!!!!
>
> Ta
>
> Jem
>
> "<ctacke/>" <ctacke[@]opennetcf[dot]com> wrote in message
> news:unKUdWcNHHA.448@TK2MSFTNGP04.phx.gbl...
>> It's quite simple - override OnPaint (and probably OnPaintBackground) and
>> paint the circle and lines. There are lots of web tutorials for this
>> type of thing.
>>
>>
>> --
>> Chris Tacke
>> OpenNETCF Consulting
>> Managed Code in the Embedded World
>> www.opennetcf.com
>> --
>>
>>
>>
>>
>> "Jem" <xxxxxxxxxx> wrote in message
>> news:kvudnWQfK-x2CjvYnZ2dnUVZ8surnZ2d@pipex.net...
>>> How difficult can it be to draw a circle and a couple of lines in VS
>>> 2005 VB.net???????
>>>
>>> It was so much easier when I could just select a tool and draw them at
>>> design time!
>>>
>>> This has got me really frustrated, and feeling pretty stupid. All I
>>> want to do is to display a circle on a pocket PC screen (WM5) have it
>>> intersected with a horizontal and vertical line so that it looks like
>>> the cross hairs on a gun sight. I then want a smaller crosshair in the
>>> middle that can be moved around by means of four buttons, one each for
>>> up, down, left and right. Each time a button is clicked I want the
>>> small crosshair to move .01mm in the corrosponding direction. The large
>>> crosshair will always remain stationary, thus referencing the centre of
>>> the circle
>>>
>>> I'm a real novice programmer and this is driving me mad. My simple
>>> programs have never really needed any sort of graphics before. It used
>>> to be so easy.
>>>
>>> Can anyone help me out please.
>>>
>>> Many thanks
>>>
>>> Jem
>>>
>>
>>
>
>



Re: Aaaaarghhh!!! Drawing a circle? by Jem

Jem
Thu Jan 11 17:25:13 CST 2007

O.K., Thanks for the info, i'll give this a go tommorrow. :-)

All the programming i've ever done simply involves calculations that provide
an answer. Hence all i've ever used on a form is textboxes, buttons and
labels.

Watch this space ;-)

Jem


"<ctacke/>" <ctacke[@]opennetcf[dot]com> wrote in message
news:%239qEAycNHHA.3916@TK2MSFTNGP02.phx.gbl...
> It's like overriding any method. Understanding this is basic OOP and you
> need to understand it to move forward programming.
>
> You need to create a project, drop on a Form, the override that Form's
> OnPaint. Once you do that and make sure it's calling into OnPaint, then
> create a brush and draw a circle.
>
>
> --
> Chris Tacke
> OpenNETCF Consulting
> Managed Code in the Embedded World
> www.opennetcf.com
> --
>
>
>
> "Jem" <xxxxxxxxxx> wrote in message
> news:PMSdnQAkO7x-MjvYnZ2dnUVZ8qqlnZ2d@pipex.net...
>> Ahhhh ha... It's like everything - It's quite simple when you know how to
>> do it. I don't even know how to override OnPaint! :-(
>>
>> All the web tutorials i've tried to follow don't work for me for some
>> reason or other. I know i'm doing something wrong, but believe me i've
>> spent ages on this and am now at the point of sheer frustration.
>>
>> Hellllllllllp!!!!
>>
>> Ta
>>
>> Jem
>>
>> "<ctacke/>" <ctacke[@]opennetcf[dot]com> wrote in message
>> news:unKUdWcNHHA.448@TK2MSFTNGP04.phx.gbl...
>>> It's quite simple - override OnPaint (and probably OnPaintBackground)
>>> and paint the circle and lines. There are lots of web tutorials for
>>> this type of thing.
>>>
>>>
>>> --
>>> Chris Tacke
>>> OpenNETCF Consulting
>>> Managed Code in the Embedded World
>>> www.opennetcf.com
>>> --
>>>
>>>
>>>
>>>
>>> "Jem" <xxxxxxxxxx> wrote in message
>>> news:kvudnWQfK-x2CjvYnZ2dnUVZ8surnZ2d@pipex.net...
>>>> How difficult can it be to draw a circle and a couple of lines in VS
>>>> 2005 VB.net???????
>>>>
>>>> It was so much easier when I could just select a tool and draw them at
>>>> design time!
>>>>
>>>> This has got me really frustrated, and feeling pretty stupid. All I
>>>> want to do is to display a circle on a pocket PC screen (WM5) have it
>>>> intersected with a horizontal and vertical line so that it looks like
>>>> the cross hairs on a gun sight. I then want a smaller crosshair in the
>>>> middle that can be moved around by means of four buttons, one each for
>>>> up, down, left and right. Each time a button is clicked I want the
>>>> small crosshair to move .01mm in the corrosponding direction. The
>>>> large crosshair will always remain stationary, thus referencing the
>>>> centre of the circle
>>>>
>>>> I'm a real novice programmer and this is driving me mad. My simple
>>>> programs have never really needed any sort of graphics before. It used
>>>> to be so easy.
>>>>
>>>> Can anyone help me out please.
>>>>
>>>> Many thanks
>>>>
>>>> Jem
>>>>
>>>
>>>
>>
>>
>
>



Re: Aaaaarghhh!!! Drawing a circle? by Jem

Jem
Sat Jan 13 11:42:15 CST 2007

O.K., So now I have the code shown below ...

It's taken me literally hours to work this out. However It's here and it
works :-)

The only problem is that I would like to have the initial graphic
automatically displayed once the form is loaded rather than having to
'click' the button 'btnCtr' in order to display it.

I know the problem is this line... myGraphics =
Graphics.FromHwnd(ActiveForm().Handle) ... as this throws up errors if I put
it anywhere other than in the button's click event. What can I use so that
it works in the forms load event (or similar). I pinched this line of code
from Sam's Mastering the Visual Basic Language site. I don't really
understand how it works, or why it works in the button but not the form
load. Any help, advice or suggestions would be greatly appreciated.

Just by way of explanation, I have four buttons on a form (up, down, left,
right) that move the CrossHair around inside a circle. The button below
simply brings the CrossHair back to the centre of the circle.

Thanks

Jem
Private Sub btnCtr_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCtr.Click

Dim VertCrossHairX1 As Integer = 75

Dim VertCrossHairX2 As Integer = 75

Dim VertCrossHairY1 As Integer = 70

Dim VertCrossHairY2 As Integer = 80

Dim HorCrossHairY1 As Integer = 75

Dim HorCrossHairY2 As Integer = 75

Dim HorCrossHairX1 As Integer = 70

Dim HorCrossHairX2 As Integer = 80

' Return the current form as a drawing surface

myGraphics = Graphics.FromHwnd(ActiveForm().Handle)

' Clear all the graphics ready for redraw

myGraphics.Clear(Color.Aquamarine)

' Create a new pen object using the color structure

myPen = New Pen(Color:=Color.Blue, Width:=1)

' Set the pen colour for the Main Circle

myPen.Color = Color.Blue

'draw an ellipse inside a bounding rectangle with a Pen instance

myGraphics.DrawEllipse(pen:=myPen, rect:=New Rectangle(x:=25, y:=25,
Width:=100, Height:=100))

' Set the pen colour for the Main lines

myPen.Color = Color.Black

'draw the vertical line on the form using the pen object

myGraphics.DrawLine(pen:=myPen, x1:=75, y1:=25, x2:=75, y2:=125)

'draw the horizontal line on the form using the pen object

myGraphics.DrawLine(pen:=myPen, x1:=25, y1:=75, x2:=125, y2:=75)

' Set the pen colour for the CrossHair

myPen.Color = Color.Red

' Draw the vertical CrossHair line on the form using the pen object

myGraphics.DrawLine(pen:=myPen, x1:=VertCrossHairX1, y1:=VertCrossHairY1,
x2:=VertCrossHairX2, y2:=VertCrossHairY2)

' Draw the horizontal CrossHair line on the form using the pen object

myGraphics.DrawLine(pen:=myPen, x1:=HorCrossHairX1, y1:=HorCrossHairY1,
x2:=HorCrossHairX2, y2:=HorCrossHairY2)

End Sub

"Jem" <xxxxxxxxxx> wrote in message
news:kvudnWQfK-x2CjvYnZ2dnUVZ8surnZ2d@pipex.net...
> How difficult can it be to draw a circle and a couple of lines in VS 2005
> VB.net???????
>
> It was so much easier when I could just select a tool and draw them at
> design time!
>
> This has got me really frustrated, and feeling pretty stupid. All I want
> to do is to display a circle on a pocket PC screen (WM5) have it
> intersected with a horizontal and vertical line so that it looks like the
> cross hairs on a gun sight. I then want a smaller crosshair in the middle
> that can be moved around by means of four buttons, one each for up, down,
> left and right. Each time a button is clicked I want the small crosshair
> to move .01mm in the corrosponding direction. The large crosshair will
> always remain stationary, thus referencing the centre of the circle
>
> I'm a real novice programmer and this is driving me mad. My simple
> programs have never really needed any sort of graphics before. It used to
> be so easy.
>
> Can anyone help me out please.
>
> Many thanks
>
> Jem
>



Re: Aaaaarghhh!!! Drawing a circle? by ctacke/>

ctacke/>
Sat Jan 13 14:54:41 CST 2007

Really - following my initial device of overriing OnPaint is where you want
to go. You get the Graphics object as an input parameter, so there's no
need to get it from a handle, and OnPaint gets automatically called whenever
the OS needs to repaint (so it will happen when the Form loads).

The resaon you get the error during load is probably becasue the handle
isn't yet valid.

While this is painful for you - it's the only way to learn, and while
grabbing the code from elsewhere mmay work, as you've already admitted, you
don't actually learn anything from it.

I'd give you the syntax off the top of my head, but I don't know the VB
syntax without using Studio to help me out. There has to be sample code out
there for doing this.

-Chris

-Chris

"Jem" <xxxxxxxxxx> wrote in message
news:B8ednWyin9llhDTYnZ2dnUVZ8tWinZ2d@pipex.net...
> O.K., So now I have the code shown below ...
>
> It's taken me literally hours to work this out. However It's here and it
> works :-)
>
> The only problem is that I would like to have the initial graphic
> automatically displayed once the form is loaded rather than having to
> 'click' the button 'btnCtr' in order to display it.
>
> I know the problem is this line... myGraphics =
> Graphics.FromHwnd(ActiveForm().Handle) ... as this throws up errors if I
> put it anywhere other than in the button's click event. What can I use so
> that it works in the forms load event (or similar). I pinched this line
> of code from Sam's Mastering the Visual Basic Language site. I don't
> really understand how it works, or why it works in the button but not the
> form load. Any help, advice or suggestions would be greatly appreciated.
>
> Just by way of explanation, I have four buttons on a form (up, down, left,
> right) that move the CrossHair around inside a circle. The button below
> simply brings the CrossHair back to the centre of the circle.
>
> Thanks
>
> Jem
> Private Sub btnCtr_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnCtr.Click
>
> Dim VertCrossHairX1 As Integer = 75
>
> Dim VertCrossHairX2 As Integer = 75
>
> Dim VertCrossHairY1 As Integer = 70
>
> Dim VertCrossHairY2 As Integer = 80
>
> Dim HorCrossHairY1 As Integer = 75
>
> Dim HorCrossHairY2 As Integer = 75
>
> Dim HorCrossHairX1 As Integer = 70
>
> Dim HorCrossHairX2 As Integer = 80
>
> ' Return the current form as a drawing surface
>
> myGraphics = Graphics.FromHwnd(ActiveForm().Handle)
>
> ' Clear all the graphics ready for redraw
>
> myGraphics.Clear(Color.Aquamarine)
>
> ' Create a new pen object using the color structure
>
> myPen = New Pen(Color:=Color.Blue, Width:=1)
>
> ' Set the pen colour for the Main Circle
>
> myPen.Color = Color.Blue
>
> 'draw an ellipse inside a bounding rectangle with a Pen instance
>
> myGraphics.DrawEllipse(pen:=myPen, rect:=New Rectangle(x:=25, y:=25,
> Width:=100, Height:=100))
>
> ' Set the pen colour for the Main lines
>
> myPen.Color = Color.Black
>
> 'draw the vertical line on the form using the pen object
>
> myGraphics.DrawLine(pen:=myPen, x1:=75, y1:=25, x2:=75, y2:=125)
>
> 'draw the horizontal line on the form using the pen object
>
> myGraphics.DrawLine(pen:=myPen, x1:=25, y1:=75, x2:=125, y2:=75)
>
> ' Set the pen colour for the CrossHair
>
> myPen.Color = Color.Red
>
> ' Draw the vertical CrossHair line on the form using the pen object
>
> myGraphics.DrawLine(pen:=myPen, x1:=VertCrossHairX1, y1:=VertCrossHairY1,
> x2:=VertCrossHairX2, y2:=VertCrossHairY2)
>
> ' Draw the horizontal CrossHair line on the form using the pen object
>
> myGraphics.DrawLine(pen:=myPen, x1:=HorCrossHairX1, y1:=HorCrossHairY1,
> x2:=HorCrossHairX2, y2:=HorCrossHairY2)
>
> End Sub
>
> "Jem" <xxxxxxxxxx> wrote in message
> news:kvudnWQfK-x2CjvYnZ2dnUVZ8surnZ2d@pipex.net...
>> How difficult can it be to draw a circle and a couple of lines in VS 2005
>> VB.net???????
>>
>> It was so much easier when I could just select a tool and draw them at
>> design time!
>>
>> This has got me really frustrated, and feeling pretty stupid. All I want
>> to do is to display a circle on a pocket PC screen (WM5) have it
>> intersected with a horizontal and vertical line so that it looks like the
>> cross hairs on a gun sight. I then want a smaller crosshair in the
>> middle that can be moved around by means of four buttons, one each for
>> up, down, left and right. Each time a button is clicked I want the small
>> crosshair to move .01mm in the corrosponding direction. The large
>> crosshair will always remain stationary, thus referencing the centre of
>> the circle
>>
>> I'm a real novice programmer and this is driving me mad. My simple
>> programs have never really needed any sort of graphics before. It used
>> to be so easy.
>>
>> Can anyone help me out please.
>>
>> Many thanks
>>
>> Jem
>>
>
>



Re: Aaaaarghhh!!! Drawing a circle? by Jem

Jem
Sat Jan 13 16:36:54 CST 2007

Hi Chris

Too right it's painful!! All i'm trying to do is update an old lens
calculation program. In VB6 I just grabbed the circle/line tool and dropped
it onto the form - Easy!

O.K., so here's where i'm up to at the moment. I scrapped the initial code
and went down your suggested path. I now get an error in the
'RefreshGraphics' Sub Routinewhen I try to refresh the drawing in order to
show the new CrossHair status. It's this bit of code that's causing it...

myGraphics.DrawEllipse(pen:=Pens.Blue, rect:=New Rectangle(x:=25, y:=25,
Width:=100, Height:=100))


The error is...
A first chance exception of type 'System.NullReferenceException

I pretty much know that it's because the myGraphics variable isn't available
in this Sub - the question is how do I get it so that it is recognised -
i've tried various options, all of which were failures. Could you possibly
give me some ideas as to what I should be looking for. I am trying hard -
honest! :-)
Public Class Form1

' Variable for Graphics

Dim myGraphics As Graphics

' Set up some variables for the CrossHair

' By changing these values (btnUp,btnDown, btnLeft, btnRight) we can move
the CrossHair

Dim VertCrossHairX1 As Integer = 75

Dim VertCrossHairX2 As Integer = 75

Dim VertCrossHairY1 As Integer = 70

Dim VertCrossHairY2 As Integer = 80

Dim HorCrossHairY1 As Integer = 75

Dim HorCrossHairY2 As Integer = 75

Dim HorCrossHairX1 As Integer = 70

Dim HorCrossHairX2 As Integer = 80



Protected Overrides Sub onPaint(ByVal pe As PaintEventArgs)

Dim MyGraphics As Graphics = pe.Graphics

'draw an ellipse inside a bounding rectangle

MyGraphics.DrawEllipse(pen:=Pens.Blue, rect:=New Rectangle(x:=25, y:=25,
Width:=100, Height:=100))

'draw the vertical line on the form using the pen object

MyGraphics.DrawLine(pen:=Pens.Black, x1:=75, y1:=25, x2:=75, y2:=125)

'draw the horizontal line on the form using the pen object

MyGraphics.DrawLine(pen:=Pens.Black, x1:=25, y1:=75, x2:=125, y2:=75)

' Draw the vertical CrossHair line on the form using the pen object

MyGraphics.DrawLine(pen:=Pens.Red, x1:=VertCrossHairX1, y1:=VertCrossHairY1,
x2:=VertCrossHairX2, y2:=VertCrossHairY2)

' Draw the horizontal CrossHair line on the form using the pen object

MyGraphics.DrawLine(pen:=Pens.Red, x1:=HorCrossHairX1, y1:=HorCrossHairY1,
x2:=HorCrossHairX2, y2:=HorCrossHairY2)

End Sub

Private Sub RefreshGraphics()

' Clear all the graphics ready for redraw

'draw an ellipse inside a bounding rectangle with a Pen instance

myGraphics.DrawEllipse(pen:=Pens.Blue, rect:=New Rectangle(x:=25, y:=25,
Width:=100, Height:=100))

'draw the vertical line on the form using the pen object

myGraphics.DrawLine(pen:=Pens.Black, x1:=75, y1:=25, x2:=75, y2:=125)

'draw the horizontal line on the form using the pen object

myGraphics.DrawLine(pen:=Pens.Black, x1:=25, y1:=75, x2:=125, y2:=75)

' Draw the vertical CrossHair line on the form using the pen object

myGraphics.DrawLine(pen:=Pens.Red, x1:=VertCrossHairX1, y1:=VertCrossHairY1,
x2:=VertCrossHairX2, y2:=VertCrossHairY2)

' Draw the horizontal CrossHair line on the form using the pen object

myGraphics.DrawLine(pen:=Pens.Red, x1:=HorCrossHairX1, y1:=HorCrossHairY1,
x2:=HorCrossHairX2, y2:=HorCrossHairY2)

' Set the variables back to their initial values

VertCrossHairX1 = 75

VertCrossHairX2 = 75

VertCrossHairY1 = 70

VertCrossHairY2 = 80

HorCrossHairY1 = 75

HorCrossHairY2 = 75

HorCrossHairX1 = 70

HorCrossHairX2 = 80

End Sub

Private Sub btnRight_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnRight.Click

VertCrossHairX1 = VertCrossHairX1 + 1

VertCrossHairX2 = VertCrossHairX2 + 1

HorCrossHairX1 = HorCrossHairX1 + 1

HorCrossHairX2 = HorCrossHairX2 + 1

RefreshGraphics()

End Sub

Private Sub btnLeft_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLeft.Click

VertCrossHairX1 = VertCrossHairX1 - 1

VertCrossHairX2 = VertCrossHairX2 - 1

HorCrossHairX1 = HorCrossHairX1 - 1

HorCrossHairX2 = HorCrossHairX2 - 1

RefreshGraphics()

End Sub

Private Sub btnUp_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUp.Click

VertCrossHairY1 = VertCrossHairY1 - 1

VertCrossHairY2 = VertCrossHairY2 - 1

HorCrossHairY1 = HorCrossHairY1 - 1

HorCrossHairY2 = HorCrossHairY2 - 1

RefreshGraphics()

End Sub

Private Sub btnDown_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDown.Click

VertCrossHairY1 = VertCrossHairY1 + 1

VertCrossHairY2 = VertCrossHairY2 + 1

HorCrossHairY1 = HorCrossHairY1 + 1

HorCrossHairY2 = HorCrossHairY2 + 1

RefreshGraphics()

End Sub

End Class

"Jem" <xxxxxxxxxx> wrote in message
news:kvudnWQfK-x2CjvYnZ2dnUVZ8surnZ2d@pipex.net...
> How difficult can it be to draw a circle and a couple of lines in VS 2005
> VB.net???????
>
> It was so much easier when I could just select a tool and draw them at
> design time!
>
> This has got me really frustrated, and feeling pretty stupid. All I want
> to do is to display a circle on a pocket PC screen (WM5) have it
> intersected with a horizontal and vertical line so that it looks like the
> cross hairs on a gun sight. I then want a smaller crosshair in the middle
> that can be moved around by means of four buttons, one each for up, down,
> left and right. Each time a button is clicked I want the small crosshair
> to move .01mm in the corrosponding direction. The large crosshair will
> always remain stationary, thus referencing the centre of the circle
>
> I'm a real novice programmer and this is driving me mad. My simple
> programs have never really needed any sort of graphics before. It used to
> be so easy.
>
> Can anyone help me out please.
>
> Many thanks
>
> Jem
>



Re: Aaaaarghhh!!! Drawing a circle? by ctacke/>

ctacke/>
Sat Jan 13 17:18:53 CST 2007

How's this?

http://blog.opennetcf.org/ctacke/PermaLink,guid,93ce9487-4afc-401c-beec-dc63bc8876e7.aspx


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--


"Jem" <xxxxxxxxxx> wrote in message
news:06WdnUtVpZ-awjTYnZ2dnUVZ8v2vnZ2d@pipex.net...
> Hi Chris
>
> Too right it's painful!! All i'm trying to do is update an old lens
> calculation program. In VB6 I just grabbed the circle/line tool and
> dropped it onto the form - Easy!
>
> O.K., so here's where i'm up to at the moment. I scrapped the initial
> code and went down your suggested path. I now get an error in the
> 'RefreshGraphics' Sub Routinewhen I try to refresh the drawing in order to
> show the new CrossHair status. It's this bit of code that's causing it...
>
> myGraphics.DrawEllipse(pen:=Pens.Blue, rect:=New Rectangle(x:=25, y:=25,
> Width:=100, Height:=100))
>
>
> The error is...
> A first chance exception of type 'System.NullReferenceException
>
> I pretty much know that it's because the myGraphics variable isn't
> available in this Sub - the question is how do I get it so that it is
> recognised - i've tried various options, all of which were failures.
> Could you possibly give me some ideas as to what I should be looking for.
> I am trying hard - honest! :-)
> Public Class Form1
>
> ' Variable for Graphics
>
> Dim myGraphics As Graphics
>
> ' Set up some variables for the CrossHair
>
> ' By changing these values (btnUp,btnDown, btnLeft, btnRight) we can move
> the CrossHair
>
> Dim VertCrossHairX1 As Integer = 75
>
> Dim VertCrossHairX2 As Integer = 75
>
> Dim VertCrossHairY1 As Integer = 70
>
> Dim VertCrossHairY2 As Integer = 80
>
> Dim HorCrossHairY1 As Integer = 75
>
> Dim HorCrossHairY2 As Integer = 75
>
> Dim HorCrossHairX1 As Integer = 70
>
> Dim HorCrossHairX2 As Integer = 80
>
>
>
> Protected Overrides Sub onPaint(ByVal pe As PaintEventArgs)
>
> Dim MyGraphics As Graphics = pe.Graphics
>
> 'draw an ellipse inside a bounding rectangle
>
> MyGraphics.DrawEllipse(pen:=Pens.Blue, rect:=New Rectangle(x:=25, y:=25,
> Width:=100, Height:=100))
>
> 'draw the vertical line on the form using the pen object
>
> MyGraphics.DrawLine(pen:=Pens.Black, x1:=75, y1:=25, x2:=75, y2:=125)
>
> 'draw the horizontal line on the form using the pen object
>
> MyGraphics.DrawLine(pen:=Pens.Black, x1:=25, y1:=75, x2:=125, y2:=75)
>
> ' Draw the vertical CrossHair line on the form using the pen object
>
> MyGraphics.DrawLine(pen:=Pens.Red, x1:=VertCrossHairX1,
> y1:=VertCrossHairY1, x2:=VertCrossHairX2, y2:=VertCrossHairY2)
>
> ' Draw the horizontal CrossHair line on the form using the pen object
>
> MyGraphics.DrawLine(pen:=Pens.Red, x1:=HorCrossHairX1, y1:=HorCrossHairY1,
> x2:=HorCrossHairX2, y2:=HorCrossHairY2)
>
> End Sub
>
> Private Sub RefreshGraphics()
>
> ' Clear all the graphics ready for redraw
>
> 'draw an ellipse inside a bounding rectangle with a Pen instance
>
> myGraphics.DrawEllipse(pen:=Pens.Blue, rect:=New Rectangle(x:=25, y:=25,
> Width:=100, Height:=100))
>
> 'draw the vertical line on the form using the pen object
>
> myGraphics.DrawLine(pen:=Pens.Black, x1:=75, y1:=25, x2:=75, y2:=125)
>
> 'draw the horizontal line on the form using the pen object
>
> myGraphics.DrawLine(pen:=Pens.Black, x1:=25, y1:=75, x2:=125, y2:=75)
>
> ' Draw the vertical CrossHair line on the form using the pen object
>
> myGraphics.DrawLine(pen:=Pens.Red, x1:=VertCrossHairX1,
> y1:=VertCrossHairY1, x2:=VertCrossHairX2, y2:=VertCrossHairY2)
>
> ' Draw the horizontal CrossHair line on the form using the pen object
>
> myGraphics.DrawLine(pen:=Pens.Red, x1:=HorCrossHairX1, y1:=HorCrossHairY1,
> x2:=HorCrossHairX2, y2:=HorCrossHairY2)
>
> ' Set the variables back to their initial values
>
> VertCrossHairX1 = 75
>
> VertCrossHairX2 = 75
>
> VertCrossHairY1 = 70
>
> VertCrossHairY2 = 80
>
> HorCrossHairY1 = 75
>
> HorCrossHairY2 = 75
>
> HorCrossHairX1 = 70
>
> HorCrossHairX2 = 80
>
> End Sub
>
> Private Sub btnRight_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnRight.Click
>
> VertCrossHairX1 = VertCrossHairX1 + 1
>
> VertCrossHairX2 = VertCrossHairX2 + 1
>
> HorCrossHairX1 = HorCrossHairX1 + 1
>
> HorCrossHairX2 = HorCrossHairX2 + 1
>
> RefreshGraphics()
>
> End Sub
>
> Private Sub btnLeft_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnLeft.Click
>
> VertCrossHairX1 = VertCrossHairX1 - 1
>
> VertCrossHairX2 = VertCrossHairX2 - 1
>
> HorCrossHairX1 = HorCrossHairX1 - 1
>
> HorCrossHairX2 = HorCrossHairX2 - 1
>
> RefreshGraphics()
>
> End Sub
>
> Private Sub btnUp_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnUp.Click
>
> VertCrossHairY1 = VertCrossHairY1 - 1
>
> VertCrossHairY2 = VertCrossHairY2 - 1
>
> HorCrossHairY1 = HorCrossHairY1 - 1
>
> HorCrossHairY2 = HorCrossHairY2 - 1
>
> RefreshGraphics()
>
> End Sub
>
> Private Sub btnDown_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnDown.Click
>
> VertCrossHairY1 = VertCrossHairY1 + 1
>
> VertCrossHairY2 = VertCrossHairY2 + 1
>
> HorCrossHairY1 = HorCrossHairY1 + 1
>
> HorCrossHairY2 = HorCrossHairY2 + 1
>
> RefreshGraphics()
>
> End Sub
>
> End Class
>
> "Jem" <xxxxxxxxxx> wrote in message
> news:kvudnWQfK-x2CjvYnZ2dnUVZ8surnZ2d@pipex.net...
>> How difficult can it be to draw a circle and a couple of lines in VS 2005
>> VB.net???????
>>
>> It was so much easier when I could just select a tool and draw them at
>> design time!
>>
>> This has got me really frustrated, and feeling pretty stupid. All I want
>> to do is to display a circle on a pocket PC screen (WM5) have it
>> intersected with a horizontal and vertical line so that it looks like the
>> cross hairs on a gun sight. I then want a smaller crosshair in the
>> middle that can be moved around by means of four buttons, one each for
>> up, down, left and right. Each time a button is clicked I want the small
>> crosshair to move .01mm in the corrosponding direction. The large
>> crosshair will always remain stationary, thus referencing the centre of
>> the circle
>>
>> I'm a real novice programmer and this is driving me mad. My simple
>> programs have never really needed any sort of graphics before. It used
>> to be so easy.
>>
>> Can anyone help me out please.
>>
>> Many thanks
>>
>> Jem
>>
>
>



Re: Aaaaarghhh!!! Drawing a circle? by Jem

Jem
Sun Jan 14 04:18:37 CST 2007

Hi Chris

Thanks for demo program. Unfortunately it doesn't want to run :-(

I'm getting these error messages...

Error 1 Overload resolution failed because no accessible 'DrawLine' can be
called without a narrowing conversion:
'Public Sub DrawLine(pen As System.Drawing.Pen, x1 As Integer, y1 As
Integer, x2 As Integer, y2 As Integer)': Argument matching parameter 'x1'
narrows from 'Double' to 'Integer'.
'Public Sub DrawLine(pen As System.Drawing.Pen, x1 As Integer, y1 As
Integer, x2 As Integer, y2 As Integer)': Argument matching parameter 'x2'
narrows from 'Double' to 'Integer'.
'Public Sub DrawLine(pen As System.Drawing.Pen, x1 As Single, y1 As
Single, x2 As Single, y2 As Single)': Argument matching parameter 'x1'
narrows from 'Double' to 'Single'.
'Public Sub DrawLine(pen As System.Drawing.Pen, x1 As Single, y1 As
Single, x2 As Single, y2 As Single)': Argument matching parameter 'x2'
narrows from 'Double' to 'Single'. C:\Documents and Settings\Jeremy
Turner\My Documents\Visual Studio 2005\Projects\Lens Drawing Demo\Lens
Drawing Demo\Form1.vb 19 9 Lens Drawing Demo


Error 2 Overload resolution failed because no accessible 'DrawLine' can be
called without a narrowing conversion:
'Public Sub DrawLine(pen As System.Drawing.Pen, x1 As Integer, y1 As
Integer, x2 As Integer, y2 As Integer)': Argument matching parameter 'y1'
narrows from 'Double' to 'Integer'.
'Public Sub DrawLine(pen As System.Drawing.Pen, x1 As Integer, y1 As
Integer, x2 As Integer, y2 As Integer)': Argument matching parameter 'y2'
narrows from 'Double' to 'Integer'.
'Public Sub DrawLine(pen As System.Drawing.Pen, x1 As Single, y1 As
Single, x2 As Single, y2 As Single)': Argument matching parameter 'y1'
narrows from 'Double' to 'Single'.
'Public Sub DrawLine(pen As System.Drawing.Pen, x1 As Single, y1 As
Single, x2 As Single, y2 As Single)': Argument matching parameter 'y2'
narrows from 'Double' to 'Single'. C:\Documents and Settings\My
Documents\Visual Studio 2005\Projects\Lens Drawing Demo\Lens Drawing
Demo\Form1.vb 24 9 Lens Drawing Demo

It appears they are occurring exclusively in the 'DrawCrossHairs' Sub
Routine.

Any pointers?

I can't express how grateful I am to you for helping me along with this
project. The software I am trying to convert was written in VB6 for the
desktop PC in about 1999. I was never very good at programming then but I
managed to get by and the program has served me well for the last 8 years,
I'm now almost 8 years older (49) and i'm sure my brain isn't quite as
nimble as it used to be.

My work is in the Optical Lens field and this program saves me loads of time
calculating the prismatic effect at any point away from the Optical Centre
on a spherical or toric lens. The maths and writing the calculation bit of
the program is fine for me (i've managed to convert 8 other calculation
programs and this is the final one), but having never had to do .Net
graphics, along with rewriting the rest in .Net for the Pocket PC is
beginning to take its toll. It's now starting to become one of those jobs I
wish i'd never started!

I do hope that you can help me

Cheers

Jeremy

"<ctacke/>" <ctacke[@]opennetcf[dot]com> wrote in message
news:%23bczvk2NHHA.536@TK2MSFTNGP02.phx.gbl...
> How's this?
>
> http://blog.opennetcf.org/ctacke/PermaLink,guid,93ce9487-4afc-401c-beec-dc63bc8876e7.aspx
>
>
> --
> Chris Tacke
> OpenNETCF Consulting
> Managed Code in the Embedded World
> www.opennetcf.com
> --
>
>
> "Jem" <xxxxxxxxxx> wrote in message
> news:06WdnUtVpZ-awjTYnZ2dnUVZ8v2vnZ2d@pipex.net...
>> Hi Chris
>>
>> Too right it's painful!! All i'm trying to do is update an old lens
>> calculation program. In VB6 I just grabbed the circle/line tool and
>> dropped it onto the form - Easy!
>>
>> O.K., so here's where i'm up to at the moment. I scrapped the initial
>> code and went down your suggested path. I now get an error in the
>> 'RefreshGraphics' Sub Routinewhen I try to refresh the drawing in order
>> to show the new CrossHair status. It's this bit of code that's causing
>> it...
>>
>> myGraphics.DrawEllipse(pen:=Pens.Blue, rect:=New Rectangle(x:=25, y:=25,
>> Width:=100, Height:=100))
>>
>>
>> The error is...
>> A first chance exception of type 'System.NullReferenceException
>>
>> I pretty much know that it's because the myGraphics variable isn't
>> available in this Sub - the question is how do I get it so that it is
>> recognised - i've tried various options, all of which were failures.
>> Could you possibly give me some ideas as to what I should be looking for.
>> I am trying hard - honest! :-)
>> Public Class Form1
>>
>> ' Variable for Graphics
>>
>> Dim myGraphics As Graphics
>>
>> ' Set up some variables for the CrossHair
>>
>> ' By changing these values (btnUp,btnDown, btnLeft, btnRight) we can move
>> the CrossHair
>>
>> Dim VertCrossHairX1 As Integer = 75
>>
>> Dim VertCrossHairX2 As Integer = 75
>>
>> Dim VertCrossHairY1 As Integer = 70
>>
>> Dim VertCrossHairY2 As Integer = 80
>>
>> Dim HorCrossHairY1 As Integer = 75
>>
>> Dim HorCrossHairY2 As Integer = 75
>>
>> Dim HorCrossHairX1 As Integer = 70
>>
>> Dim HorCrossHairX2 As Integer = 80
>>
>>
>>
>> Protected Overrides Sub onPaint(ByVal pe As PaintEventArgs)
>>
>> Dim MyGraphics As Graphics = pe.Graphics
>>
>> 'draw an ellipse inside a bounding rectangle
>>
>> MyGraphics.DrawEllipse(pen:=Pens.Blue, rect:=New Rectangle(x:=25, y:=25,
>> Width:=100, Height:=100))
>>
>> 'draw the vertical line on the form using the pen object
>>
>> MyGraphics.DrawLine(pen:=Pens.Black, x1:=75, y1:=25, x2:=75, y2:=125)
>>
>> 'draw the horizontal line on the form using the pen object
>>
>> MyGraphics.DrawLine(pen:=Pens.Black, x1:=25, y1:=75, x2:=125, y2:=75)
>>
>> ' Draw the vertical CrossHair line on the form using the pen object
>>
>> MyGraphics.DrawLine(pen:=Pens.Red, x1:=VertCrossHairX1,
>> y1:=VertCrossHairY1, x2:=VertCrossHairX2, y2:=VertCrossHairY2)
>>
>> ' Draw the horizontal CrossHair line on the form using the pen object
>>
>> MyGraphics.DrawLine(pen:=Pens.Red, x1:=HorCrossHairX1,
>> y1:=HorCrossHairY1, x2:=HorCrossHairX2, y2:=HorCrossHairY2)
>>
>> End Sub
>>
>> Private Sub RefreshGraphics()
>>
>> ' Clear all the graphics ready for redraw
>>
>> 'draw an ellipse inside a bounding rectangle with a Pen instance
>>
>> myGraphics.DrawEllipse(pen:=Pens.Blue, rect:=New Rectangle(x:=25, y:=25,
>> Width:=100, Height:=100))
>>
>> 'draw the vertical line on the form using the pen object
>>
>> myGraphics.DrawLine(pen:=Pens.Black, x1:=75, y1:=25, x2:=75, y2:=125)
>>
>> 'draw the horizontal line on the form using the pen object
>>
>> myGraphics.DrawLine(pen:=Pens.Black, x1:=25, y1:=75, x2:=125, y2:=75)
>>
>> ' Draw the vertical CrossHair line on the form using the pen object
>>
>> myGraphics.DrawLine(pen:=Pens.Red, x1:=VertCrossHairX1,
>> y1:=VertCrossHairY1, x2:=VertCrossHairX2, y2:=VertCrossHairY2)
>>
>> ' Draw the horizontal CrossHair line on the form using the pen object
>>
>> myGraphics.DrawLine(pen:=Pens.Red, x1:=HorCrossHairX1,
>> y1:=HorCrossHairY1, x2:=HorCrossHairX2, y2:=HorCrossHairY2)
>>
>> ' Set the variables back to their initial values
>>
>> VertCrossHairX1 = 75
>>
>> VertCrossHairX2 = 75
>>
>> VertCrossHairY1 = 70
>>
>> VertCrossHairY2 = 80
>>
>> HorCrossHairY1 = 75
>>
>> HorCrossHairY2 = 75
>>
>> HorCrossHairX1 = 70
>>
>> HorCrossHairX2 = 80
>>
>> End Sub
>>
>> Private Sub btnRight_Click(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles btnRight.Click
>>
>> VertCrossHairX1 = VertCrossHairX1 + 1
>>
>> VertCrossHairX2 = VertCrossHairX2 + 1
>>
>> HorCrossHairX1 = HorCrossHairX1 + 1
>>
>> HorCrossHairX2 = HorCrossHairX2 + 1
>>
>> RefreshGraphics()
>>
>> End Sub
>>
>> Private Sub btnLeft_Click(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles btnLeft.Click
>>
>> VertCrossHairX1 = VertCrossHairX1 - 1
>>
>> VertCrossHairX2 = VertCrossHairX2 - 1
>>
>> HorCrossHairX1 = HorCrossHairX1 - 1
>>
>> HorCrossHairX2 = HorCrossHairX2 - 1
>>
>> RefreshGraphics()
>>
>> End Sub
>>
>> Private Sub btnUp_Click(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles btnUp.Click
>>
>> VertCrossHairY1 = VertCrossHairY1 - 1
>>
>> VertCrossHairY2 = VertCrossHairY2 - 1
>>
>> HorCrossHairY1 = HorCrossHairY1 - 1
>>
>> HorCrossHairY2 = HorCrossHairY2 - 1
>>
>> RefreshGraphics()
>>
>> End Sub
>>
>> Private Sub btnDown_Click(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles btnDown.Click
>>
>> VertCrossHairY1 = VertCrossHairY1 + 1
>>
>> VertCrossHairY2 = VertCrossHairY2 + 1
>>
>> HorCrossHairY1 = HorCrossHairY1 + 1
>>
>> HorCrossHairY2 = HorCrossHairY2 + 1
>>
>> RefreshGraphics()
>>
>> End Sub
>>
>> End Class
>>
>> "Jem" <xxxxxxxxxx> wrote in message
>> news:kvudnWQfK-x2CjvYnZ2dnUVZ8surnZ2d@pipex.net...
>>> How difficult can it be to draw a circle and a couple of lines in VS
>>> 2005 VB.net???????
>>>
>>> It was so much easier when I could just select a tool and draw them at
>>> design time!
>>>
>>> This has got me really frustrated, and feeling pretty stupid. All I
>>> want to do is to display a circle on a pocket PC screen (WM5) have it
>>> intersected with a horizontal and vertical line so that it looks like
>>> the cross hairs on a gun sight. I then want a smaller crosshair in the
>>> middle that can be moved around by means of four buttons, one each for
>>> up, down, left and right. Each time a button is clicked I want the
>>> small crosshair to move .01mm in the corrosponding direction. The large
>>> crosshair will always remain stationary, thus referencing the cen