Anchoring issue.

B

BennyEz

Lets say I have a control at the bottom of my form and I have it set
to anchor Top, Bottom, Left, Right

That does exactly what I want it to do....

Ok here's my issue. I have recently taken the contents from that form
and placed them on a user control instead. I set the output type to
dll for the project with the user control. I implement my own
interface, compile, and then place the dll in a plugins directory of
my host app. My host app then rakes the directory, finds any types
that implement the interface and when it finds one it loads that user
control as a new tab in the host apps tab control.

The interface requires that there be an init function. The host always
runs this when it finds the dll and passes in DB information. Inside
the init function I have tried to also set the user controls anchor
like so:

this.Anchor = ((System.Windows.Forms.AnchorStyles)
((((System.Windows.Forms.AnchorStyles.Top |
System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));

I'm not sure if the syntax is 100% in this posting because I've
commented and uncommented and recommented so many times trying
different combinations. Just know that I'm setting it the same as if I
were using the designer. Top, Bottom, Left, Right...

Now the Host app has a tab control as I've already stated. It has it's
anchor set to Top, Bottom, Left, Right so that it expands if the form
does.

Now when it loads, everything runs off the screen. So let me lay out
the context more clearly:

Host Form
- Tab control - Anchor Top, Bottom, Left, Right
- User Control found at runtime - Anchor Top, Bottom, Left, Right
- Control - anchro Top, Bottom, Left, Right

I can create the same app with just a tab control and place the end
control right on a new tab page and anchor it. That works as expected
and everything expands as it should. but once I put the control on a
user control and then load that dynamically into the tab control
setting it's anchor, everything expands way off to the right and
bottom.

Any help would be great!!!!!!!!!!!!!!!!!!!!!!
 
B

BennyEz

All,

Somtimes detailing the problem out for others is all it takes to
figure it out on your own.. My problem was that my host app was
calling the user control's init function (which set the anchor) before
the user control was added to a tab page on the host. Without a parent
it had nothing to base those anchors on... So to correct my problem, I
moved the anchor code from the user control's init function into the
host. Now I have:

FoundInterface = tp.GetInterface("IPlugin");
if (FoundInterface != null)
{
GenericInstance = asmAssembly.CreateInstance(tp.FullName);
newControl = (Extensibility.IPlugin)GenericInstance;
newControl.Init(DBPath.ToString(), UserID, ref mainMenu1);
tabPage = new TabPage(newControl.PluginName);
tabPage.AutoScroll = true;
tabPage.Controls.Add((Control)newControl);
tabPage.Controls[0].Anchor =
((System.Windows.Forms.AnchorStyles)
((((System.Windows.Forms.AnchorStyles.Top |
System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
tabControl1.TabPages.Add(tabPage);
}


So I add the plugin to the tabPage and then I set it's anchor. Works
like a charm.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top