label wont update text

I have a group of dynamic label controls hosted in a groupbox. I have created event handlers  for dbl click which pops up a dialog box to alter the text property of the control.For some strange reason the change only occurs if I minimise and then maximise the form. ANy ideas

cheers


Answer this question

label wont update text

  • Davve

    My app allows a user to create and store any number of PrintLabel templates for printing barcode labels. When a Plabel is viewed for changes etc I retrieve a set of records for the Plabel which correspond to the data which appears on the Plabel(fields), for each field a label control is created with the properties retrieved from the database ie. xpos,ypos, text, fontsize etc. When changes are made I clear all label controls and recreate them. This was the only solution I could find that would persist the text on the label control.

    Private Sub AddItemLabel(ByRef thisPrintItem As PrintItem, ByVal lblname As String, ByVal LabelText As String, ByVal xpos As Integer, ByVal ypos As Integer, _

    ByVal FontSize As Single, ByVal ID As Integer)

    Dim lblNew As New Label

    Dim obinding As Binding = Nothing

    Dim currentSize As Single

    With lblNew

    .Text = LabelText

    .BorderStyle = BorderStyle.None

    .AutoSize = True

    .BackColor = Color.White

    .BackColor = Color.Transparent

    .Name = lblname

    .Parent = GroupBox1

    .Top = ypos

    .Left = xpos

    .Tag = ID 'allows the printItem to be referenced by ID from the labels Tag property

    currentSize = FontSize 'lblNew.Font.Size

    .Font = New Font(thisPrintItem.FieldFont.ToString, currentSize, .Font.Style)

    If thisPrintItem.FontBold = True Then

    .Font = New System.Drawing.Font(thisPrintItem.FieldFont.ToString, currentSize, FontStyle.Bold)

    Else

    .Font = New System.Drawing.Font(thisPrintItem.FieldFont.ToString, currentSize, FontStyle.Regular)

    End If

    'The following Handlers are linked to "My Dynamic Label EventHandlers"

    AddHandler .Click, AddressOf Label_Click

    AddHandler .MouseDown, AddressOf Label_MouseDown

    AddHandler .MouseUp, AddressOf label_mouseup

    AddHandler .MouseMove, AddressOf Label_MouseMove

    AddHandler .MouseLeave, AddressOf Label_MouseLeave

    AddHandler .DoubleClick, AddressOf Label_DoubleClick

    GroupBox1.Controls.Add(lblNew)

    lblNew.ContextMenu = lblMenu

    lblNew.Visible = True

    End With

    End Sub

    The final stage of the routine that calls the above is to repaint

    Me.InvokePaint(Me, New PaintEventArgs(Me.CreateGraphics(), New Rectangle(0, 0, Me.Width, Me.Height)))

    Hope this clears things up a little


  • abc0918

    Hi kiwicoder2,

    thanks for ur post..

    tell me what is the role of invokepaint what does it actually do

    what i have done now is to update a control, i write

    me.controls.removeat(indexnoofthecontrol)

    and then create a new at the same location..

    but i am still looking for an optimized method..

    Rajesh



  • AndyL

    Have you tried a PerformLayout

  • Helen Cool Granny

    Cheers for all the replys guys. I have resolved the issue by reloading all the controls with updated values from the database.

    Regards
              kev

  • Sébastien Nunes

    Yes refresh is from the dbl click event not the dialog. Got me stumped


  • nickisacrazypirate

    Are you performing the refresh on the form with the label on it (e.g. within the doubleclick event after the dialog is closed)   It should not be called from the dialog unless the dialog has a reference back to the main form.

    Josh

  • Wolfsvein

    Did you try application.doevents()

    --Carl


  • tranders

    There seems to be an issue with the invalidate method because I couldn't get it to work either. It's supposed to cause repainting, but it doesn't.

    Regards,

      Guido

  • Ole Brydensholt

    hi kiwicoder2

    even i am facing the same problem. please tell me how did u resolve by Reloading all the controls.

    How did you reload all the controls

    Regards



  • turnbui

    hi Carl

    thanks for your concern.. i am a beginner, so please explain a little more as to where shud i write application.doevents().

    basically, i have a set of linklabels i initialize, and assign values to, in a function. this function takes as an input, a string variable(URL of an XML file) and reads and fills the labels.

    Now On a button click, i want them to load a similar but different XML file having different values. And want to update the same already created Linklabels.

    So what I did was on the button click event, i invoke the same function and pass a different URL. But nothing is updated.

    One more thing i would like to point is that when I re-invoke the XML read function, the linklabels are again redefined...

    I have tried using me.refresh(), me.activate() but none work.

    I have not created label arrays instead wrote this:

    Dim lbl As LinkLabel

    lbl = New System.Windows.Forms.LinkLabel

    And this code is repeated each time for each node in the XML.

    Hope you understood my problem.. waiting to hear from you :)



  • Deepak Vyas

    A. Rajesh wrote:

    hi Carl

    thanks for your concern.. i am a beginner, so please explain a little more as to where shud i write application.doevents().

    Anywhere you update a label

    label1.text="new info"

    application.doevents()

    I don't know if that will work or not for what you are doing, it was just a suggestion to try it.

    Carl


  • Adam Uebel

    Tried that but it won't work. strange eh

  • levi.rogers

    I'm not 100% sure, but i think calling refresh() will only draw portions marked as dirty.
    If it's not getting marked as dirty, you can specify to redraw the entire form.

    Use



        Me.Invalidate()

     


    or



        Me.InvokePaint(Me, New PaintEventArgs(Me.CreateGraphics(), New Rectangle(0, 0, Me.Width, Me.Height)))

     



    Dustin.


  • Neotech

    You need to repaint the screen after closing the dialog box ...

    <form_name>.Refresh
    or
    me.Refresh (if refreshing from within the code of the form)

    Hope this helps,
    Josh Lindenmuth



  • label wont update text