<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>MDI</title>
        <link>http://blogs.ugidotnet.org/franx_blog/category/MDI.aspx</link>
        <description>MDI Form</description>
        <language>it-IT</language>
        <copyright>Francesco Geri</copyright>
        <generator>Subtext Version 2.6.0.0</generator>
        <item>
            <title>Eliminazione dello sfarfallio (flickering) delle Finestre figlie di una MDI all&amp;rsquo;activate</title>
            <link>http://blogs.ugidotnet.org/franx_blog/archive/2013/03/01/101460.aspx</link>
            <description>Quando una Form MDI contiene delle form figlie aperte in modalità Maximized si uno sfarfallio al cambio delle finestra attiva.  Ciò succede quando si attiva la finestra da codice. Per evitare questo fastidioso comportamento si può come al solito ricorrere alle API Windows.  A tal proposito ho preparato un modulo MDIUtil che crea un Extension method per aggiungere alla form MDIParent il metodo MyActivateMdiChild con cui si può richiedere di attivare una form child evitando il flickering.   Il codice del modulo è il seguente:          Imports System.Collections.Generic


    Imports System.Linq


    Imports System.Text


    Imports System.Windows.Forms


    Imports System.Runtime.InteropServices


     


    Public Module MDIUtil


     


    #Region " MDI Activate Child "


     


        &amp;lt;System.Security.SuppressUnmanagedCodeSecurity&amp;gt;


        &amp;lt;System.Runtime.InteropServices.DllImport("user32.dll", CharSet:=System.Runtime.InteropServices.CharSet.Auto)&amp;gt;


        Public Function SendMessage(hWnd As IntPtr, msg As Integer, wParam As IntPtr, lParam As IntPtr) As IntPtr


        End Function


     


        Public Const WM_MDINEXT As Integer = &amp;amp;H224


     


        ''' &amp;lt;summary&amp;gt;


        ''' Attiva la form MDI child specificata eviatando i problemi di flicker/flashing


        ''' che si avrebbero usando semplicemente il metodo &amp;lt;see cref="Form.Activate"&amp;gt;Activate&amp;lt;/see&amp;gt;.


        ''' Vedi post http://www.codeproject.com/Articles/19524/Workaround-for-flicker-flashing-when-programmatica


        ''' &amp;lt;/summary&amp;gt;


        ''' &amp;lt;param name="form"&amp;gt;Form MDI partent&amp;lt;/param&amp;gt;


        ''' &amp;lt;param name="childToActivate"&amp;gt;Form MDI child da attivre&amp;lt;/param&amp;gt;


        &amp;lt;System.Runtime.CompilerServices.Extension&amp;gt;


     Public Sub MyActivateMdiChild(form As Form, childToActivate As Form)


            If Not childToActivate Is form.ActiveMdiChild Then


                Dim mdiClient As MdiClient = GetMDIClient(form)


                If mdiClient Is Nothing Then Return


                Dim count As Integer = form.MdiChildren.Length


                Dim childForm As Control = Nothing


                ' next or previous MDIChild form


                Dim pos As Integer = mdiClient.Controls.IndexOf(childToActivate)


                If pos &amp;lt; 0 Then Return 'Throw New InvalidOperationException("MDIChild form not found")


                If mdiClient.Controls.Count &amp;lt;= 1 Then


                    ' C'è un solo child, quindi attiva quello in modo classico


                    childToActivate.Focus()


                    Return


                End If


                If pos = 0 Then


                    childForm = mdiClient.Controls(1)


                Else


                    ' get next and activate previous


                    childForm = mdiClient.Controls(pos - 1)


                End If


                ' get previous and activate next


     


                ' flag indicating whether to activate previous or next MDIChild


                Dim direction As New IntPtr(If(pos = 0, 1, 0))


     


                ' bada bing, bada boom


                SendMessage(mdiClient.Handle, WM_MDINEXT, childForm.Handle, direction)


            End If


        End Sub


     


        Public Function GetMDIClient(form As Form) As MdiClient


            For Each c As Control In form.Controls


                If TypeOf c Is MdiClient Then


                    Return DirectCast(c, MdiClient)


                End If


            Next


            Return Nothing 'Throw New InvalidOperationException("No MDIClient")


        End Function


     


    #End Region


     


    End Module



 

A questo punto nella form parent MDI si deve importare il modulo e usare il metodo MyActivateMdiChild al posto di child.Activate() (o Focus()):


  
    Imports itConsult.josh.joshDesigner.MDIUtil


     


     


    ...


     


    Dim child As Form = getTheFormToActivate()


    ' La seguente istruzione sostisuice l'istruzione: child.Activate()


    Me.MyActivateMdiChild(child)



 

Nei commenti del codice del modulo è indicata anche la fonte da cui ho liberamente preso quel codice, ovvero questo post.&lt;img src="http://blogs.ugidotnet.org/franx_blog/aggbug/101460.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Francesco Geri</dc:creator>
            <guid>http://blogs.ugidotnet.org/franx_blog/archive/2013/03/01/101460.aspx</guid>
            <pubDate>Fri, 01 Mar 2013 18:13:59 GMT</pubDate>
            <comments>http://blogs.ugidotnet.org/franx_blog/archive/2013/03/01/101460.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.ugidotnet.org/franx_blog/comments/commentRss/101460.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Rimuovere il bordo interno delle form MDI (sunken)</title>
            <link>http://blogs.ugidotnet.org/franx_blog/archive/2013/03/01/101458.aspx</link>
            <description>Una Form MDI di default ha un bordo interno (che credo sia di tipo sunken), ovvero del tipo:    Per rimuoverlo si può ricorrere alle API windows.   A tal proposito ho preparato un modulo MDIUtil che crea un Extension method per aggiungere alla form MDIParent il metodo SetBevel con cui si può richiedere di mostrare o non mostrare il bordo.  Il codice del modulo è il seguente:          Imports System.Collections.Generic


    Imports System.Linq


    Imports System.Text


    Imports System.Windows.Forms


    Imports System.Runtime.InteropServices


     


    Public Module MDIUtil


     


    #Region " Bordo interno (sunken) "


     


        &amp;lt;DllImport("user32.dll")&amp;gt; _


        Private Function GetWindowLong(hWnd As IntPtr, nIndex As Integer) As Integer


        End Function


     


        &amp;lt;DllImport("user32.dll")&amp;gt; _


        Private Function SetWindowLong(hWnd As IntPtr, nIndex As Integer, dwNewLong As Integer) As Integer


        End Function


     


        &amp;lt;DllImport("user32.dll", ExactSpelling:=True)&amp;gt; _


        Private Function SetWindowPos(hWnd As IntPtr, hWndInsertAfter As IntPtr, X As Integer, Y As Integer, cx As Integer, cy As Integer, _


            uFlags As UInteger) As Integer


        End Function


     


        Private Const GWL_EXSTYLE As Integer = -20


        Private Const WS_EX_CLIENTEDGE As Integer = &amp;amp;H200


        Private Const SWP_NOSIZE As UInteger = &amp;amp;H1


        Private Const SWP_NOMOVE As UInteger = &amp;amp;H2


        Private Const SWP_NOZORDER As UInteger = &amp;amp;H4


        Private Const SWP_NOREDRAW As UInteger = &amp;amp;H8


        Private Const SWP_NOACTIVATE As UInteger = &amp;amp;H10


        Private Const SWP_FRAMECHANGED As UInteger = &amp;amp;H20


        Private Const SWP_SHOWWINDOW As UInteger = &amp;amp;H40


        Private Const SWP_HIDEWINDOW As UInteger = &amp;amp;H80


        Private Const SWP_NOCOPYBITS As UInteger = &amp;amp;H100


        Private Const SWP_NOOWNERZORDER As UInteger = &amp;amp;H200


        Private Const SWP_NOSENDCHANGING As UInteger = &amp;amp;H400


     


        ''' &amp;lt;summary&amp;gt;


        ''' Consente di rimuovere il bordo 3D interno della form MDI (sunken).


        ''' Vedi post: http://stackoverflow.com/questions/7752696/how-to-remove-3d-border-sunken-from-mdiclient-component-in-mdi-parent-form


        ''' Oppure articolo: http://www.codeproject.com/Articles/8489/Getting-a-quot-Handle-quot-on-the-MDI-Client#Changing%20the%20Border%20Styles:


        ''' &amp;lt;/summary&amp;gt;


        ''' &amp;lt;param name="form"&amp;gt;&amp;lt;/param&amp;gt;


        ''' &amp;lt;param name="show"&amp;gt;False per rimuovere il sunken (3D interno), True per mostrarlo&amp;lt;/param&amp;gt;


        ''' &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;


        &amp;lt;System.Runtime.CompilerServices.Extension&amp;gt;


     Public Function SetBevel(form As Form, show As Boolean) As Boolean


            For Each c As Control In form.Controls


                Dim client As MdiClient = TryCast(c, MdiClient)


                If client IsNot Nothing Then


                    Dim windowLong As Integer = GetWindowLong(c.Handle, GWL_EXSTYLE)


     


                    If show Then


                        windowLong = windowLong Or WS_EX_CLIENTEDGE


                    Else


                        windowLong = windowLong And Not WS_EX_CLIENTEDGE


                    End If


     


                    SetWindowLong(c.Handle, GWL_EXSTYLE, windowLong)


     


                    ' Update the non-client area.


                    SetWindowPos(client.Handle, IntPtr.Zero, 0, 0, 0, 0, _


                        SWP_NOACTIVATE Or SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOOWNERZORDER Or SWP_FRAMECHANGED)


     


                    Return True


                End If


            Next


            Return False


        End Function


     


    #End Region


     


    End Module



 

A questo punto nella form parent MDI si deve importare il modulo e usare il metodo SetBevel nella load, ovvero:


  
    Imports itConsult.josh.joshDesigner.MDIUtil


     


    Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        Me.SetBevel(False)


    End Sub



 

Nei commenti del codice del modulo sono indicate anche le fonti da cui ho liberamente preso quel codice, ovvero questo post e questo post.&lt;img src="http://blogs.ugidotnet.org/franx_blog/aggbug/101458.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Francesco Geri</dc:creator>
            <guid>http://blogs.ugidotnet.org/franx_blog/archive/2013/03/01/101458.aspx</guid>
            <pubDate>Fri, 01 Mar 2013 11:05:46 GMT</pubDate>
            <comments>http://blogs.ugidotnet.org/franx_blog/archive/2013/03/01/101458.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.ugidotnet.org/franx_blog/comments/commentRss/101458.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>