﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » WinForms (How do I?)  » MDIChildred collection and security</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 15 Sep 2026 22:24:01 GMT</lastBuildDate><ttl>20</ttl><item><title>MDIChildred collection and security</title><link>http://forum.strataframe.net/FindPost15727.aspx</link><description>Scenario:&lt;br&gt;
MDI application where in my launchform method I have:&lt;br&gt;
&lt;br&gt;
[code]&lt;br&gt;
   Private Sub LaunchForm(ByVal FormType As System.Type)&lt;br&gt;
        '-- Establish Locals&lt;br&gt;
&lt;br&gt;
        For Each f As Form In Me.MdiChildren&lt;br&gt;
            If Not String.IsNullOrEmpty(f.Name) Then&lt;br&gt;
                If f.Name.ToUpper = FormType.Name.ToUpper Then&lt;br&gt;
                    MessageBox.Show("Form """ &amp; f.Text.Trim() &amp; """ already running.")&lt;br&gt;
                    Exit Sub&lt;br&gt;
                End If&lt;br&gt;
            End If&lt;br&gt;
        Next&lt;br&gt;
&lt;br&gt;
        Dim loForm As Form&lt;br&gt;
&lt;br&gt;
        '-- Create the form&lt;br&gt;
        Try&lt;br&gt;
&lt;br&gt;
            loForm = CType(Activator.CreateInstance(FormType), Form)&lt;br&gt;
&lt;br&gt;
            '-- Set the MDI parent&lt;br&gt;
            loForm.MdiParent = Me&lt;br&gt;
&lt;br&gt;
            '-- Add a handler to the form close&lt;br&gt;
            ' AddHandler loForm.FormClosed, AddressOf HandlefFormClosed&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
            '-- Show the form&lt;br&gt;
            loForm.Show()&lt;br&gt;
        Catch ex As Exception&lt;br&gt;
            MessageBox.Show(ex.Message)&lt;br&gt;
        End Try&lt;br&gt;
&lt;br&gt;
    End Sub&lt;br&gt;
[/code]&lt;br&gt;
&lt;br&gt;
As we do not want users to be able to launch the same form twice.  This works well except when a user does not have access to a form based on the ViewSecurityKey and then another user signs in after a call to SessionLock.LockSession using F11 - this new user may have access to the same form the other user did not, but when they try to launch it it says it's already running because its still in the MDIChildren collection even though it is not visible anymore - So, when a user gets "access denied" what really happens to the form as it doesn't appear to completely get released.&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
Randy</description><pubDate>Thu, 17 Apr 2008 16:52:38 GMT</pubDate><dc:creator>Randy Jean</dc:creator></item><item><title>RE: MDIChildred collection and security</title><link>http://forum.strataframe.net/FindPost15750.aspx</link><description>It depends on how you have your IDE setup to copy from the code &amp;#119;indow.&amp;nbsp; However, the CodeSnippet tag just strips formatting with a PRE tag so that we don't have other tags bring down the forum...this happened a while back.</description><pubDate>Thu, 17 Apr 2008 16:52:38 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: MDIChildred collection and security</title><link>http://forum.strataframe.net/FindPost15748.aspx</link><description>Thanks Edhy.  OK, I figured out how to test the ViewSecurityKey in a generic way before showing the form.  Its working great!  Any thoughts on if there is a better way are appreciated.&lt;br&gt;
&lt;br&gt;
[codesnippet]&lt;br&gt;
loForm = CType(Activator.CreateInstance(FormType), Form)&lt;br&gt;
If TypeOf loForm Is MicroFour.StrataFrame.UI.Windows.Forms.StandardForm Then&lt;br&gt;
    If SecurityBasics.CurrentUser.GetPermission(CType(loForm, _&lt;br&gt;
        MicroFour.StrataFrame.UI.Windows.Forms.StandardForm).ViewSecurityKey.Trim()).Action = _&lt;br&gt;
        PermissionAction.Deny Then&lt;br&gt;
&lt;br&gt;
         MessageBox.Show("Access Denied", "Access has been denied to " &amp; loForm.Text.Trim() &amp; ".", _&lt;br&gt;
              MessageBoxButtons.OK, MessageBoxIcon.Stop)&lt;br&gt;
         Exit Sub&lt;br&gt;
     End If&lt;br&gt;
End If&lt;br&gt;
[/codesnippet]&lt;br&gt;
&lt;br&gt;
Still can't figure out why my code looks so bad when I copy/paste.  I'm using the codesnippet tags now.</description><pubDate>Thu, 17 Apr 2008 16:27:58 GMT</pubDate><dc:creator>Randy Jean</dc:creator></item><item><title>RE: MDIChildred collection and security</title><link>http://forum.strataframe.net/FindPost15745.aspx</link><description>[quote][b]Randy Jean (04/17/2008)[/b][hr]&lt;BR&gt;So, my other question is: how the heck do I put code in here so it still looks like code with coloring, etc. I just used the code tag but obviously that didn't work well...&lt;BR&gt;[/quote] &lt;P&gt;Use the [codesnippet][/codesnippet] link from the left of the message panel and for the tabs I manually add 5 spaces to format it nicely:D.&amp;nbsp; I copy the code from the VS IDE and that is pasted here with the colors.</description><pubDate>Thu, 17 Apr 2008 16:15:50 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: MDIChildred collection and security</title><link>http://forum.strataframe.net/FindPost15744.aspx</link><description>Thanks Edhy, &lt;br&gt;
This may be something I can use.  I originally was not displaying a message but they asked for a message saying form was already running.  But bringing it to front makes sense if you're not displaying a message.  &lt;br&gt;
&lt;br&gt;
So, I'm still trying to figure out how to generically check the security on a form before I show it.  Seems I can check the specific permission if I know its name but I hate hard-coding that somewhere.  I think the ViewSecurityKey is a hidden/private property.&lt;br&gt;
&lt;br&gt;
So, my other question is: how the heck do I put code in here so it still looks like code with coloring, etc.  I just used the code tag but obviously that didn't work well...&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
Randy</description><pubDate>Thu, 17 Apr 2008 16:09:49 GMT</pubDate><dc:creator>Randy Jean</dc:creator></item><item><title>RE: MDIChildred collection and security</title><link>http://forum.strataframe.net/FindPost15742.aspx</link><description>Hi Randy,&lt;P&gt;I use a different version of the LaunchForm which check if the form exist in the MDI collection and then will bring it to front, it may help you out in your situation, but I am not sure :hehe:&lt;/P&gt;&lt;P&gt;[codesnippet]&lt;FONT size=2&gt;&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Private&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/FONT&gt;&lt;FONT size=2&gt; LaunchForm(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ByVal&lt;/FONT&gt;&lt;FONT size=2&gt; FormType &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; System.Type)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Establish Locals&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; loForm &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; Form&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Create the form&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;loForm = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;CType&lt;/FONT&gt;&lt;FONT size=2&gt;(Activator.CreateInstance(FormType), Form)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Check if the form exist in the MDI collection and if so activate it.&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;For&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Each&lt;/FONT&gt;&lt;FONT size=2&gt; currentForm &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; Form &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;In&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;._MDI.Controls&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;If&lt;/FONT&gt;&lt;FONT size=2&gt; currentForm.Name = loForm.Name &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Then&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- IF the form is minimized then restore it.&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;If&lt;/FONT&gt;&lt;FONT size=2&gt; currentForm.WindowState = FormWindowState.Minimized &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Then&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;currentForm.WindowState = FormWindowState.Normal&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Show the form on top of the others.&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;currentForm.BringToFront()&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;Exit&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;Next&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Set the MDI parent&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;loForm.MdiParent = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Show the form&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;loForm.Show()&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;[/codesnippet]</description><pubDate>Thu, 17 Apr 2008 15:39:45 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: MDIChildred collection and security</title><link>http://forum.strataframe.net/FindPost15741.aspx</link><description>[quote][b]Trent L. Taylor (04/17/2008)[/b][hr]Test the security key in the LaunchForm method so that you can determine if the user has the permissions prior to ever showing the form. [/quote]&lt;br&gt;
&lt;br&gt;
I will try this. Thanks.&lt;br&gt;
&lt;br&gt;
[quote]As for the form hanging around, we do not close the form, we place a locked panel on the form. [/quote]&lt;br&gt;
&lt;br&gt;
Well, the form is not already active or visible in this case.  User 1 does not have access, tries to launch.  Gets "Access Denied" (not my code- coming from framework) Form never shows up. Thats good.  User 2 comes up, hits F11 and logs in with different credentials.  User 2 has access to same form User 1 was denied access to.  Tries to launch and my code in the launchform method tells them its already running.  Odd thing is, if I set a breakpoint and check the form properties of "f" object it shows Visible = True, etc.  But it is nowhere to be seen.  I get what your saying about the locked panel and that is cool assuming User 1 hits F11 when User 2 already has form running.  That's a good thing and I assume User 1 can then close the locked form.&lt;br&gt;
&lt;br&gt;
Anyway, your first suggestion may solve the problem and make this moot so I'll try that.&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
Randy</description><pubDate>Thu, 17 Apr 2008 15:10:34 GMT</pubDate><dc:creator>Randy Jean</dc:creator></item><item><title>RE: MDIChildred collection and security</title><link>http://forum.strataframe.net/FindPost15728.aspx</link><description>Test the security key in the LaunchForm method so that you can determine if the user has the permissions prior to ever showing the form.&amp;nbsp; As for the form hanging around, we do not close the form, we place a locked panel on the form.&amp;nbsp; So if the form is going away you have other logic that is causing this to happen.&amp;nbsp; You can see what I am talking about in the Role Based Security sample that comes with the framework.</description><pubDate>Thu, 17 Apr 2008 10:55:59 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item></channel></rss>