MdiWindowListItem


Author
Message
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Trent L. Taylor (04/15/2008)

For each f as Form In Me.MdiChildren
    If DirectCast(f, MyBaseForm).FormId = MyLookupId Then
        '-- You found the form
    End If
Next

If you take this approach you will be much safer across multiple platforms and won't be reliant upon the window handle.

Trent, I hate to ask, but using the GUID logic, where is the MyLookupID value coming from?

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Since we no longer use this logic I hadn't noticed that Vista changes the handle several times through the life of the form.  So to get around this, if you still intend to use window handle, then you will need to override the OnHandleChanged method to trap that event so that you can update your collection logic.

Overrides Protected Sub OnHandleChanged(...)
    '-- Add your logic to update the collections
End Sub

However, I would recommend against using the window handle at this point and add a Guid property to your BaseForm that uniquely identifies the form:

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

   Private _FormId As String = System.Guid.NewGuid().ToString()

   Public Readonly Property FormId As String
        Get
             Return _FormId
        End Get
   End Property
End Class

Then you can enumerate the Forms collection of the MDI to find your form and then activate it (this code would be referencing the MDI  form):

For each f as Form In Me.MdiChildren
    If DirectCast(f, MyBaseForm).FormId = MyLookupId Then
        '-- You found the form
    End If
Next

If you take this approach you will be much safer across multiple platforms and won't be reliant upon the window handle.

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Oh....nevermind, you are using that older logic on the window handles being stored off in the collection...gotcha.  I will see if I can reproduce.
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
OK...different than what?  You have mentioned that you are getting back a different handle...but what are you comparing the handle to? 
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Just to confirm,

I'm also getting back a different handle to than which the child window was assigned on creation.

And also I've tried changing to formclosing but the handle still changes.

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
The form handle won't change after it has been assigned.  If you are running in an MDI environment, then you can handle the OnParentChanged event and save off the handle at that point (I recommend against this).  You should ALWAYS be able to reference the Me.Handle of the form and it will return the handle to which it is presently assigned, which is the only one that you should ever deal with.  This is standard WinForms logic...once a handle is assigned it should never be changed unless the parent changes...that may be the ONLY time that it would change. 

Now it is another thing entirely if the handle has already been released.  In that case you just need to handle an event further up the chain to perform your closing logic.

Mike Tomlin
Mike Tomlin
StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)StrataFrame Beginner (31 reputation)
Group: StrataFrame Users
Posts: 23, Visits: 5.8K
I'm trying the VB version of this technique and I too am getting back a different handle to that which the child window was assigned on creation. I've tried changing to formclosing but the handle still changes. Any thoughts?

Thanks

Mike

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Handle the FormClosing event instead of the FormClosed event...that way you will still have a handle.
Chan
Chan
Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)
Group: Forum Members
Posts: 533, Visits: 2K
Hi,

May I know what control/container are you using to drop window and user panel on? I tried to use flowlayout but its docking cause themetoolstrip unable to dock to top with full screen width.



Please advice.



Thank you
Chan
Chan
Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)
Group: Forum Members
Posts: 533, Visits: 2K
Hi,

I tried the code snippet and convert it to C# as below. I face problem that, the value of loForm.handle is changed in HandleFormClosed event handler. Any ideas? Thank you



private void LaunchForm(System.Type FormType)

{

//-- Establish Locals

Form loForm;

//-- Create the form

loForm = (Form)Activator.CreateInstance(FormType);

//-- Set the MDI parent

loForm.MdiParent = this;

int lnHandle = (int)loForm.Handle;

loForm.FormClosed += this.HandleFormClosed;

_Forms.Add(lnHandle, loForm);

imgWindows.Images.Add(loForm.Text, loForm.Icon);

lvWindows.Items.Add(lnHandle.ToString(), loForm.Text, imgWindows.Images.Count - 1);

//-- Show the form

loForm.Show();

}



private void HandleFormClosed(object sender, FormClosedEventArgs e)

{

System.Windows.Forms.Form loForm;

loForm = (Form)sender;

int lnHandle = (int)loForm.Handle;

if (_Forms.ContainsKey(lnHandle))

{

loForm = _Forms[lnHandle];

loForm.FormClosed -= HandleFormClosed;

imgWindows.Images.RemoveByKey(loForm.Text);

lvWindows.Items.RemoveByKey(lnHandle.ToString());

_Forms.Remove(lnHandle);

}

}

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search