MSDN > Home page del forum > Windows Forms General > Do not refresh User Control
Formula una domandaFormula una domanda
 

Con rispostaDo not refresh User Control

  • mercoledì 4 novembre 2009 20.44Codeeater Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Contiene codice
    Hey,

    Is it possible to command a user control to not refresh unless called by code written by me? This is because I have a User Control called a DateBar, which has many child User Controls called Tasks and another child User Control called an ArrowPanel. When the date bar is refreshed, first I want it to refresh itself, then the Tasks, and finally the ArrowPanel. It has to be in this order, but it currently is not doing that. I also think that the problem may lie in the fact that the ArrowPanel contains the following code:

     protected override CreateParams CreateParams
            {
                get
                {
                    CreateParams cp = base.CreateParams;
                    cp.ExStyle |= 0x00000020;//WS_EX_TRANSPARENT 
                    return cp;
                }
            }
    
            protected override void OnPaintBackground(PaintEventArgs e)
            {
                Color bk = Color.FromArgb(0, this.BackColor);
                e.Graphics.FillRectangle(new SolidBrush(bk), e.ClipRectangle);
            }
    
    From what I gather, when this code is executed, it redraws the parent control, and thus the Tasks (although I'm not sure). Also making it very slow.

    Is there anyway around this?

    To explain what the ArrowPanel is doing: It is basically there to be ontop of all of the Tasks so that it can be passed coordinates between which to draw lines. So, it makes itself "transparent" using the code above. I was wondering if instead, what would be better, would be if I were to use Windows API or something like that to draw the lines ontop of the form rather than on a UserControl.

    Thanks very much and any input is much appreciated,,,

    Matt
    • SpostatoTaylorMichaelLMVPgiovedì 5 novembre 2009 18.49WinForms related (From:Visual C# General)
    •  

Risposte

  • mercoledì 4 novembre 2009 20.56BigTuna99 Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con risposta
    this.SuspendLayout()

    then when you want it to paint again

    this.ResumeLayout(true)



    If this answers your question, please mark the question as answered.
  • martedì 10 novembre 2009 19.15Rudedog2 Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con risposta
    Not certain what you are after.
    You can draw on one object at a time.  That's how it works.
    Overlay something over the form and draw on that.  Looks and appearance is all that matters.

    Mark the best replies as answers. "Fooling computers since 1971."

Tutte le risposte

  • mercoledì 4 novembre 2009 20.56BigTuna99 Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con risposta
    this.SuspendLayout()

    then when you want it to paint again

    this.ResumeLayout(true)



    If this answers your question, please mark the question as answered.
  • giovedì 5 novembre 2009 18.07Codeeater Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Thanks,,, if I say this.SuspendLayout(), can I then say this.refresh() and have it refresh without saying this.ResumeLayout(true)?

    thanks,,,

    Matt
  • giovedì 5 novembre 2009 18.10BigTuna99 Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Nope.  Calling SuspendLayout does just that, it ignores all calls to Refresh until you call ResumeLayout.



    If this answers your question, please mark the question as answered.
  • lunedì 9 novembre 2009 18.05Codeeater Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Ok,,, well I don't think that this is the method that I would like to pursue as I think that it makes it overly complicated. Is there anyway that I could make the DateBar draw over its children? Or is there anyway that I can easily draw over the top of DateBar and its children without using a UserControl?

    Thanks,,,

    Matt
  • lunedì 9 novembre 2009 19.38Rudedog2 Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Why don't you just call the methods explicitly on the controls you want in the order that you want?

    Sorry, I would love to answer stuff about your custom control, but we just don't know enough about it.

    Mark the best replies as answers. "Fooling computers since 1971."
  • martedì 10 novembre 2009 18.06Codeeater Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Ok, thanks,,,

    But just out of interest, is there anyway that I can draw on top of all the controls on a form?

    Thanks,,,

    Matt
  • martedì 10 novembre 2009 19.15Rudedog2 Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con risposta
    Not certain what you are after.
    You can draw on one object at a time.  That's how it works.
    Overlay something over the form and draw on that.  Looks and appearance is all that matters.

    Mark the best replies as answers. "Fooling computers since 1971."
  • giovedì 12 novembre 2009 22.54Codeeater Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Ok,,, I was thinking along the lines of ControlPaint. Because that allows you to draw anywhere on the screen (even outside the form). I wanted somehing like this but I can only draw in th selected form. Is this not possible, thanks,,, Matt ps I fixed th original problem. Wasn't what I thought it was. Thanks for the help anyway :)