This question already has answers here:
Center a C# Windows Form inside another window
(1 answer)
Show a child form in the centre of Parent form in C#
(19 answers)
Show Dialog box at center of its parent
(5 answers)
Closed 1 year ago.
I want to make classic a modal Window with dark background.
I don't know why this is so hard to make it. I tried a lot way to do it, however it just doesn't fit with my needs.
I have 10+ modal Windows and they are customized Forms which contain grids, charts, etc.
They are not 'OK, No, Cancel' stuff.
My code basically creates another Form with black background between parent Form and modal Form:
Form f = new Form();
f.BackColor = Color.Black;
f.Size = this.Size;
f.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
f.StartPosition = this.StartPosition;
f.Opacity = 0.6;
f.Show();
notificationSGA nsga = new notificationSGA(Cursor.Position);
nsga.ShowDialog();
f.Dispose();
f.Close();
Above code works perfectly fine. However if I move the parent (master) Form to somewhere instead of center of the screen, the black Form still appears at the center of the screen, not centered to the parent Form.
How can I solve my issue?
Note: This is not duplicated topic with below question:
How to show a pop up message with dark background
Change the .StartPosition to .Manual so that you can set .Location to where your reference form is.
Also, change the owner in the .Show() method for both new Forms.
Form f = new Form();
//(...)
f.Size = this.Size;
f.StartPosition = FormStartPosition.Manual;
f.Location = this.Location;
//(...)
f.Show(this);
using (var nsga = new notificationSGA(Cursor.Position)) {
nsga.StartPosition = FormStartPosition.CenterParent;
nsga.ShowDialog(f);
}
f.Dispose();
Related
I have windows form with some form with buttons and other components. Buttons are anchored to Bottom and Right. When the application is started as maximized, the buttons don't appear in the corner of the form as they should but remain as if they were anchored to Top and Left. If I unmaximize this form, they remain as far away from the bottom right as in maximized. However, if the form is started normal, not maximized, then everything is ok and the buttons are in the corner. I have the same buttons in other forms and there everything works good, only this one is broken. How can I fix this?
Designer:
Form started maximized:
Form unmaximized:
Now I change the WindowState from Maximized to Normal:
And when I maximize:
And this happens only in this form, in other forms, this solution works fine, it doesn't matter if maximized or normal. What is broken in this particular form?
Designer.cs code for this form is the following (the whole file has over 600 lines, so I selected the important ones:
this.buttonAneks = new System.Windows.Forms.Button();
(...)
// buttonAneks
//
this.buttonAneks.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonAneks.BackColor = System.Drawing.SystemColors.Window;
this.buttonAneks.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.buttonAneks.Location = new System.Drawing.Point(715, 585);
this.buttonAneks.Name = "buttonAneks";
this.buttonAneks.Size = new System.Drawing.Size(75, 23);
this.buttonAneks.TabIndex = 103;
this.buttonAneks.Text = "Aneksy";
this.buttonAneks.UseVisualStyleBackColor = false;
this.buttonAneks.Click += new System.EventHandler(this.buttonAneks_Click);
(...)
this.Controls.Add(this.buttonAneks);
this.Controls.SetChildIndex(this.buttonAneks, 0);
(...)
private System.Windows.Forms.Button buttonAneks;
Turns out that the problem was the Adobe PDF Reader control axAcroPDF, which was present in this particular form, and for unknown reasons, it caused such behavior. Removing it solved the problem.
Am creating a windows application (win form). I want to create a UI something like the attached image.
Am using a form (called CalendarForm),that will contains the right side controls (blue background portion)
The issue now am facing is, when am using MDI and setting CalendarForm as a child. Then I am not able to sent the opacity to show the MDI parent form background.
Am using below mentioned code in MDIForm_Load method
this.WindowState = FormWindowState.Maximized;
CalendarForm calForm = new CalendarForm();
calForm.BackColor = Color.FromArgb(33, 66, 131);
calForm.Opacity = 0.5d;
calForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
calForm.MdiParent = this;
calForm.Show();
Is there any way to achieve my requirement ?
Using this Custom Month Calendar created by Patrik Bohman ,we can make the calendar background transparent.
To make a WinForm transparent you could use the opacity property
calForm.Opacity = 0.5;
We're using MDI for our program.
Yes, I know, use something else, MDI is bad etc etc...the client is more comfortable with the MDI style of UI so we're sticking to that. So far we have found no need for anything like TDI or SDI anyway.
The one thing we would like to be able to do is to automatically size an MDI child to be half of the MDI client area's size; kind of similar to how in Windows 7/8 you can drag a window to one side of the screen and it will resize it to fill half of the desktop.
How can I do this?
To clarify, I'm not looking for docking, and obviously resizing a form is easy enough, I'm more interested in how to catch when the user drags the form to the edge of the MDI client area, and somehow centralising that logic so I'm not duplicating it in every form. Showing an outline of where the form will end up would be pleasant as well (again, similar to Win7/8 resizing).
Thanks
You are in for a world of hurt.
But here is how to get started:
Form f = new Form();
f.ResizeEnd += f_ResizeEnd;
f.MdiParent = this;
f.Show();
void f_ResizeEnd(object sender, EventArgs e) {
MdiClient mc = this.Controls.OfType<MdiClient>().First();
Form f = sender as Form;
if (f.Right >= mc.ClientSize.Width) {
f.SetBounds(mc.ClientSize.Width / 2, 0,
mc.ClientSize.Width / 2, mc.ClientSize.Height);
}
}
This question already has answers here:
Load a form without showing it
(8 answers)
Closed 8 years ago.
I have winforms application which has a popup dialog. I need the dialog to popup but without showing itself. This is how I currently do it:
DialogForm myDialog = new DialogForm();
myDialog.Show();
myDialog.Visible = false;
The problem with this method is that for a split second the dialog shows up and then disappears. From a functional point of view it works fine, but it does annoy some users of my application and actually takes the "focus" away from the main form. I've also tried this but it doesn't work:
DialogForm myDialog = new DialogForm();
myDialog.Visible = false;
myDialog.Show();
There has to be a way to create the dialog and run it in the background without having to call "Show()." Thanks for any possible help!
How about doing something like positioning the pop-up window in the left lower corner of the screen?
So even if it's showing for a split second, nobody will still be able to see it.
So before showing your window, write a line such as:
myDialog.Location = new Point(x,y);
// the x,y will be your coordinates of the lower-left margin of Form1
This question already has answers here:
How to CenterParent a non-modal form
(4 answers)
Closed 8 years ago.
I have my main form as my application.
Now when I open a new form say to display settings.
FormB bForm = new FormB(this);
blpForm.Show();
Now this works fine but Form b is a smaller form and it appears outside of the boundaries of my original form. I don't want it to be 'Inside' the original form I just want its initial position to be the centre of the original form.
How do I go about doing that?
You have to set its Location yourself, which means that you also have to set its StartPosition to Manual. It's basic arithmetic to calculate the Location of the dialogue based on the Location and Size of the caller and the Size of the dialogue.
What about this code ? As Rotem said here ,
FormB bForm = new FormB ();
bForm .StartPosition = FormStartPosition.Manual;
bForm .Location = new Point(this.Location.X + (this.Width - bForm.Width) / 2,
this.Location.Y + (this.Height - bForm.Height) / 2); //this is just an example , you can customize the location
bForm .Show();