How to clear image control?

Discussion in 'Questions (Windows Mobile)' started by RB Smissaert, Dec 27, 2008.

  1. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Maybe a simple one, but I can't see it:
    I have a form with on it a simple image control.
    On that image control I draw lines with Graham's chart dll.
    When I have seen the chart I close the form and I thought that that would
    clear the image, but it doesn't, so when I make a new chart and load the form
    again I see the old chart plus the new one.

    This is the relevant code section:

    LineChart.New1(imgChart.Width, imgChart.Height)
    LineChart.Text = strTerm
    LineChart.Color = Rgb(255,255,230)
    LineChart.MaxScaleValue = dMaxValue
    LineChart.MinScaleValue = dMinValue 'no effect with positive values
    LineChart.ShowGrid = True
    LineChart.AddXAxisText(1, 80, strMinDate)
    LineChart.AddXAxisText(160, imgChart.Width - 1, strMaxDate)
    LineChart.XAxisIntervalValue = 240 'to avoid any ticks on the X-axis

    dXAxisFactor = (lMaxDate - lMinDate) / imgChart.Width

    LineChart.NewLine(cRed)

    For n = 0 To lRecords - 1
    'the + 1 and - 1 x-axis adjustments are to prevent
    'these values falling of the image on the device
    '-------------------------------------------------
    If n = 0 Then
    LineChart.AddPoint(1, ArrayListValues1.Item(n))
    Else
    If n < lRecords - 1 Then
    LineChart.AddPoint(Int((ArrayListDateTicks.Item(n) - lMinDate) / dXAxisFactor), _
    ArrayListValues1.Item(n))
    Else
    LineChart.AddPoint(imgChart.Width - 1, ArrayListValues1.Item(n))
    End If
    End If
    Next n

    Linechart.LineWidth = 1
    LineChart.AddLine

    imgChart.Image = LineChart.Draw
    frmChart.Show



    The arraylists are cleared before adding new values (from a SQLite Reader) and they are not the problem.
    Thanks again for any advice.

    RBS
     
  2. agraham

    agraham Expert Licensed User

    This line assigns a new Bitmap ,with the chart drawn on it, to the Image property of the Image control. I can't see how the old Bitmap could still be visible. Are you doing "LineChart.New1(imgChart.Width, imgChart.Height)" the second time around? This is needed to clear the LineChart or you will get the old data redrawn.
     
  3. taximania

    taximania Well-Known Member Licensed User

    OT:
    When posting code, highlight the code text in the input window and click the # icon above it.
    This adds the code tag, and makes your post a bit more readable. eg.

    Code:
    Sub Globals
       
    'Declare the global variables here.

    End Sub

    Sub App_Start
       Form1.Show
    End Sub
    Sorry for grumbling, grovel, grovel :)
     
  4. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    > Are you doing "LineChart.New1(imgChart.Width, imgChart.Height)" the second time around?

    Yes, that runs every time. Just tested it to make sure.
    I must be overlooking something simple here.
    I have attached the full code of this Sub as a zipped text file.

    RBS
     
  5. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Ah, yes; thanks for the tip.
    Will do that from now on.

    RBS
     
  6. taximania

    taximania Well-Known Member Licensed User

    I'm sorry if I sounded a bit harsh :sign0188:
     
  7. agraham

    agraham Expert Licensed User

    You are making things unnecessarily complicated. Just post the sbp file then I can run it directly otherwise I have to prat around recreating all the objects etc. and I have too much to do to waste time redoing what you have already done :(
     
  8. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    OK, attached the source file. Bear in mind that you can't run it as you haven't got the SQLite db file. This is a very large file, but if you need it then I can make a small one and post that.

    RBS
     
  9. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Not at all; I just hadn't looked at the icons.

    RBS
     
  10. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    All solved.:)
    This was a simple and plain bug in my code and sorry to cause and wasted time anywhere.:signOops:
    I have 4 arraylists and they all need clearing before the next chart is made, but I had forgotten to clear ArrayListDateTicks.
    Once that was done all was fine.

    RBS
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice