Not sure what the problem is

ssgglenn

Member
Joined
Jul 14, 2008
Messages
11
Programming Experience
1-3
As stated I am not sure what the problem is, but as I am new to GDI+, I am sure someone here can help me out.

I am developing an application that will take the current coordinates (sorry 'bout this but they military MGRS ie; 13S CF 1234 5678) draw a circle depicting radar coverage and then draw a series of lines North to South, and West to East to display a grid based on the current location.

The problem is, and I am sure that it will be simple to fix, that I can only draw one line at a time. The circle is redrawn each time, but only one line appears.

The code that I wrote is as follows:

VB.NET:
Private Sub GET_UTM()

        'GET INFORMATION FOR CURRENT LOCATION
        GRID_COORDINATE = Me.tbCURRENT.Text
        GRID_COORDINATE = GRID_COORDINATE.Trim

        '*** 1,000 GRID SQUARE ***
        '***  WEST-EAST ***
        UTM_1 = Val(GRID_COORDINATE.Chars(0))
        UTM_2 = Val(GRID_COORDINATE.Chars(1))
        UTM_WE = UTM_1 & UTM_2
        '***  SOUTH-NORTH ***
        UTM_NS = GRID_COORDINATE.Chars(2)

        '***100K GRID ZONE ***
        '*** WEST-EAST ***
        GRID_COL = GRID_COORDINATE.Chars(4)
        '*** SOUTH-NORTH ***
        GRID_ROW = GRID_COORDINATE.Chars(5)

        '*** EASTING ***
        X_10K = Val(GRID_COORDINATE.Chars(7))
        X_1K = Val(GRID_COORDINATE.Chars(8))
        X_100M = Val(GRID_COORDINATE.Chars(9))
        X_10M = Val(GRID_COORDINATE.Chars(10))

        '*** NORTHING ***
        Y_10K = Val(GRID_COORDINATE.Chars(12))
        Y_1K = Val(GRID_COORDINATE.Chars(13))
        Y_100M = Val(GRID_COORDINATE.Chars(14))
        Y_10M = Val(GRID_COORDINATE.Chars(15))

        '1 PIXEL = 1 KILOMETER

        '**** START POINT LOCATION ****
        'DRAW 10K GRID SQUARES
        'GET X (EAST-WEST)VALUES

        'DETERMINE CENTER OF GRID (832 PIXELS)
        'EACH SQUARE WEST-EAST MEASUREMENT IS 83.2 PIXELS
        'X CENTER LOCATION 348

        'DETERMINE WHERE LEFT BOUNDRY IS LOCATED.
        XG_10M = X_10M * 0.0832
        XG_100M = X_100M * 0.832
        XG_1K = X_1K * 8.32
        X2 = XBase - (XG_10M + XG_100M + XG_1K)


        'FOR NORTH-SOUTH GRID LINES
        '*** X VALUES ***
        'EQUAL: X1 = X2

        'SET VALUES
        X1 = X2
        Y1 = 0
        Y2 = 696
        'SET XBASE TO CURRENT VALUE FOR CALCULATION OF VALUES EAST OF LOCATION
        XBase = X2

        'FILL ARRAY WITH VALUES WEST OF LOCATION
        'FIRST LINE
        Grid.X1 = X1
        Grid.Y1 = Y1
        Grid.X2 = X2
        Grid.Y2 = Y2
        Grid_Data.Add(Grid)

        'LINES WEST OF CURRENT LOCATION

        While X2 > 83.2
            X2 -= 83
            X1 = X2
            Grid.X1 = X1
            Grid.Y1 = Y1
            Grid.X2 = X2
            Grid.Y2 = Y2
            Grid_Data.Add(Grid)
        End While
        Pan_Graph.Refresh()

       End Sub

#End Region

    Private Sub Pan_Graph_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Pan_Graph.Paint

        Dim g As Graphics = e.Graphics

        'DRAWS ARC DEPICTING 40KM RADIUS OF RADAR COVERAGE
        g.DrawArc(p, 166, 98, 500, 500, 0, 360)

        'DRAWS GRID BASED ON COORDINATES OF CURRENT LOCATION
        For Each Grid In Grid_Data
            g.DrawLine(PLINE, X1, Y1, X2, Y2)
        Next

        MyBase.OnPaint(e)



    End Sub
 
The problem is that when you call DrawLine you're passing the same coordinates every time. You're not getting your X and Y values from the current Grid but rather using the member variables.
 
I'm sorry, I didn't think to specify this before when I posted it, it redraws a line in a new location each time I click the button, but it will not draw all the lines in the array.
 
Problem solved

LOL It finally dawned on me right after I posted my last remark, I was not using the array correctly to reassign values to the variables. I took care of that with the following following statements

x1 = Grid.X1
y1 = Grid.Y1
x2 = Grid.X2
y2 = Grid.Y2

Thanks for your help.
 
Back
Top