I want to create label and set the text using method but it wont work, here's my code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
intro();
}
private void fullScreen()
{
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Bounds = Screen.PrimaryScreen.Bounds;
}
private void intro()
{
pictureBox1.BackColor = Color.White;
pictureBox1.SendToBack();
Label introInfo = new Label();
introInfo.Font = new Font("century gothic", 24, FontStyle.Bold);
introInfo.ForeColor = Color.Cyan;
introInfo.Text = "succes bro!";
introInfo.Visible = true;
introInfo.Location = new Point(100, 100);
}
}
What should I do to make it work?
You need to add the label to the form
this.Controls.Add(label);
Take a look at this example
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Load += Form1_Load;
}
void Form1_Load(object sender, EventArgs e)
{
intro();
}
private void fullScreen()
{
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Bounds = Screen.PrimaryScreen.Bounds;
}
private void intro()
{
Label introInfo = new Label();
introInfo.Font = new Font("century gothic", 24, FontStyle.Bold);
introInfo.ForeColor = Color.Cyan;
introInfo.Text = "succes bro!";
introInfo.Visible = true;
introInfo.Location = new Point(100, 100);
introInfo.Height = 35;
introInfo.Width = 250;
this.Controls.Add(introInfo);
}
}
You need to add newly created label to the control collection
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
intro();
}
private void fullScreen()
{
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Bounds = Screen.PrimaryScreen.Bounds;
}
private void intro()
{
pictureBox1.BackColor = Color.White;
pictureBox1.SendToBack();
Label introInfo = new Label();
introInfo.Font = new Font("century gothic", 12, FontStyle.Bold);
introInfo.ForeColor = Color.Cyan;
introInfo.Text = "succes bro!";
introInfo.Visible = true;
introInfo.Location = new Point(75, 23);
introInfo.Size= new Size(100,100);
this.Controls.Add(introInfo);
}
Related
I have a tabControl in a Winform application. The user is able to change settings that will impact each tab visually, and I need to get each tabs as images.
I'm trying to understand why/how some controls are updating even if not visible and some other don't.
Is there a way to force an existing UserControl to update/redraw even if not visible so that Control.DrawToBitmap(...) gets a valid image?
I created an example with a Chart and a FlowLayoutPanel to explain what I mean and to make sure I could reproduce the issue I have.
In the example below:
The image created from the FlowLayoutPanel is only correct if it was updated and visible before DrawToBitmap is called.
The image from the Chart is alway up to date even if updated when not visible.
Questions:
How does it work with one control and not the other?
How could I ensure the FlowLayoutPanel has the same behavior as the Chart?
(EDIT) I have tried a few things without success:
Suspend/Resume layout when updating
call Refresh / Update / Invalidate on the layout that do not update as expected
Here is a gif showing that the chart get updated even when not visible but not the FlowLayoutPanel:
Here is the code of this example:
using LiveChartsCore.SkiaSharpView;
using System.Collections.ObjectModel;
namespace WinFormsDrawToBitmapTest
{
public partial class Form1 : Form
{
int legendCount = 1;
ViewModel viewModel;
public Form1()
{
InitializeComponent();
viewModel = new ViewModel();
cartesianChart1.Series = viewModel.Series;
updateLegend(this.flowLayoutPanel1);
}
private async void button1_Click(object sender, EventArgs e)
{
Bitmap bitmap = await Task.Run(() => getImg3());
this.pictureBox1.Image = bitmap;
this.pictureBox1.Invoke((MethodInvoker)delegate
{ this.pictureBox1.Image = bitmap; });
}
private Bitmap getImg3()
{
Bitmap bitmap = new Bitmap(this.cartesianChart1.Width, this.cartesianChart1.Height + this.flowLayoutPanel1.Height);
Bitmap chart = new Bitmap(this.cartesianChart1.Width, this.cartesianChart1.Height);
Bitmap legend = new Bitmap(this.flowLayoutPanel1.Width, this.flowLayoutPanel1.Height);
this.cartesianChart1.Invoke((MethodInvoker)delegate
{
this.cartesianChart1.DrawToBitmap(chart, new Rectangle(new Point(0, 0), this.cartesianChart1.Size));
});
this.flowLayoutPanel1.Invoke((MethodInvoker)delegate
{
this.flowLayoutPanel1.DrawToBitmap(legend, new Rectangle(new Point(0, 0), this.flowLayoutPanel1.Size));
});
using (Graphics g = Graphics.FromImage(bitmap))
{
g.DrawImage(legend, 0, 0);
g.DrawImage(chart, 0, legend.Height);
}
return bitmap;
}
private void button2_Click(object sender, EventArgs e)
{
Random r = new Random();
viewModel.Data.Add(r.Next(0, 10));
legendCount++;
updateLegend(this.flowLayoutPanel1);
}
private void updateLegend(FlowLayoutPanel flow)
{
flow.Controls.Clear();
Color[] colorList = new Color[]
{
Color.FromArgb(15, 1, 215),
Color.FromArgb(255, 0, 0),
Color.FromArgb(0, 176, 80),
Color.FromArgb(112, 48, 160)
};
for (int i = 0; i < legendCount; i++)
{
//flow.Controls.Add(new LegendLabel($"Label {i}", colorList[i % colorList.Length]));
Button btn = new Button();
btn.Name = $"Button {i}";
btn.TabIndex = 0;
btn.Text = $"Button {i}";
flow.Controls.Add(btn);
}
}
}
public partial class ViewModel
{
public ObservableCollection<double> Data { get; set; }
public List<LineSeries<double>> Series { get; set; }
public ViewModel()
{
Data = new ObservableCollection<double>();
Data.Add(1); Data.Add(2); Data.Add(5); Data.Add(4);
Series = new List<LineSeries<double>>();
Series.Add(new LineSeries<double> { Values = Data, Fill = null });
}
}
}
With the associated .Designer.cs in case it helps
namespace WinFormsDrawToBitmapTest
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panel2 = new System.Windows.Forms.Panel();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.cartesianChart1 = new LiveChartsCore.SkiaSharpView.WinForms.CartesianChart();
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.panel2.SuspendLayout();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// panel2
//
this.panel2.Controls.Add(this.button2);
this.panel2.Controls.Add(this.button1);
this.panel2.Dock = System.Windows.Forms.DockStyle.Top;
this.panel2.Location = new System.Drawing.Point(0, 0);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(1042, 24);
this.panel2.TabIndex = 1;
//
// button2
//
this.button2.Location = new System.Drawing.Point(167, 0);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(86, 23);
this.button2.TabIndex = 1;
this.button2.Text = "Change Tab1";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(0, 0);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(161, 23);
this.button1.TabIndex = 0;
this.button1.Text = "Get Tab1 as Image in Tab 2";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(0, 24);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(1042, 585);
this.tabControl1.TabIndex = 2;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.cartesianChart1);
this.tabPage1.Controls.Add(this.flowLayoutPanel1);
this.tabPage1.Location = new System.Drawing.Point(4, 24);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(1034, 557);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "tabPage1";
this.tabPage1.UseVisualStyleBackColor = true;
//
// cartesianChart1
//
this.cartesianChart1.Location = new System.Drawing.Point(8, 116);
this.cartesianChart1.Name = "cartesianChart1";
this.cartesianChart1.Size = new System.Drawing.Size(1018, 435);
this.cartesianChart1.TabIndex = 4;
//
// flowLayoutPanel1
//
this.flowLayoutPanel1.Location = new System.Drawing.Point(8, 6);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.Size = new System.Drawing.Size(1018, 100);
this.flowLayoutPanel1.TabIndex = 3;
//
// tabPage2
//
this.tabPage2.Controls.Add(this.pictureBox1);
this.tabPage2.Location = new System.Drawing.Point(4, 24);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
this.tabPage2.Size = new System.Drawing.Size(1034, 557);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "tabPage2";
this.tabPage2.UseVisualStyleBackColor = true;
//
// pictureBox1
//
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Location = new System.Drawing.Point(3, 3);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(1028, 551);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1042, 609);
this.Controls.Add(this.tabControl1);
this.Controls.Add(this.panel2);
this.Name = "Form1";
this.Text = "Form1";
this.panel2.ResumeLayout(false);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private Panel panel2;
private Button button1;
private TabControl tabControl1;
private TabPage tabPage1;
private TabPage tabPage2;
private PictureBox pictureBox1;
private FlowLayoutPanel flowLayoutPanel1;
private LiveChartsCore.SkiaSharpView.WinForms.CartesianChart cartesianChart1;
private Button button2;
}
}
Thank you for your help with this.
I have a problem creating a class that generates labels with specific weight and height, it works on the code, but doesn't show up on the form when I create the object. how I can solve this problem guys?
class cub
{
public int cubWeight = 150;
public int cubHeight = 150;
public void createNewCub()
{
Label cubLabel = new Label();
cubLabel.Size = new Size(cubWeight, cubHeight);
cubLabel.Text = "GeeksforGeeks";
cubLabel.Location = new Point(500, 200);
cubLabel.Font = new Font("Calibri", 18);
cubLabel.ForeColor = Color.Green;
cubLabel.Padding = new Padding(6);
}
}
public Form1()
{
InitializeComponent();
label1.Text = "Number of cubs: " + trackBar1.Value;
label2.Text = "Number of seconds: " + trackBar2.Value;
cub xxx = new cub();
xxx.createNewCub();
)
how I can solve this problem?
You can do like this: Edit from your code
public Form1()
{
InitializeComponent();
cub xxx = new cub();
this.Controls.Add(xxx.createNewCub()); // Add the Label
}
class cub
{
public int cubWeight = 150;
public int cubHeight = 150;
public Label createNewCub() //change void to Label
{
Label cubLabel = new Label();
cubLabel.Size = new Size(cubWeight, cubHeight);
cubLabel.Text = "GeeksforGeeks";
cubLabel.Location = new Point(500, 200);
cubLabel.Font = new Font("Calibri", 18);
cubLabel.ForeColor = Color.Green;
cubLabel.Padding = new Padding(6);
return cubLabel; //return label
}
}
I am trying to create a user control using a Windows Forms Panel and number of Labels with some text dynamically added to the Panel horizontally. I am trying with below code and the Labels get overridden.
public partial class AllergyBar : Panel
{
public AllergyBar()
: base()
{
InitializeComponent();
}
int X = 0, Y=0;
int height, width;
public AllergyBar(List<String> lstAlerts)
: base()
{
this.BackColor = System.Drawing.Color.WhiteSmoke;
this.Name = "panel2";
this.Size = new System.Drawing.Size(75, 23);
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
foreach (string alert in lstAlerts)
{
Label AllergyLabel = new Label();
AllergyLabel.Text = alert;
width = AllergyLabel.Size.Width;
Y = AllergyLabel.Location.Y;
AllergyLabel.Location = new System.Drawing.Point(X+width, Y);
AllergyLabel.Size = new System.Drawing.Size(75, 23);
AllergyLabel.AutoSize = true;
AllergyLabel.BorderStyle = BorderStyle.FixedSingle;
AllergyLabel.Dock = DockStyle.Fill;
this.Controls.Add(AllergyLabel);
}
InitializeComponent();
}
}
You have to update X value at the end of each loop:
public partial class AllergyBar : Panel
{
public AllergyBar(): base()
{
InitializeComponent();
}
int X = 0, Y=0;
int height, width;
public AllergyBar(List<String> lstAlerts): base()
{
InitializeComponent();
this.BackColor = System.Drawing.Color.WhiteSmoke;
this.Name = "panel2";
this.Size = new System.Drawing.Size(75, 23);
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
foreach (string alert in lstAlerts)
{
Label AllergyLabel = new Label();
AllergyLabel.Text = alert;
AllergyLabel.Location = new System.Drawing.Point(X, Y);
AllergyLabel.AutoSize = true;
AllergyLabel.BorderStyle = BorderStyle.FixedSingle;
AllergyLabel.Dock = DockStyle.Fill;
X += AllergyLabel.Width;
this.Controls.Add(AllergyLabel);
}
}
}
I made a custom form.
Now I'm trying to implement the feature to drag the form around while holding the titlebar. But it always throws this exception:
system.ObjectDisposedException
Has anyone an idea what the problem is?
This is my code:
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
Form form;
Button buttonCancel;
Button buttonOk;
DialogResult InputBox(string title, string promptText, ref string value)
{
form = new Form();
buttonCancel = new Button();
buttonOk = new Button();
Label label = new Label();
TextBox textBox = new TextBox();
Panel titlebar = new Panel();
Label lbltitle = new Label();
Panel pnlexit = new Panel();
Label lblexit = new Label();
form.Text = title;
label.Text = promptText;
textBox.Text = value;
buttonOk.Text = "OK";
buttonCancel.Text = "Cancel";
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = DialogResult.Cancel;
label.SetBounds(9, 20, 372, 13);
textBox.SetBounds(12, 36, 372, 20);
buttonOk.SetBounds(228, 72, 75, 23);
buttonCancel.SetBounds(309, 72, 75, 23);
buttonCancel.Location = new Point(250, 100);
buttonCancel.Parent = form;
buttonCancel.BackColor = ColorTranslator.FromHtml("#CDDC39");
buttonCancel.FlatStyle = FlatStyle.Flat;
buttonCancel.FlatAppearance.BorderSize = 0;
buttonCancel.MouseClick += ButtonCancel_MouseClick;
buttonOk.Location = new Point(170, 100);
buttonOk.Parent = form;
buttonOk.BackColor = ColorTranslator.FromHtml("#CDDC39");
buttonOk.FlatStyle = FlatStyle.Flat;
buttonOk.FlatAppearance.BorderSize = 0;
form.Height = 150;
form.Width = 350;
form.BackColor = ColorTranslator.FromHtml("#455A64");
form.FormBorderStyle = FormBorderStyle.None;
form.AutoSize = false;
form.StartPosition = FormStartPosition.CenterScreen;
form.AcceptButton = buttonOk;
form.CancelButton = buttonCancel;
titlebar.Width = form.Width;
titlebar.Height = 25;
titlebar.BackColor = ColorTranslator.FromHtml("#37474F");
titlebar.Parent = form;
titlebar.Controls.Add(pnlexit);
titlebar.MouseDown += Titlebar_MouseDown;
lblexit.Text = "X";
lblexit.Font = new Font("Arial", 9.5f, FontStyle.Bold);
lblexit.TextAlign = ContentAlignment.MiddleCenter;
lblexit.Dock = DockStyle.Fill;
lblexit.MouseClick += lblexit_click;
pnlexit.Height = titlebar.Height - 10;
pnlexit.Width = 30;
pnlexit.BackColor = ColorTranslator.FromHtml("#CDDC39");
pnlexit.Location = new Point(titlebar.Width - 33, 0);
pnlexit.Parent = titlebar;
pnlexit.Controls.Add(lblexit);
lbltitle.Parent = titlebar;
lbltitle.Text = title;
lbltitle.ForeColor = ColorTranslator.FromHtml("#CDDC39");
lbltitle.Font = new Font("Arial", 9.5f, FontStyle.Bold);
lbltitle.Location = new Point(5, 3);
label.AutoSize = true;
label.Location = new Point(25, 50);
label.Parent = form;
label.ForeColor = Color.White;
textBox.Parent = form;
textBox.Location = new Point(25, 65);
textBox.Width = 300;
DialogResult dialogResult = form.ShowDialog();
value = textBox.Text;
Console.WriteLine("Value = " + value);
return dialogResult;
}
private void Titlebar_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
private void ButtonCancel_MouseClick(object sender, MouseEventArgs e)
{
// throw new NotImplementedException();
}
private void lblexit_click(object sender, MouseEventArgs e)
{
form.Close();
}
i want to create a semi transparent form for overlay effect. the form should be see through.
this is the way i try to do it but it is not getting semi-transparent form. so please help me.
Form mMask = new Form();
mMask.FormBorderStyle = FormBorderStyle.None;
mMask.BackColor = Color.DarkGray;
mMask.Opacity = 0.10;
mMask.Height = this.ClientRectangle.Height;
mMask.Width = this.ClientRectangle.Width;
mMask.Top = 0;
mMask.Left = 0;
mMask.Text = this.Text;
mMask.AllowTransparency = true;
mMask.ShowInTaskbar = false;
mMask.StartPosition = FormStartPosition.Manual;
mMask.TopLevel = false;
this.Controls.Add(mMask);
mMask.Show();
mMask.BringToFront();
please guide me thanks.
i modify this routine and now it is as follow
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace dialog
{
public class MaskedDialog : Form
{
static MaskedDialog mask;
static Form frmContainer;
private Form dialog;
private UserControl ucDialog;
private MaskedDialog(Form parent, Form dialog)
{
this.dialog = dialog;
this.FormBorderStyle = FormBorderStyle.None;
this.BackColor = System.Drawing.Color.Black;
this.Opacity = 0.50;
this.ShowInTaskbar = false;
this.StartPosition = FormStartPosition.Manual;
this.Size = parent.ClientSize;
this.Location = parent.PointToScreen(System.Drawing.Point.Empty);
parent.Move += AdjustPosition;
parent.SizeChanged += AdjustPosition;
}
private MaskedDialog(Form parent, UserControl ucDialog)
{
this.ucDialog = ucDialog;
this.FormBorderStyle = FormBorderStyle.None;
this.BackColor = System.Drawing.Color.Black;
this.Opacity = 0.50;
this.ShowInTaskbar = false;
this.StartPosition = FormStartPosition.Manual;
this.Size = parent.ClientSize;
this.Location = parent.PointToScreen(System.Drawing.Point.Empty);
parent.Move += AdjustPosition;
parent.SizeChanged += AdjustPosition;
}
private void AdjustPosition(object sender, EventArgs e)
{
Form parent = sender as Form;
this.Location = parent.PointToScreen(System.Drawing.Point.Empty);
this.ClientSize = parent.ClientSize;
}
public static DialogResult ShowDialog(Form parent, Form dialog)
{
mask = new MaskedDialog(parent, dialog);
dialog.StartPosition = FormStartPosition.CenterParent;
mask.Show();
DialogResult result = dialog.ShowDialog(mask);
mask.Close();
return result;
}
public static DialogResult ShowDialog(Form parent, UserControl dialog)
{
mask = new MaskedDialog(parent, dialog);
frmContainer = new Form();
frmContainer.ShowInTaskbar = false;
frmContainer.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
frmContainer.StartPosition = FormStartPosition.CenterParent;
frmContainer.Height = dialog.Height;
frmContainer.Width = dialog.Width;
frmContainer.Controls.Add(dialog);
mask.Show();
DialogResult result = frmContainer.ShowDialog(mask);
frmContainer.Close();
mask.Close();
return result;
}
public static void CloseDialog()
{
if (frmContainer != null)
{
frmContainer.Close();
}
}
}
}
calling technique 1 with form
Form d = new Form();
d.Width = 400;
d.Height = 300;
MaskedDialog.ShowDialog(this, d);
calling technique 2 with form
UserControl1 uc = new UserControl1();
uc.CloseClicked += new UserControl1.CloseComplete(OnCloseClicked);
MaskedDialog.ShowDialog(this, uc);
void OnCloseClicked()
{
MaskedDialog.CloseDialog();
}
void Main()
{
var f = new Form
{
Width = 800,
Height = 600
};
var d = new Form
{
Width = 400,
Height = 300
};
var tb = new TextBox
{
Width = 250,
Height = 250,
Multiline = true,
Text = "Hello World",
Dock = DockStyle.Top
};
var b = new Button
{
Text = "Display Masked Dialog",
Dock = DockStyle.Top
};
b.Click += (s, e) =>
{
MaskedDialog.ShowDialog(f, d);
};
f.Controls.AddRange(new Control[] { tb, b } );
Application.Run(f);
}
public class MaskedDialog : Form
{
private Form dialog;
private MaskedDialog(Form parent, Form dialog)
{
this.dialog = dialog;
this.FormBorderStyle = FormBorderStyle.None;
this.BackColor = System.Drawing.Color.Black;
this.Opacity = 0.50;
this.ShowInTaskbar = false;
this.StartPosition = FormStartPosition.Manual;
this.Size = parent.ClientSize;
this.Location = parent.PointToScreen(System.Drawing.Point.Empty);
parent.Move += AdjustPosition;
parent.SizeChanged += AdjustPosition;
}
private void AdjustPosition(object sender, EventArgs e)
{
Form parent = sender as Form;
this.Location = parent.PointToScreen(System.Drawing.Point.Empty);
this.ClientSize = parent.ClientSize;
}
public static DialogResult ShowDialog(Form parent, Form dialog)
{
var mask = new MaskedDialog(parent, dialog);
dialog.StartPosition = FormStartPosition.CenterParent;
mask.Show();
var result = dialog.ShowDialog(mask);
mask.Close();
return result;
}
}