5

I have a form with two custom panels and I'm adding some labels to them and in the end i want they to scroll from the right to the left but they are just stucking in the same position. There is a screenshot of what i have enter image description here There are two panels and the 4 labels and they just stay stuck in there... This is the code in my form:

  private MyPanel topPanel;  // the red bar
  private MyPanel botPanel;  // the white bar

        public SmsBar()
    {
        InitializeComponent();

        this.Width = 500000;

        this.Location = new Point(x, y);
 
        topPanel = new MyPanel(System.Drawing.Color.White, System.Drawing.Color.Red, (new Font("Tahoma", 10, FontStyle.Bold)));
        botPanel = new MyPanel(System.Drawing.Color.Black, System.Drawing.Color.White, (new Font("Tohama", 10, FontStyle.Regular)));

        msgPanel.Controls.Add(topPanel);
        adPanel.Controls.Add(botPanel);
        botPanel.addMsg(new MsgForDisplay(0, AppData.getInstance().getAdMsg()));
        botPanel.addMsg(new MsgForDisplay(0, AppData.getInstance().getAdMsg2()));

        topPanel.addMsg(new MsgForDisplay(0, "test top"));
        topPanel.addMsg(new MsgForDisplay(0, "test top 2"));

        adPanel.Refresh();
        msgPanel.Refresh();
  
    }

And there is some code of my custom panel (Constructor):

  public MyPanel(Color corLabel, Color back, Font text){
    this.color = corLabel;
    this.backg = back;
    this.textFont = text;
    this.Width = 500000;

    txt= new LinkedList<string>();
    msgs = new LinkedList<MsgForDisplay>();
    labels = new LinkedList<Label>();
    var it = labels.GetEnumerator();
    var it2 = msgToRemove.GetEnumerator();

    this.FlowDirection = FlowDirection.LeftToRight;
    this.BackColor = backg;
    this.Size = new Size(500000, 35);
    this.Refresh();
 
    }

The running:

         public void run() {

         while (true) {
             
              var it = labels.GetEnumerator();
                while(it.MoveNext()){
               Label lb = it.Current;

                    if (lb.Location.X + lb.Width < 0) {

                        if (msgsRemover.Contains(lb.Text.ToString())) {
                            labels.Remove(lb);
                            this.Invoke(new MethodInvoker(() => { this.Controls.Remove(lb); }));
                            msgsRemover.Remove(lb.Text.ToString());
                        } else {
                            // if there is no message to be removed, they will just continue
                            // going to the end of the queue
                            this.Invoke(new MethodInvoker(() => { this.Controls.Remove(lb); }));
                            this.Invoke(new MethodInvoker(() => { this.Controls.Add(lb); }));

                        }
                        this.Invoke(new MethodInvoker(() => { this.Refresh(); }));

                    }
                    
                    this.Invoke(new MethodInvoker(() => { lb.Location = new Point(lb.Location.X - 3, lb.Location.Y); }));
             
             }

             System.Threading.Thread.Sleep(30);

         }
     
     }

And the addMsg function:

      public void addMsg(MsgForDisplay msg) {
        Label lbl = new Label();
        lbl.Text = ("- " + msg.getText() + " -");
        lbl.ForeColor = color;
        lbl.Font = textFont;
        lbl.BackColor = backg;
        lbl.Visible = true;
        lbl.AutoSize = true;
        labels.AddLast(lbl);
        this.Controls.Add(lbl);
    }

I guess that the problem must be with the layouts but I doesn't really know what I should use... Thank you in advance for the help!

Community
  • 1
  • 1
João Silva
  • 531
  • 4
  • 21
  • 40
  • The FlowLayoutPanel handles the location of the child controls for you. If you want to move the labels in a marque style, you will have to use just a regular panel and handle the location properties yourself. Consider using a timer instead of that `while (true)` loop. – LarsTech Nov 22 '13 at 13:39

3 Answers3

1

If I am properly understood your problem is.. The Label moves from right to left and then stuck in the Left side.

You are removing and adding the control. But it will not reset the controls position. You need to set Control.Location.X to 800 or some value, just before adding it again.

Rajan Panneer Selvam
  • 1,279
  • 10
  • 24
  • They are starting at that position, they didn't move at all, i also tried change **lb.Location.X** to **+3** but they still stucked, **MyPanel** is a **FlowLayoutPanel**, maybe that might be the problem but I'm not sure – João Silva Nov 21 '13 at 12:34
1

For solve this i removed the flowlayout and let the panel as a panel and not as a FlowLayoutPanel, that way I was able to move the labels, the diference is that i had to create an algorithm to add each label in the panel.

João Silva
  • 531
  • 4
  • 21
  • 40
0

@João Silva : Just to Remind... C# is server side and when you view the page it is at client side. (If you are speaking about ASP.NET)

  1. When ever you wish to get the effects / animation there are only two ways to achieve it.
    A. Use CSS3
    B. Use JQuery or Javascript accordingly.

Note: Jquery plugins are generally of light weight and that will be better in terms of performance too.

let me know if you need a solution I will try to write some sample for you

Reference link to verify if that is what you need:
Documentation and Source : http://remysharp.com/2008/09/10/the-silky-smooth-marquee/
Demo : http://remysharp.com/demo/marquee.html

Venkatesh Ellur
  • 158
  • 1
  • 10
  • Yes, it's not related to web, this is a application for run in a computer and display messages in another monitor... – João Silva Nov 28 '13 at 16:21