RE: Mdi Icon Position in MenuStrip
- From: v-lliu@xxxxxxxxxxxxxxxxxxxx (Linda Liu [MSFT])
- Date: Tue, 09 Jan 2007 08:56:40 GMT
Hi Lance,
Based on my understanding, you'd like to show the icon of a maximized MDI
child form immediately left of the control box buttons(Minimize, Maximize,
Close). If I'm off base, please feel free to let me know.
When an MDI child form is maximized, its system menu (corresponding to the
icon of the MDI child form) and control box buttons(Minimize, Maximize,
Close) are merged into its MDI parent form's MainMenuStrip (if the MDI
parent form has).
The merged menu items are inserted into the top of the MainMenuStrip and
the sequence is like blow:
system menu item
Close menu item
Maximize/Resore menu item
Minimize menu item
All the value of the Alignment property of the above menu item are
ToolStripItemAlignment.Right, except the system menu item, which has a
value of ToolStripItemAlignment.Left. So system menu item is located at the
far left of the MainMenuStrip.
After above menu items are merged into the MainMenuStrip of the MDI parent
form, we could "adjust" the index of the system menu item to accomplish
what you want.
However, there remains another question, i.e., when to "adjust" the index
of the system menu item? The SizeChanged event of the MDI child form is not
appropriate, because the menu items(system, Close, Maximize and etc) have
not yet merged intot the MainMenuStrip of the MDI parent form when the
SizeChanged event occurs.
I use Spy++ to capture all the messages sent to an MDI child form when it
is maximized, and found the message WM_GETTEXT, which is sent to a window
to copy the text corresponding to the window into a butter provided by the
caller. This message is sent to the MDI child form AFTER the menu items
related to the MDI child form are merged into the MainMenuStrip of the MDI
parent form. So we could catch this message and adjust the index of the
system menu item.
The following is a sample code snippet.
Public Class ParentForm
Private m_originalMenuItemCount As Integer
Public ReadOnly Property OriginalMenuItemCount() As Integer
Get
Return Me.m_originalMenuItemCount
End Get
End Property
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.m_originalMenuItemCount = Me.MenuStrip1.Items.Count
End Sub
End Class
Public Class ChildForm
Private Sub AdjustMenuItem()
If (Me.WindowState = FormWindowState.Maximized) Then
If (Not (Me.MdiParent.MainMenuStrip Is Nothing)) Then
If (Me.MdiParent.MainMenuStrip.Items.Count >
CType(Me.MdiParent, Form1).OriginalMenuItemCount) Then
If (Me.MdiParent.MainMenuStrip.Items(0).Alignment =
ToolStripItemAlignment.Left) Then
Dim item0 As ToolStripMenuItem =
Me.MdiParent.MainMenuStrip.Items(0)
item0.Alignment = ToolStripItemAlignment.Right
Me.MdiParent.MainMenuStrip.Items.RemoveAt(0)
Me.MdiParent.MainMenuStrip.Items.Insert(3, item0)
End If
End If
End If
End If
End Sub
Private WM_GETTEXT = &HD
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If (m.Msg = WM_GETTEXT) Then
Me.AdjustMenuItem()
End If
MyBase.WndProc(m)
End Sub
End Class
I have performed a test on the above code and confirmed it works.
If you have anything unclear, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
.
- Prev by Date: Re: Database problems in VB.NET 2003
- Next by Date: Confused myself!
- Previous by thread: GAC install problem
- Next by thread: Confused myself!
- Index(es):