Drawing Bunch of Lines To Visualbasic Picturebox - visual-studio-2010

I have thousands of x and y coordinates in a datagridview, and i need to draw lines with them. for instance row 1, cell 1 contains x, row 1 cell 2 contains y and goes on. i need to draw from row 1 to 2, row 2 to 3. must be like a design. i used For i = 1 to 1000 for instance. and i used drawline function.
Dim bmp As New Drawing.Bitmap(640, 480)
Dim gfx As Graphics = Graphics.FromImage(bmp)
Dim i As Integer
Dim prcoordx As Integer
Dim prcoordy As Integer
Dim nextcoordx As Integer
Dim nextcoordy As Integer
For i = 1 To 1000 Step 1
prcoordx = DataGridView1.Rows(i).Cells(1).Value
prcoordy = DataGridView1.Rows(i).Cells(2).Value
nextcoordx = DataGridView1.Rows(i+1).Cells(1).Value
nextcoordy = DataGridView1.Rows(i+1).Cells(2).Value
Next i
gfx.DrawLine(Pens.Black, prcoordx, prcoordy, nextcoordx, nextcoordy)

Related

VB6 Picturebox top position

In my application I have two picture boxes. Picture1 is aligned to bottom. When I press the mouse button and move the Picture2, the height of Picture1 will change accordingly. Its working fine.
My problem is when I resize the form Picture1 and Picture2 are in different position. Picture2 is not exactly in the top position of Picture1.
Private Sub Form_Resize()
Picture2.Width = Me.ScaleWidth
Picture2.Top = Picture1.Height + Picture1.Top
End Sub
Private Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next
Screen.MousePointer = 7
If Button = 1 Then
Picture2.Top = Picture2.Top + (Y)
Picture1.Height = Me.Height - Picture2.Top - 720
End If
End Sub
I am not sure what are you trying to accomplish. It seems to me that Picture1
is aligned to top, not bottom.
Anyway. Did you mean this?
Private Sub Form_Resize()
Picture2.Width = ScaleWidth
Picture2.Top = Picture1.Top + Picture1.Height
End Sub
Private Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next
Screen.MousePointer = 7
If Button = 1 Then
Picture2.Top = Picture2.Top + (Y)
Picture1.Height = Picture2.Top
End If
End Sub
The picture boxes should stay in the same position wheather you resize the form or not. As #ota milink said, I do not know what you are truly one to accomplish.

How to convert feet and inches into inches using classic .asp

I have thousands of different sizes that I need to convert from feet and inches into inches using classic .asp.
The sizes are listed in the following format:
[width] x [height]
The width and height are shown with ' marks, which stand for feet and " marks which stand for inches.
For example, take the following and convert it into inches:
2'6" x 8' = width = 30; height = 96
9'6" x 13'6" = width = 120; height = 162
Sometimes there is no X in the size, indicating that it is round or square in shape. For example:
2'6"
That would have to make both the width and height the same, so:
2'6" = width = 30; height = 30
Sometimes, there is a trailing " at the end, where there should be inches, but there are none listed. For example:
5'0" x 8'" = width = 60; height = 96
I am guessing that I would need to create some sort of custom function with expressions, but just having a hard time figuring it out.
I tried creating the following function, but it only outputs the test size I created, 5' x 4'
'example source sizes
'5'2" X 4'3"
'4' X 3'
'3'4"
'5'
'23" X 21"
'21"
'then run the function
'idsize = GetInches(rs("size"))
dim idsize
idsize = "5' x 4'"
GetInches(idsize)
Response.Write (idsize)
Function GetInches(feet_inches)
dim sizehold
feet_inches = split(feet_inches,"X")
sizehold = split(feet_inches(0),"'")
feet_inches = sizehold(0)
feet_inches = replace(feet_inches,chr(34),"")
feet_inches = replace(feet_inches,"'","")
feet_inches = trim(feet_inches)
feet_inches = feet_inches * 12
End Function
Any pointers would be appreciated.
You'll need to search the string for an X and then use string split functions.
You can split on the X if it exists to start to split things out into the width and height. You should then be able to split on the single quote, convert the feet using *12 and add to the inches.
Remember that classic ASP is basically VB script so there's probably some code for this floating around on google.

How to assign random colors to shapes in vb6 form

