Hey there,
At school my teacher gave me vb project that we haven't studied yet... and of course i have no idea how do it.
The image updated below is the task.How can it be drawn any tips?
Wow, tough task if you are new to VB. Is your class VB6 or VB.Net?
The triangle is the hardest shape I would think and you can find threads on this forum about drawing triangles. The other shapes are common rectangles, circles and lines. Those should not be too hard. But you should let us know which "visual basic" you are using.
And one more thing, most here will not do the work for you. We will give hints and help fix your code once you show it to us.
Welcome to the forums
Insomnia is just a byproduct of, "It can't be done"
Yeah, I agree. Using a combination of the "Line" control and the "Shape" control, all of it is easy except for the triangle.
If it must be done with code (and not "cheating" and using a paint program to make that shape, and then put it in a picturebox), I'd probably do it with a series of lines, making each line shorter and shorter, until the length went to zero.
I probably shouldn't do this, but I'd prefer you become a VB6 advocate rather than get frustrated with not being able to do it. Here's how my quick attempt to get the triangle done worked out:
Rather than just attaching a completed project, I'll make you work for it just a touch. here's the code in a Form1 I used to do that:
Code:
Option Explicit
Private Sub Form_Load()
Dim i As Long
For i = 1 To 1000
Load Line1(i)
Line1(i).X1 = Line1(i - 1).X1 + 15
Line1(i).X2 = Line1(i - 1).X2 - 15
Line1(i).Y1 = Line1(i - 1).Y1 - 15
Line1(i).Y2 = Line1(i - 1).Y2 - 15
If Line1(i).X1 > Line1(i).X2 Then
Unload Line1(i)
Exit For
End If
Line1(i).Visible = True
Next i
End Sub
Now, what I did was place a Line1 on the Form1. Then, I turned it red, and then I set its index property to zero (allowing me to make copies). Hopefully, obviously, the line was placed on the form in a horizontal fashion. I'll let you work it out from there.
All the other shapes should be fairly easy with the Shape control, and maybe more use of the Line control. But that can all be done directly from the VB6 design mode with no need for any code.
Good Luck,
Elroy
p.s. If you want the triangle to be shorter or taller, tweak on the first two 15's (the ones messing with X1 and X2. You should probably leave the Y1 and Y2 15's alone, as that's moving the lines up one pixel per line.
p.p.s. The base of the triangle will always start wherever you place your zero index line.
Last edited by Elroy; Apr 25th, 2017 at 10:25 AM.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
Cool... Everyone does it different. I use the trusty Polygon.
Code:
Private Declare Function Polygon Lib "gdi32" (ByVal hDC As Long, lpPoint As TPOINT, ByVal nCount As Long) As Long
Private Type TPOINT
X As Long
Y As Long
End Type
Private Sub Form_Paint()
Dim Point(1 To 3) As TPOINT
Point(1).X = 120
Point(1).Y = 40
Point(2).X = 200
Point(2).Y = 120
Point(3).X = 40
Point(3).Y = 120
ScaleMode = vbPixels
FillStyle = vbSolid
ForeColor = vbRed
FillColor = vbRed
DrawWidth = 1
Polygon hDC, Point(1), UBound(Point)
End Sub
Last edited by DEXWERX; Apr 25th, 2017 at 11:27 AM.
Hey Dex, that's pretty cool, but if he's truly a noob, I'm not sure we want to throw API calls at him just yet. *laughs and shakes head*
I was actually worried about throwing control arrays at him.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
The 'tip' for using no code, just picturebox, shapes (circles and rectangles) and lines, is to hide part of the red roof. Simple...two 'fat' lines (width of 80 in my example), angled appropriately, and then set border color to the color of the picturebox back color. Below is the image showing those two lines, but in Blue. I used circles for the leaves and sun, and lines for the grass and sun rays. All basic, basic stuff.
Use the Order Property to put the Red Rectangle (roof) behind those two lines, and also use the Order Property to put the tree trunk behind the 'leaves'.
As OP didn't say HOW he wanted this done...sometime the simpler is the better (yes dile?).
All of this is possible in code as well, but why spend all that time doing that when the tools are readily available in the IDE; that is why we HAVE VB and other UI programs.
I suspect the prof put that triangle in there trying to get them to use a bit of code, but you certainly met the criteria.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
@the OP
Please don't bring that as a solution to your problem, because:
- it might not work, when the Screen-Resolution is higher than 100% (the coords and fontsizes will work properly only with 96dpi).
- your teacher will expect, that you will make yourself familiar with VBs "normal" drawing-commands
It is amazing. Olaf's source code runs on my computer, and there are different effects, falling many gifts from heaven, and there are two children's faces behind the tree. Olaf is a superman.
Last edited by dreammanor; Apr 25th, 2017 at 09:53 PM.
@Olaf: I'll have to second LaVolpe's comment. That's pretty creative. If we don't stop, vanko0o1 will tell the entire class to come here and just divvy up the different ways it's been done.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
And for the Unicode version, also replace Sub TextOut:
Code:
Sub TextOut(x, y, S As String, Color, Optional ByVal pFontSize = 10)
ForeColor = Color: FontSize = pFontSize
TextOutW hDC, x * 15 / Screen.TwipsPerPixelX, y * 15 / Screen.TwipsPerPixelY, StrPtr(S), Len(S)
End Sub
Just curious...what ARE you going to do? Have you completed your assignment? Did you understand all the 'advice' given above? What grade did you get????
Yeah, I'd be curious to know too. Maybe he sprinkled in a few ideas from all the above and really blew his professor away. hahaha, I'd love it if he actually did that.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.