having a couple of problems with Windown Forms

Started by
13 comments, last by Manhattanisgr8 10 years, 3 months ago

How would I go around this? I tried to implement your second example, however, instead of setting the list, I tried to set the visibility of another panel, and that didn't work.


control1.ButtonClicked += delegate { control3.SetList(list1); }; control2.ButtonClicked += delegate { control3.SetList(list2); };

Cpl Alt, Travis A

USMC

Advertisement
Did you fix the things that I suggested? Or do you need to know exactly which lines to change?

If you've fixed them yourself, then I see another problem that will prevent the program from working nicely:


this.Controls.Add(panel1);
this.Controls.Add(listboxPanel);
this.Controls.Add(addItems);
That adds the controls, but you haven't set their position!

By default, the position of a control is 0,0 - the upper left corner of the control or form that contains it. Also, UserControls have a default size of 100x100 when you make them in the form designer.

So, my guess is that all of your panels are overlapping on top of each other right now, which will make it hard to tell if any of them are actually changing visibility or not.

In my examples, you can see that in a few places I set the Left, Top and sometimes the Width and Height of certain things. I've done this to make sure that they aren't placed on top of each other.

Left is the X position of the left edge of a control, relative to its parent. You can set this.
Top is the Y position of the top edge of a control, relative to its parent. You can set this.

"Parent" in this case means the control or form that you've added it to. In fact, 'Parent' is an actual property of controls that you can use in your code.

Right and Bottom are read-only. You can get their values but you can't set them.

Width and Height can be set. When you change them, Right and Bottom will reflect the changes.
Which lines do I change? All the initializing of the buttons are in the classxx.deigner.cs portion of the panel.

Cpl Alt, Travis A

USMC

You're going to need to learn how to figure this stuff out on your own. Perhaps find a good WinForms-in-C# book. But here are the lines you need to change:

In Form1:

//panel1.Link = listboxPanel.Link;
panel1.Link = listboxPanel;
In Panel1:

//public Panel1 Link;
public ListboxPanel Link;
In ListboxPanel:

//public ListboxPanel Link;
public Panel1 Link;
In AddItemsPanel:


//public AddItems Link;
// I have no idea what you're planning to do with this.
Your compiler has been giving you helpful error messages so far, which you need to learn how to understand. If you don't understand an error, type in its "error CS####" code into google for a more detailed explanation. This should help you to figure out what the error means, and sometimes the results will contain examples showing what's wrong and how to fix it. You can find the "error CS####" in the "Output" window of Visual Studio (They are not shown in the Error List window.)

Both the compiler and I have already explained several times why these need to be changed. I may hang around for a little while longer but I think you need to find someone with more patience than I have to help you out.

I figured it out, thank you for your help and patience.

Cpl Alt, Travis A

USMC

This topic is closed to new replies.

Advertisement