Add White Layer on top of Main Window - c#

I need to add a white layer on top of a Main form when a modal window appears on top of it so that it gives prominent to the modal window and kind of make the background transparent.
Add 75% Opaque white background for example...
Can it be done in Win forms?
Thanks!

The easiest way to do this might be to disable the main container control in your main form. That usually gives a faded look to everything in it.

You can set the parent form enabled property to false after you open the child form, which will make the parent form read only and darker, so it's obvious the parent form is not active.
form1.Enabed = false;

Related

Do it yourself MDI

I have created an MDI application that I want to add a ToolStripContainer to. My first try was to just add one and dock it on Top. Problem I got here was moving ToolStrips inside the container's ToolStripPanels would create an extra Row which was invisible.
Then I saw this question and tried to implement my do-it-yourself MDI interface, using the ToolStripContainer's ContentPanel as where the windows go. This way, I can have my ToolStrips anywhere around the MDI.
The code I have is as follows:
Form f = new Form();
f.TopLevel = false;
tsContainer.ContentPanel.Controls.Add(f);
It all works remarkably well, but I am wondering if this is smart, would I not run into problems later on? Also, if this is possible, why have the entire MDI functionality in Windows?
By setting the TopLevel property to false, the form essentially turns into a UserControl. Do note that you have to explicitly set the Visible property to true, it isn't automatic.
But yes, there certainly are problems and it doesn't behave like an MDI child window at all. The biggest issue should be readily visible, the form can no longer be activated. Very noticeable from its caption bar, it will always be rendered with the colors for a non-active window. It however still works like a caption bar, the user can drag the window and move it around. Which has the clear failure mode that the window is going to get clipped without scrollbars. Not only that, the window can still be maximized and minimized by double-clicking the caption. An MDI child does this very differently. And the visual style for the frame will be wrong in Windows 8.x, looking like a Win7 frame instead, a quirk that has no known workaround.
Realistically, you have to set the FormBorderStyle property to None so it behaves more like a true child window. Or write a bunch of fairly nasty code in the WndProc() override to tame the window, you'll be doomed to re-invent an MDI child, imperfectly.
Which is otherwise a fine way to embed a form. The only remaining quirk after fixing the border is that the form still gets added to the Application.OpenForms collection.

How to Display Label on MDI Form without background Color(Transperent) in c#

I placed an MDI form in my application . I have given Background image to the MDI Form , And I wants to Display The Label On MDI Form and also wants to add some picture buttons.
So, How should i remove that background color , Please Help Me.
You cannot add child controls like a Label to an MDI parent form. It just doesn't work. The only thing that MDI parent forms are designed to contain is child MDI forms.
If you want a background to be visible, you should just use a regular form. The only purpose of MDI is to allow your parent window to act as a container of other sub-windows. This is a fairly obsolete design pattern, one that Microsoft and most other vendors stopped using in their software long ago because it confuses users.
If you drop MDI and use a regular form, you can add whatever Label, Button, and PictureBox controls you want to it. To make them transparent, you can enable their Transparent property. This doesn't always work as expected because WinForms doesn't support true transparency, but it sounds like to me that it will work fine for your described use.

How to disable a Grid (Panel) in XAML Metro app?