I am developing a game using VB6.0, I want to generate randomly moving shapes (circles, squares, rectangles, ovals, etc.) with different colors in the background of form. I am using timers and shapes to achieve this.my contribution is furnished below.
Private Sub Timer1_Timer()
For i = 0 To 20
s_left = Round(Rnd * 20050)
s_top = Round(Rnd * 860)
shape(i).Left = s_left
shape(i).Top = s_top
shape(i).Visible = True
Next i
End Sub
Now the problem is that, I can use only one shape and one color, is there any possibility to select a random color and shape within this Timer1_Timer()?
' the function that generate random colors
Public Function RandomRGBColor() As Long
RandomRGBColor = RGB( _
Int(Rnd() * 256), _
Int(Rnd() * 256), _
Int(Rnd() * 256))
End Function
your code should be changed as follows to get the requested result
dim shape_style as integer
Private Sub Timer1_Timer()
For i = 0 To 20
shape_style= Round(Rnd * 5)
s_left = Round(Rnd * 20050)
s_top = Round(Rnd * 860)
shape(i).Left = s_left
shape(i).Top = s_top
shape(i).Visible = True
shape(i).fillcolor=RandomRGBColor()
shape(i).shape=shape_style
Next i
End Sub

How to draw in a picturebox in vb6

i have used loads of websites for this but none worked so i am hoping i could get a correct answer
i have tried this could any one tell me whats wrong with it:
Private sub Picture1_mouseDown
x = picture1.currentx
y = picture1.currenty
End sub
Private sub Picture1_MouseMove
If button = 1 then
line (picture1.currentx,picture1.currenty)-(x,y), _
QBColor(0)
End if
End sub
i have cut the Private sub Picture1_MouseMove,Mousedown() bits off because i am in a rush to finish
This one will draw a line, only slightly different from kurniliya's solution which draws points
Option Explicit
Private lastX As Single
Private lastY As Single
Private Sub Form_Load()
' no need to set this every time we move the mouse inside Picture1
Picture1.DrawWidth = 5
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Picture1.Line (lastX, lastY)-(X, Y), vbBlue
End If
lastX = X
lastY = Y
End Sub
You draw a line on PictureBox control using its Line method:
Sub Line(Flags As Integer, X1 As Single, Y1 As Single, X2 As Single, Y2 As Single, Color As Long)
Member of VB.PictureBox
Draws lines and rectangles on an object.
There isn't much to say about it, and it has already been covered in How do you draw a line dynamically in vb6?
You seem to have trouble with writing event handlers though. If you don't know/remember the signature, IDE is always there to assist. Check out Assigning Code to a Control to Respond to an Event in VB6 tutorial.
There is the code to help you get started with drawing. Picture1 is PictureBox control. Blue line will be drawn when you move your mouse over the picture box holding left mouse button down.
Option Explicit
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Picture1.DrawWidth = 5
Picture1.Line (X, Y)-(X, Y), vbBlue
End If
End Sub

having trouble calculating distance in centimeters through windows phone

I developed an app to read distance between two locations on windows phone 7 . But while testing the app, whenever i move some centimeters, it starts to give value in 13000's.
Public Sub watcher1_PositionChanged(sender As Object, e As GeoPositionChangedEventArgs(Of GeoCoordinate))
Dim dCoord As GeoCoordinate
Dim currentDistance As Double
Dim convertedDistance As Double
dCoord = New GeoCoordinate(e.Position.Location.Latitude, e.Position.Location.Longitude)
If mlastCoordinate.Latitude <> 0.0 Then
'distanceText.Text = e.Position.Location.Latitude.ToString()
currentDistance = mlastCoordinate.GetDistanceTo(dCoord)
mDistance = startCoordinate.GetDistanceTo(dCoord)
' mDistance += currentDistance
'mDistance = Math.Round(mDistance, 2)
'Dim distance As String
'distance = String.Format("%.2", mDistance)
If selectedSystemState.Equals("centi") Then
convertedDistance = mDistance * 100
ElseIf selectedSystemState.Equals("meter") Then
convertedDistance = mDistance
ElseIf selectedSystemState.Equals("inches") Then
convertedDistance = mDistance * 39.37
ElseIf selectedSystemState.Equals("feet") Then
convertedDistance = mDistance * 3.28
End If
convertedDistance = Math.Round(convertedDistance, 2)
The distance you are getting is in meters. So, 13000 centimeters is 130 meters - unless we know what and how you move, this seems like a very plausible value.
How are you instantiating the Location Service - If you're not using GeoCoordinateWatcher(GeoPositionAccuracy.High) you'll likely be using Cell Tower data, which can be off by many 100s of metres.
Even if you are using GPS the accuracy of civilian GPS units is only in the order of 5-10m, so measuring distances in cm or inches is really beyond these things.
You should probably check the GeoCoordinate.HorizontalAccuracy to see what the "noise" is likely to be.

Resources