Creating a new form

hendrikbez

Active member
Joined
Nov 24, 2005
Messages
35
Location
South Afica
Programming Experience
1-3
I am new to vb.net, and I want to make a customize winsows form for my sine-in form, it will be a cross, how do I Use the graphics in vb.net 2003.:eek:

Thanks
 
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.

Is this enough information for you?:)
 
No problem.

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...

[e.graphics.drawpath(new pen(color.black),mygraphicspath).

 
Thanks for your reply

I get error on "dim MyGraphicsPath as new Graphicspath" it dont want to exept graphicpaht or anything else here


Where can I get a sample on this or were can I get a tuturiol on how to do this in vb.net.
 
Sorry thats my fault....

At the very top of your class above the 'Public Class.....' Statement add the following imports statements......

[Imports system.drawing]
[imports system.drawing.drawing2d]

You now can access the graphics classes as thier members.

As for the tutorial have a lok on MSDN they have some helpful articals on GDI+ and it's where i got started when i was trying to learn.
 
I have put this in my form, but When I run it I cannot see the line.

With this will it when I get it to work, only show the cross and not the whole form.

Protected
Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim myGraphicspath As New GraphicsPath
myGraphicspath.AddLine(100, 2000, 500, 200)
'myGraphicspath.AddLines(30, 50, 20, 20)
e.Graphics.DrawPath(New Pen(Color.Red), myGraphicspath)
End Sub
 
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.

Making any sense?
 
vis781

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.

Thanks
 
I have put in this four lines, the first three line is working ok, but when I add the fouth line, it draws extra line from the others.

Gp.AddLine(250, 60, 250, 100)

Gp.AddLine(250, 60, 310, 60)
Gp.AddLine(310, 60, 310, 100)
Gp.AddLine(70, 80, 70, 80)


 
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.
 
Back
Top