//文件:Program.csusing System;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            OpenFileDialog o = new OpenFileDialog();
            if (o.ShowDialog()==DialogResult.OK)
            {
                Application.Run(new Form1(o.FileName));
            }
            
        }
    }
}
//文件:Form1.csusing System;
using System.Drawing;using System.Windows.Forms;namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1(string fileName)
        {
            InitializeComponent();
            this.textBox1.Text = fileName;
        }
    }
}
这样的WinForm为什么From1打开的时候窗口不是现实在前面的(被其他窗口遮住了)?怎么解决?把TopMost设置为true不符合我的要求,因为我不想一直让Form1显示在屏幕最前面。只是在程序启动的时候要把它放在屏幕最前面。

解决方案 »

  1.   

    启动完你就不会把TopMost改成false啊
      

  2.   

    Form.Active()
    激活窗口,就在前面了
      

  3.   

    加载程序时            this.BringToFront();    //提到最前面
                this.Focus();           //获得焦点
      

  4.   

    试试:form.bringtofront();
    其实一楼的方法不错
      

  5.   

     你可以试试这个方法
    this.BringToFront();    //提到最前面下面的这个是可加可不加的 
     this.Focus();          //获得焦点
      

  6.   


    这个没用。在构造方法中将TopMost暂时改成true是没用的。我试过了。
      

  7.   


    我换了个系统。到XP下测试成功了。但是在Win7下始终不成功。
      

  8.   

    wo de ye shi win7   zhe dong xi bu hao 
      

  9.   


    借同学的Vista试了一下,仍然不行。看来这个代码只有XP行。Vista和Windows7都不行。
      

  10.   

    加载程序时 
    this.Activate();
      

  11.   

    让那个窗体获得焦点...并Active()
      

  12.   

    这个没用。试过了。在Vista和Windows7下没用。