Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF Form disapears whenever I add `NoResize` property
    text
    copied!<p>I am trying to use WPF to create a dock application in the style of <a href="http://www.delldock.com/images/version15d/dell_dock.jpg" rel="nofollow noreferrer">the Dell Dock</a> and it is going well so far.</p> <p>My WPF form appears like so on my screen:</p> <p><img src="https://i.stack.imgur.com/otKNl.jpg" alt="John Dock"></p> <p>The XAML for my form is below:</p> <pre><code>&lt;Window x:Class="WpfApplication7.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="130" Width="525" Loaded="Window_Loaded" Background="Transparent" WindowStyle="None"&gt; &lt;Grid&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>I found a tutorial on the Microsoft website to add the Aero Glass effect. With this in mind, my code is below:</p> <pre><code>using System; using System.Drawing; using System.Runtime.InteropServices; using System.Windows; using System.Windows.Forms; using System.Windows.Interop; namespace WpfApplication7 { /// &lt;summary&gt; /// Interaction logic for MainWindow.xaml /// &lt;/summary&gt; public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { MakeTransparent(); Topmost = true; var screenWidth = SystemInformation.PrimaryMonitorSize.Width; var startingPoint = (screenWidth / 2) - (Width / 2); Top = 2; Left = startingPoint; } private void MakeTransparent() { IntPtr mainWindowPtr = new WindowInteropHelper(this).Handle; HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr); mainWindowSrc.CompositionTarget.BackgroundColor = System.Windows.Media.Color.FromArgb(0, 0, 0, 0); Graphics desktop = Graphics.FromHwnd(mainWindowPtr); float DesktopDpiX = desktop.DpiX; float DesktopDpiY = desktop.DpiY; MARGINS margins = new MARGINS() { cxLeftWidth = 0, cxRightWidth = Convert.ToInt32(Width) * Convert.ToInt32(Width), cyTopHeight = 0, cyBottomHeight = Convert.ToInt32(Height) * Convert.ToInt32(Height) }; int hr = DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins); } [StructLayout(LayoutKind.Sequential)] public struct MARGINS { public int cxLeftWidth; public int cxRightWidth; public int cyTopHeight; public int cyBottomHeight; } [DllImport("DwmApi.dll")] public static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS pMarInset); } } </code></pre> <p>So far so good. However, my form is resizable which I don't want so I set the <code>ResizeMode</code> property to <code>NoResize</code> and whenever I do this my form is nowhere to be found when launched.</p> <p>Why does this happen?</p> <p>I tried to get around this by resseting the form size on the <code>SizeChanged</code> event, but this only if you try to resize from the right or bottom of the form, if you try to resize from the top of left, it moves the form which I don't want either.</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload