Saturday, May 26, 2012

Problem with ShowDialog when ShowInTaskbar

ปัญหาเมื่่อ set form.ShowInTaskbar = false แล้วเวลาแสดง form จะ ไม่แสดงไว้หน้าสุด

form.ShowInTaskbar = false;

แก้ไขโดยกำหนด
public partial class Form1 : Form
{
    Form2 f2;

    public Form1()
    {
        InitializeComponent();

        f2 = new Form2();
        f2.Owner = this;  // <-- This is the important thing
        f2.Show();
    }
}
Example :

private void ShowInTaskBarEx()
{
    Form myForm = new Form();
    myForm.Text = "My Form";
    myForm.SetBounds(10,10,200,200);
    myForm.FormBorderStyle = FormBorderStyle.FixedDialog;
    myForm.MinimizeBox = false;
    myForm.MaximizeBox = false;
    // Do not allow form to be displayed in taskbar.
    myForm.ShowInTaskbar = false;
    myForm.ShowDialog();
}
ref : http://msdn.microsoft.com/en-us/library/system.windows.forms.form.showintaskbar(v=vs.80).aspx

No comments:

Post a Comment