Расположение элементов управления внутри панели WindowsFormHost - wpf - PullRequest
0 голосов
/ 30 апреля 2020

У меня есть три элемента управления внутри панели, как показано ниже. Я должен расположить один в центре панели. и два других должны располагаться слева и справа от центра. Я пытался, как показано ниже. Но все три элемента управления выровнены по левому краю. Пожалуйста, помогите исправить.

   <WindowsFormsHost  x:Name="windowsFormsHost1"  Grid.Row="5"   Grid.ColumnSpan="3"   Initialized="WindowsFormsHost_Initialized"  HorizontalAlignment="Center" VerticalAlignment="Center"  >
        <wf:Panel x:Name="Panel_glcontrol" Dock="None" BackColor="yellow" >
            <wf:Panel.Controls>
                <opentk:GLControl x:Name="glControl" Width="450" Height="299"  Dock="None"   Visible="True" MouseMove="GlControl_MouseMove" MouseDown="GlControl_MouseDown"  Resize="glControl_Resize" Paint="glControl_Paint"  />
                <opentk:GLControl x:Name="glControl2"  Width="450" Height="299" Dock="None"    MouseDown="GlControl2_MouseDown" MouseMove="GlControl2_MouseMove"   Visible="True"  Resize="glControl2_Resize" Paint="glControl2_Paint"  />
                <opentk:GLControl x:Name="glControl3" Width="450" Dock="None" Height="299"  Visible="True"  MouseDown="GlControl3_MouseDown" MouseMove="GlControl3_MouseMove" Resize="glControl3_Resize" Paint="glControl3_Paint" />
            </wf:Panel.Controls>
        </wf:Panel>
    </WindowsFormsHost>

     glControl2.Location = new System.Drawing.Point((_Screenwidth / 2) - glControl2.Width / 2, (_Screenheight - glControl.Height) / 2);
     glControl.Location = new System.Drawing.Point(glControl2.Location.X - glControl.Width - 5, (_Screenheight - glControl2.Height) / 2 );          
     glControl3.Location = new System.Drawing.Point(glControl2.Location.X + glControl2.Width + 5, (_Screenheight - glControl3.Height) / 2 );

Ответы [ 2 ]

0 голосов
/ 04 мая 2020

Я решил это путем удаления горизонтального и вертикального выравнивания WindowsFormsHost. А затем добавив функцию ниже, чтобы переместить элементы управления.

     private void RelocateOpenGLs()
    {
        int PSBH = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
        int TaskBarHeight = PSBH - System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;//have to hide taskbar

        glControl2.Location = new System.Drawing.Point((_Screenwidth / 2) - glControl2.Width / 2, ((Panel_glcontrol.Height - glControl.Height) / 2) - TaskBarHeight);
        glControl.Location = new System.Drawing.Point(glControl2.Location.X - glControl.Width - 2, ((Panel_glcontrol.Height - glControl2.Height) / 2) - TaskBarHeight);
        glControl3.Location = new System.Drawing.Point(glControl2.Location.X + glControl2.Width + 2, ((Panel_glcontrol.Height - glControl3.Height) / 2) - TaskBarHeight);

    }  
0 голосов
/ 30 апреля 2020

Что если вы поместите каждый элемент управления WinForms на свой собственный хост, а затем будете использовать панели WPF для макета? Как то так:

<UniformGrid Rows="1" Grid.Row="5" Grid.ColumnSpan="3" HorizontalAlignment="Center" VerticalAlignment="Center" Background="Yellow">
    <WindowsFormsHost>
        <opentk:GLControl x:Name="glControl" Width="450" Height="299" Dock="None" Visible="True" MouseMove="GlControl_MouseMove" MouseDown="GlControl_MouseDown" Resize="glControl_Resize" Paint="glControl_Paint"/>
    </WindowsFormsHost>
    <WindowsFormsHost>
        <opentk:GLControl x:Name="glControl2" Width="450" Height="299" Dock="None" MouseDown="GlControl2_MouseDown" MouseMove="GlControl2_MouseMove" Visible="True" Resize="glControl2_Resize" Paint="glControl2_Paint"/>
    </WindowsFormsHost>
    <WindowsFormsHost>
        <opentk:GLControl x:Name="glControl3" Width="450" Dock="None" Height="299" Visible="True" MouseDown="GlControl3_MouseDown" MouseMove="GlControl3_MouseMove" Resize="glControl3_Resize" Paint="glControl3_Paint"/>
    </WindowsFormsHost>
</UniformGrid>
...