Popup window in C#.net - c#

How to popup a child form when I click the button. I want to child winform to be in the centre of the screen and the whole background screen should be blurred. and a small close button should be visible in the right corner of the form. I have searched the web but found nothing.
Using Winforms.

Make a new windows form. it has a close button by default. Set it default position to center screen. Then on your button click.
Lets say your new form is Form2
Form2 frm = new Form2();
frm.ShowDialog();
it will not make the rest of screen blurred but user will not be able to do anything with it.
For blurry effect a workaround has been posted here

You can trigger event from click button like this
Form form1=new Form();
form1.show;
and after that to blurr the parent screen use opacity property of and increase or decrease it accord to your requirement.
you can also control the transparency of the child form using a timer and increase paacity with timer click it will make it more dynamic and interactive.

Related

How Can I make a C# Windows Form Overlap in a Sidebar form?

So, how can I make a Windows form, come onto the current form as a Sidebar instead of full form?
For example, I have Form 1 with a button named Sidebar, I press that button and Form2 comes and overlaps Form 1 as a Sidebar on the left? I know I can do it with the entire Computer Screen, but I just want it within the Application itself.

C# Form2.ShowDialog() and Mouse Cursor

(NET Compact Framework 3.5, Windows CE 6.0)
I want to hide mouse cursor.
So, I use Curosr.Hide()
I have two forms, Form1, Form2.
The size of Form2 is smaller than Form1.
PictureBox1 is in Form1.
When PictureBox1 is clicked, Form2 will be opened. (modal)
At this point, the mouse cursor suddenly appears outside area of Form2.
MouseDonw PictureBox1 -> Form2.ShowDialog -> Show MouseCursor
I have never done Cursor.Show()
Why does the mouse cursor appear?
Added the following
I moved Form2.ShowDialog() from 'MouseDown Event' to 'MouseUp Event'. then it is resolved. Why?
First, form show and other 'actions' usually are done with a mouse click event. That is fired after mouse down and mouse up.
If you break the normal sequence, ie show a form on a mouse down event, the GUI is in 'Mouse down/move' mode, for example to drag an element or draw a line.
As each element can show/hide the mouse cursor, the Windowing System recognizes youre Cursor Hide on the second form, but the first form still shows the mouse cursor as the Mouse Up event is not done.
If you would like to know more about the Basics, you should look at a native WndProc and how are Window Messages are handled. Programming Windows by Charles Petzold is still the bible for Windows programming.

Add White Layer on top of Main Window

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;

MDI Child Form Start Position Problem

I am having this strange problem with the start position of the MDI child Form.
Here is my code for the start position, I wanted it to be the middle left of
the MDI Parent Form.
//show the task bar
ChildForm c1 = new ChildForm();
c1.MdiParent = this;
c1.StartPosition = FormStartPosition.Manual;
c1.Location = new Point(0, this.Height/2);
Strange thing is every time I start my Mdi parent form, the vertical scrollbar show up
and the mdi child form is position lower than half of the MDI parent form's height.
Then if I scroll the scroll bar down to see the whole mdi child form, the scrollbar disappear.
After this point, no matter how I change the size of the mdi parent form, the scrollbar will
not show up again.
Does Anybody knows Why?
Also, I was wondering if it is possible to hide a mdi child form with only a handle-like control left
in the mdi parent form. If the user click that handle, then the form show up again. If the user
click somewhere else, the form hide. It is kind of like Window taskbar.
I tried to use form.hide(), but it hides the whole mdi child form.
Thanks
Alex
Is is possible that your calculation is taking into account the windows bar at the top.
You can have a look at PointToClient or PointToScreen
you sholud minuse child form height and width like this
c1.Location = new Point(0, (this.Height - c1.Height)/2);

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