StrataFrame Forum

Security Sample question.

http://forum.strataframe.net/Topic15590.aspx

By Ross L. Rooker, Sr. - 4/14/2008

Your SecuritySample (C#) displays the main form for the app (SecurityMain) which has a flow panel to the left (pnlSide)with a themed container (ThemedContainer1). I like this approach but have a question. I want to expand on this some that when the Customers button the the SecurityMain form is clicked and the CustomerMaintenance form appears, it would dynamically add another ThemedContainer2 to the SecurityMain form's pnlSide area.

First I added a user control called CustomerMaintenanceThemedContainer which inherited from the Strataframe Themed Container. and used the Visual Designer to get it the same with, look and feel as the one already on the SecurityMain form.

My thought is to add a ThemedContainer to the pnlSide area of the SecurityMain form whenever I display another form such as the CustomerMaintenance form to give the user other information or links they could click on for the form.

When the CustomerMaintenance form first displays, what code would I need to add the Themed Container to the pnlSide area of the SecurityMain form? And then when the user CLOSES the CustomerMaintenance form, what code would be needed to removed the Themed Container from the pnlSide area on the SecurityMain form?

I added the following code on the button click of the cmdCustomers button on the SecurityMain form which does work, but this should happen as a part of the CustomerMaintenance form and not the button click on the SecurityMain form. Valet is my namespace for my application. My question is how do I get a reference to the SecurityMain form once the CustomerMaintenance form is displayed so that I can control the displaying of the associated Themed Container and removing it from the CustomerMaintenance form?

Valet.frmCustomerMaintenanceUserThemedContainer ThemedContainer2 = new frmCustomerMaintenanceUserThemedContainer();

this.pnlSide.Controls.Add(ThemedContainer2);

LaunchForm(typeof(frmCustomersMaintenance));

By Trent L. Taylor - 4/14/2008

OK...a couple of things.  You don't want to re-write this code over and over again so this logic should be placed in your BaseForm.  All of your maintenance forms will inherit your BaseForm which inherits from our StandardForm:

Public Class MyBaseForm
    Inherits MicroFour.StrataFrame.UI.Windows.Forms.StandardForm
End Class

Next, you will probably just always allow that themed container to be on the side panel, just change its visibility and place it as well as any other items in a FlowLayoutPanel.  This way when you change their sizes and visibilities the other controls will automatically adjust themselves in respect to the controls being changed.

Finally you will need to create a shared reference to that object and/or create a shared event that is managed by application.  You can go a lot of different ways on the event in regards to who manages what.  For example, you could create a shared event that the ThemedContainerClass that will be in the panel manages.  Conversly you could create an event that is managed by the form which forces the logic to execute.  If you just want to go down the object route, then create a shared reference to the themed continer and then in your base form add your logic:

Public NotInheritable Class MyBasics
    Private _PanelContainer As ThemedContainer

    Public Property SidePanelContainer as ThemedContainer
        Get
              Return _PanelContainer
        End Get
        Set(Byval value as ThemedContainer)
              _PanelContainer = value
        End Set
    End Property
End Class

Set this property in your application once the object has been created.  It could be in the panel itself it necessary:

MyBasics.SidePanelContainer = Me

Finally, add your logic in your base form to update the container:

Overrides Protected Sub OnLoad(...)
    MyBase.OnLoad(...)
    MyBasics.SidePanelContainer.Visible = True
End Sub

Overrides Protected Sub OnFormClosing(...)
    '-- Add your logic to see if the container should be removed
    MyBasics.SidePanelContainer.Visible = False

   MyBase.OnFormClosing(...)
End Sub

By Ross L. Rooker, Sr. - 4/14/2008

The reason I did not want to add the themed container to the side panel and set it's visible property is because eventually there will be 100 different forms, each with a different themedContainer to appear only when that form is displayed. By adding it to the side panel and removing it, we will not have to set all them up on the main form and toggle the visibility property.

The main form is SecurityMain. The flow panel on it is called "pnlSide". The themed container when the CustomerMaintenance form displays should be added to the pnlSide controls object on the SecurityMain form. I am using the example that came with Strataframe. Based on this, would the "base form" be the SecurityMain form, or the CustomerMaintenance form?

How do I get a reference to the pnlSide object on the SecurityMain form when the CustomerMaintenance form is displayed?
 

By Trent L. Taylor - 4/14/2008

it's visible property is because eventually there will be 100 different forms, each with a different themedContainer to appear only when that form is displayed. By adding it to the side panel and removing it, we will not have to set all them up on the main form and toggle the visibility property.

I wouldn't take that approach.  The more objects that you are planning on using creates a much larger margin of error.  You are better off creating a reusable solution.  This is what we do in our medical software.  We place a ThemedLinkMenu on the left side and then update the control from a collection on the BaseForm.  So the same control is reused for all forms.  If you have more than one form up and select another form, it automatically updates the control to work with the selected form, etc.

would the "base form" be the SecurityMain form, or the CustomerMaintenance form?

BaseForm would be what the CustomerMaintenance form would inherit.

How do I get a reference to the pnlSide object on the SecurityMain form when the CustomerMaintenance form is displayed?

me.ParentForm
By Ross L. Rooker, Sr. - 4/14/2008

The main form is SecurityMain. The flow panel on it is called "pnlSide". The themed container when the CustomerMaintenance form displays should be added to the pnlSide controls object on the SecurityMain form. I am using the example that came with Strataframe. Based on this, would the "base form" be the SecurityMain form, or the CustomerMaintenance form?

How do I get a reference to the pnlSide object on the SecurityMain form when the CustomerMaintenance form is displayed?

When I go into the CustomerMaintenance form and type: this.ParentForm.  <---- none of the objects from the parent form (SecurityMain) display in the intellisence... ie... the pnlSide object. Is there a way to get this type of reference?

By Trent L. Taylor - 4/14/2008

Is there a way to get this type of reference?

It is probably declared as a private.  Make sure that the pnlSide is declared as a Friend or Public.  If you can't get it working I will look at the sample tomorrow.

By Ross L. Rooker, Sr. - 4/14/2008

Here was what I had to do which seems to work perfectly: My namespace is called Valet.

Based on my main form being called frmMain rather than SecurityMain and the CustomerMaintenance form being called from a button in the toolbar on the frmMain for here is all that was needed:

First created a user control for a themedContainer for the CustomerMaintance form. I called it frmCustomerMaintenanceUserThemedContainer. My thought that although the width would be consistent with the other themedContained in the pnlSide bar on the frmMain for (your SecurityMain form) it could vary greatly with each form called by the frmMain form.

For each form called by the frmMain form, "CustomerMaintenance" as in this example, I had to add the following code:

protected override void OnLoad(EventArgs e)

{

base.OnLoad(e);

Valet.frmCustomerMaintenanceUserThemedContainer ThemedContainerCustomerMaintenance = new frmCustomerMaintenanceUserThemedContainer();

((Valet.frmMain)(this.Parent.TopLevelControl)).pnlSide.Controls.Add(ThemedContainerCustomerMaintenance);

}

protected override void OnFormClosing(FormClosingEventArgs e)

{

((Valet.frmMain)(this.Parent.TopLevelControl)).pnlSide.Controls.RemoveAt(1);

base.OnFormClosing(e);

}

This seems to works flawlessly for me. And it seems quick.

I still need to do some work on the OnFormClosing rather than assume that RemoveAt should be the  done at RemoveAt(1) but need to locate the exact control to eliminate.

I also had to public the frmMain form.