advertisement
from the None department...
How could I draw a Polygon in Visual Basic?
Programming languages. topic
Posted by Javier Garcia on 17 November, 2002 - 3:00 pm
I have been playing with Visual Basic trying to find out why many people say that Visual Basic could be use as HMI. My first steps were oriented to the graphics area and I tried drawing the most common shapes used in any HMI (Circles, Rectangles, polygons). I expected to see in Visual Basic a friendly graphic editor to do that (as almost any HMI), but I haven't found any way to create Polygons, even triangles to change on them backcolor, styles, etc. Personalized valves, motors, general symbols involved on HMI applicatios alwas require shapes as polygons. How you guys are dealing with this?

Any advice would be appreciated.

Javier Garcia
Harper International


Posted by Miguel on 18 November, 2002 - 10:11 am
If You want to do it the easey way You have to purchase an ActiveX library of instrumentation components like http://www.globalmajic.com/index.html
If you want to create shapes by force , I belive that you must do it by API calls to functions such as SetWindowRgn.
You may also need a communication library such as
Parijat.
You can find more information about the subject in http://www.htservices.com/Tools/VisualBasic/index.htm


Posted by Yosef Feigenbaum on 18 November, 2002 - 10:05 am
This may not be a complete solution to the problem but you could always use the Windows API (gdi32) to call the polygon function. There are probably a bunch of sites on the internet where you could find examples of how to create a polygon from VB code.

Good Luck

(8{)} ( .)
yosi(AT)ludan.co.il


Posted by Sven on 18 November, 2002 - 10:27 am
Process layout screens like you describe are not very easy to create in VB.

However, very often in HMI applications it will work fine with standard Windows controls.


Posted by Todd on 18 November, 2002 - 11:16 am
In the past, I have drawn the icon or symbol in a graphic editor (e.g. MS Paint) and used the Image Control to display it on a form. Unfortunately, if I need to toggle colors of a symbol (e.g. from red to green to signify that it's ON) I needed a different file for that symbol. It worked fine for the application, but it didn't have a lot if different images.

-Todd


Posted by Koen Verschueren on 18 November, 2002 - 4:19 pm
First declare the Polygon function and the POINTAPI type (in a Form or Module):

Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long) As Long

Type POINTAPI
x As Long
y As Long
End Type

Then write the following code (For instance under Command button click):

Dim point(3) As POINTAPI
Dim handle As Long
Dim temp1 As Long

Form1.Cls
handle = Form1.hDC

point(0).x = 0
point(0).y = 0
point(1).x = 20
point(1).y = 20
point(2).x = 20
point(2).y = 10
point(3).x = 10
point(3).y = 20
temp1 = Polygon(handle, punt(0), 4)

This will draw a polygon with 4 point on form1.
You can also use a picture to draw on. Change the handle to Picture1.hDC
You can add more point by increasing the point() variable.


Posted by Regis on 17 May, 2004 - 7:25 pm
Visual Basic allows you to draw rectangles, filled rectangles and lines using the line method. You can also do oval and filled oval using the circle method. You can draw a polygon using multiple line commands. Those commands are not supported anymore in VB.NET, so you will have to redo this part of code if you ever decide to port it to .NET.

What you cannot do natively is draw a filled polygon (like a filled triangle). In order to do a filled triangle in VB, you the Win32 API 'Polygon' function.

Under VB.NET, it is completely different. Although you can still use Win32 API with unmanaged .NET, you have access to Graphics.DrawPolygon to draw a polygon.

Your use of this site is subject to the terms and conditions set forth under Legal Notices and the Privacy Policy. Please read those terms and conditions carefully. Subject to the rights expressly reserved to others under Legal Notices, the content of this site and the compilation thereof is © 1999-2014 Nerds in Control, LLC. All rights reserved.

Users of this site are benefiting from open source technologies, including PHP, MySQL and Apache. Be happy.


Fortune
One good reason why computers can do more work than people is that they
never have to stop and answer the phone.
Advertise here
Advertisement
our advertisers
Help keep our servers running...
Patronize our advertisers!
Visit our Post Archive