The way i would go about this is to override the 'OnPaint' event of your form. Then in that event declare a New GraphicsPath. i.e
Dim gp as New GraphicsPath
Then using that graphics paths 'Addline' method build your cross. i.e
gp.Addline(Place code here to build the first line of your cross)...Then the
same again.... gp.addline(the next line of your cross)
And so-on untill you have your desired shape. You can then fill your shape using the gp.fillpath method with any type of brush that you like.
Then set the backcolor of the form to a color that you are NOT going to use anywhere in that form. Then set the transparency key of the form to that color. Now when you load your form your cross should appear and the rest of the form should appear transparent.
select the combobox in the the top left corner of the IDE and click on OVERRIDES then over to the declarations combobox and select 'ONPAINT'
This will open up the 'Overrides OnPaint' event
This means that you are telling VS.Net that you are going to handle the drawing of this control(which is essentially what a form is)
Inside that event Write......
[Dim MyGraphicsPath As New GraphicsPath]
(you dont have to use MyGraphicsPath it could be your name if you wanted!!)
So now you have your graphicspath object you can use it to do loads of cool stuff. For example..
[MyGraphicsPath.AddLine(10,20,50,20) Will add a very short straight lint to your graphicspath. When you want to draw it to the screen, if you look in the parameters of the 'Overrides OnPaint' event to will see...
[Byval e as .......painteventargs]
Therefore 'e' is the surface on which you are going to draw. So to draw our graphicspath on this surface we simply call...
I cant really see an awful lot wrong with that. As for the making only the cross visible. Refer to my first post on this thread in the bit about the transparency key. Thats the part that will make the from transparent apart from yuor cross.`
Thanks it is workin now I can see the line. Can you please explain the code GP.AddLine(20, 30, 300, 0) to me, what does the numbers do, I am getting a bit confused when I change them.
Ok, in order to draw anything on a 2-dimensional plane you need a starting point x,y and an ending point x,y. That is what these numbers refrer to for example...
[Gp.addline(10,10,30,10)]
The first number 10 is the horizontal location of the starting point of the line i.e 10 pixels accross on the form
The second number is the vertical location of the starting point of the line i.e 10 pixels down the form
So going 10 pixels accross from the left and ten pixels down from the top, gives us our starting point.
The third number is the horizontal location of the END of the line i.e
30 pixels accross the from
And the fourth number is the vertical location of the END of the line i.e
10 pixels down
So because this line is the same amount of pixels down the form we know it will be a straight line.
Thanks for your help, but I am still a bit confused how it works.
Do I have it right here.
1 the first number is were you want it to start to draw horizontal
2 the second number is were to start to draw the line vertical.
3 The third number is were to end the line horizontal
4 the fourth number is were to end the line vertical.
I still can not get the line to go about in the middel and it must be horizontal and about 150 pixel long.
Ok , glad that your starting to get somewhere. What is happening is that when you add lines to a graphics path visual studio will have automatically try to close the shape that you are drawing by adding a line. If you just keep adding the lines where you want them it will be fine.
As for the other question yes, that is exactly how it works.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.