Jelmer Posted August 15, 2006 Posted August 15, 2006 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: 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); } } } Quote
Cags Posted August 15, 2006 Posted August 15, 2006 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? Quote Anybody looking for a graduate programmer (Midlands, England)?
Jelmer Posted August 18, 2006 Author Posted August 18, 2006 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: 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: 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 ;) Quote
Leaders snarfblam Posted August 18, 2006 Leaders Posted August 18, 2006 Is it possible that the event handler is being attatched to the event twice? Probably not likely, but I'll throw it out there. Quote [sIGPIC]e[/sIGPIC]
Jelmer Posted August 19, 2006 Author Posted August 19, 2006 Not possible.. is only activated by the click of the mouse... I build it so: 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 Quote
Leaders snarfblam Posted August 19, 2006 Leaders Posted August 19, 2006 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? Quote [sIGPIC]e[/sIGPIC]
Jelmer Posted August 19, 2006 Author Posted August 19, 2006 (edited) 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...listbar.zip Edited August 19, 2006 by PlausiblyDamp Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.