Panel [Form->panel] is loaded 2 times

Jelmer

Regular
Joined
Jan 11, 2006
Messages
96
Hello Programmers

I've build a pretty nice program.
Everything works rigth but 1 panel is loaded 2 times, that looks stupid.
Everything gets build up. and its broken and loaded again. Then its good.

How can i handel that?
My code:

Code:
        private void listBar1_ItemClicked(object sender, vbAccelerator.Components.ListBarControl.ItemClickedEventArgs e)
        {
            if (e.MouseButton == MouseButtons.Left)
            {
                panel3.Controls.Clear();
                if (e.Item.IconIndex == 0)
                {                    
                    NieuwFactuur myCtrl = new NieuwFactuur();
                    panel3.Controls.Add(myCtrl);
                }
            }
        }
 
I really have no idea what your looking for here? Using an objects .SuspendLayout and .ResumeLayout you can prevent flickering of controls. You call .SuspendLayout before removing/adding anything, then .ResumeLayout when everthing is added/removed. Does this help?
 
Sorry for my late post...

I tried it .. but it doesn't help.
The code is placed on the click tap of the listbar.

That code is loaded 2 times:

Code:
        private void listBar1_ItemClicked(object sender, vbAccelerator.Components.ListBarControl.ItemClickedEventArgs e)
        {
            if (e.MouseButton == MouseButtons.Left)
            {
                panel3.Controls.Clear();
                if (e.Item.IconIndex == 0)
                {                    
                    NieuwFactuur myCtrl = new NieuwFactuur();
                    myCtrl.SuspendLayout();
                    MessageBox.Show("1");
                    panel3.Controls.Add(myCtrl);
                    myCtrl.ResumeLayout();
                }
                else if (e.Item.IconIndex == 1) 
                {
                    ZoekFactuur myCtrl = new ZoekFactuur();
                    MessageBox.Show("2");
                    panel3.Controls.Add(myCtrl);
                }
            }
        }

If the e.item.iconindex ==0 then i get 2 times on the screen: "1".
Thats the error.

This piece:

Code:
                    NieuwFactuur myCtrl = new NieuwFactuur();
                    myCtrl.SuspendLayout();
                    MessageBox.Show("1");
                    panel3.Controls.Add(myCtrl);
                    myCtrl.ResumeLayout();

Needs to be loaded 1 time!
The susprendlayout doesnt help much in this case ;)
 
Is it possible that the event handler is being attatched to the event twice? Probably not likely, but I'll throw it out there.
 
Not possible.. is only activated by the click of the mouse...
I build it so:

Code:
        private void listBar1_ItemClicked(object sender, vbAccelerator.Components.ListBarControl.ItemClickedEventArgs e)
        {
            if (kliktel == 0)
            {
                if (e.MouseButton == MouseButtons.Left)
                {
                    panel3.Controls.Clear();
                    if (e.Item.IconIndex == 0)
                    {
                        NieuwFactuur myCtrl = new NieuwFactuur();
                        myCtrl.SuspendLayout();
                        panel3.Controls.Add(myCtrl);
                        myCtrl.ResumeLayout();
                    }
                    else if (e.Item.IconIndex == 1)
                    {
                        ZoekFactuur myCtrl = new ZoekFactuur();
                        panel3.Controls.Add(myCtrl);
                    }
                    kliktel = kliktel + 1;
                }
            }
        }

The kliktel is a variable.
On the first its 0, after 1 run it gets 1.

But how can i get it back to 0 again???

Its working, but only 1 time .. so you can't press another button
 
Now that I've looked at the code more closely, it definitely seems like the event handler is attatched twice. That you need a variable to count the number of times the handler is called and only run the code the first time shows that the code is being run twice per click (which means the handler must be attatched twice).

How do you attatch the event to the handler? Through the designer? In code? Or both?
 
here is a package with some components, i 'borrowed' from.
So this is not my official project.

the click event is on one of the objects on the left side.
I don't see it...
 

Attachments

Last edited by a moderator:
Back
Top