I want to emulate modal dialog in XAML Metro App.
So I was going to set .IsEnabled = false on all controls apart from the one which will pose as a modal dialog.
Apparently IsEnabled not in Grid not in Panel not in FrameworkElement. How to disable it not making a user control out of it?
I guess Sinofsky cut so many corners that the whole thing is now more like an Escher staircases. I am loosing my faith. Please help
Sorry, I am a little late to the party...
Here is how I created a modal popup - I used a popup dialog where the top and bottom portions are transparent so that anything behind it will show through. When the popup is opened, I set its size to cover the entire screen.
The top and bottom portions of the popup also are set to autosize (height = *), so that they fill up the entire top and bottom of the screen. This prevents any input from going into the grid underneath.
Here is a screen shot of my popup in Visual Studio:
The popup is a grid with 5 rows, 3 for the dialog itself and 2 for the transparent top and bottom.
Here is how the popup looks in my app. Obviously the grid shows through the transparent top and bottom. Since the popup fills the entire screen, any input (keyboard or mouse) goes to it rather than the grid underneath, making the popup act like a modal dialog.
Be warned though that with this strategy, you have to handle these events:
Screen resizes (full screen, snapped view, filled view) - you need to resize the popup to fit within each of the view states
Screen rotation - again, you have to handle resizing here
Keyboard popup - you need to shift the popup up so that the onscreen keyboard does not interfere with it.
Set IsHitTestVisible = false on the background content.
Additionally you could set focus to something in your modal layer root and set TabNavigation to Cycle on the modal layer root to make sure that users can't tab/shift+tab out of it. Also make sure the modal layer is all hit test-solid - e.g. Transparent or has some other fill so users can't click through it.
Also make sure no Popups show while your modal layer is visible.
Unfortunately no one seems to know (except Mr Skakun who gave wrong answer and never bothered to revise it).
Hence my solution (the simplest) is to make the element in question Hidden - I cant find any other ways to 'disable' a grid.
If I wanted to disable it correctly I would have to write a recursive function to find all FrameworkElements in the grid children and set IsEnabled = false though.

C# topmost window

I have two windows form and both set the topmost property to true. But the form border style of the one form is Set to "None". The other form has border. When these two forms launch together, the one without the border is always on top and overlap the other form. How do i make the form with border always on top? thanks.
I suggest you to start the form with borders last or set other form TopMost property to false.
[Edit] I sugest you to look at the Forms Owner property - http://msdn.microsoft.com/en-us/library/system.windows.forms.form.owner.aspx.
formWithoutBorders.AddOwnedForm(borderForm);
borderForm.Show();
Show (make Visible) the window that is supposed to be on top, later as the other window.
Topmost only works between non-topmost and topmost windows. Between Topmost windows, the normal rules apply of what window to show.
To understand why this is happening, I recommend Raymond Chen's What if two programs did this article

Maximizing child mdi in limited area

I have a form which is a mdicontainer and has a menu strip at the top. I add a child form to my mdi container and when I maximize the child it maximizes over the menustrip. I want to know how to limit the child to maximize below the menustrip. Any help would be appreciated.
Your child form is being maximized in the way that child forms are supposed to be maximized in MDI. It's not really covering the menu strip of the parent form - it's actually merging its own menu strip with that of the parent form.
To make the child form take up only the available child area in the MDI parent (and not merge its menu with the parent's menu), put something like this code in the child form's Resize event:
if (this.WindowState == FormWindowState.Maximized)
{
this.WindowState = FormWindowState.Normal;
this.Size = this.MdiParent.ClientSize;
this.Location = new Point(0, 0);
}
which will prevent the child window from being actually maximized.
I say "something like this code" because this snippet doesn't work exactly right. The ClientSize property of the parent form gives the overall size of the form, whereas you want to use the size of just the MDI client area. I don't know how to get that, and apparently it's not super-easy. See this question:
Size/Location of Winforms MDI Client Area
You could set the MaximumSize property so that it doesn't fill up the entire container.
I know this an old question, but I just ran into this on an old project I'm working on, so here's an answer for anyone seeing this. Setting the Dock to DockStyle.Fill will give you the behaviour you want.
Just be aware that the window will act/look strange if you try to reposition or resize the window while it has that DockStyle.
To accomplish this, I subscribed to the MDI client window's resize event and if the window had just been maximized, I set its DockStyle to Fill, set the FormBorderStlye to FixedDialog(to prevent resizing), and set the window state to normal to prevent the maximization from occurring.
To prevent the user from moving the window while it is in this "maximized state" I simply overrode the WndProc method and handled when the window was being moved(SC_MOVE) and placed a return to prevent the action from taking effect.

Categories

Resources