做了个小程序VS2008 C#做的窗口程序,弹出FORM2提示信息.用f2.Show();这样显示他,设置为最上层topmost,userwaitcursor都设置的false 为什么第一次弹出,窗口不会是当前窗口,之后弹出就是当前窗口了?影响做其他事啊.

解决方案 »

  1.   

    lz是要f2显示在最前?
    f2.Show();
    f2.Activate();
    或者:
    f2.ShowDialog()
      

  2.   

    WindowState = System.Windows.Forms.FormWindowState.Minimized;  试试
      

  3.   


    用这个跟f2.Show();效果一样啊,第一次弹出不是当前,之后弹出就变当前窗口了.
      

  4.   

    f2.WindowState = System.Windows.Forms.FormWindowState.Minimized;  让窗体一出来最小化,
    或者试试这个API [DllImportAttribute("user32.dll")]         
    private static extern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow);
    Form2 f2=new Form2();
    ShowWindow(f2.Handle,4);
      

  5.   

    这样试试,这是效果不? Form2 frm = new Form2();
     frm.Show();
     frm.TopMost = true;
     this.Focus();
      

  6.   

    不知道你是不是想要类似于QQ右下角弹出提示框的效果?
    是的话用下面的API就ok
    [c#]
            protected const Int32 HWND_TOPMOST = -1;
            protected const Int32 SWP_NOACTIVATE = 0x0010;
            protected const Int32 SW_SHOWNOACTIVATE = 4;
            [DllImport("user32.dll")]
            protected static extern bool ShowWindow(IntPtr hWnd, Int32 flags);
            [DllImport("user32.dll")]
            protected static extern bool SetWindowPos(IntPtr hWnd, Int32 hWndInsertAfter, Int32 X, Int32 Y, Int32 cx, Int32 cy, uint uFlags);            ShowWindow(Handle, SW_SHOWNOACTIVATE);
                SetWindowPos(Handle, HWND_TOPMOST, tmpRectangle.Right - this.Width, tmpRectangle.Bottom, Width, Height, SWP_NOACTIVATE);
    [/c#]
      

  7.   


     Form1 f = new Form1();
                f.TopMost = true;//这样出来的f不会获得焦点 但是会遮住当前窗体。 
    你把上面那句改成看看效果f.TopMost = false;//
                f.UseWaitCursor = true;
                f.Show();
                this.Activate();
      

  8.   


    我不要F2当前啊,this.Focus();直接让他当前了
      

  9.   

    弹出窗体不在最上一层那开窗体做什么啊?
    几种方法
    打开窗体最小化,设置窗体的WindowState 属性
    打开窗体后隐藏,frm2.Hide();
    打开窗体后主窗体继续获得焦点!
      

  10.   


           //这样打开的窗体不会聚焦.
           //引用程序集
            using System.Runtime.InteropServices;        [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public extern static IntPtr SetParent(IntPtr hChild, IntPtr hParent);        [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern IntPtr GetDesktopWindow();         //打开窗体时:
            f2 frm = new f2();
            frm.TopLevel = false;
            frm.Parent = this;
            frm.Show();
            SetParent(frm.Handle, GetDesktopWindow()); 
      

  11.   


    实际测试一下就知道了:
    frm.Show();  执行后,Form2获得焦点
    this.Focus(); 执行后,当前(Form1)获得焦点.
      

  12.   

    难道用这个API不行吗,你控制好位置,看看你能不能在主窗体中继续输入,yd
      

  13.   

     private void button1_Click(object sender, EventArgs e)
            {
                Form3 f = new Form3();
                f.Location = new Point(300, 300);
                f.Show();
                this.Focus();
    }
    这样?好像比较土
      

  14.   

    因为你在设置为TOPMOST时。别人的窗口也是TOPMOST。别人的窗口也是这个级别。可能。NET默认显示不是最上一级。好象有个API也可把他设置第一级窗口。用这个API可以直接显示为最顶级。
      

  15.   


    主窗体(你打开form2的窗体) 
     [DllImportAttribute("user32.dll")]         
    private static extern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow);
    private void textBox1_TextChanged(object sender, EventArgs e)
            {
                Form3 f2 = new Form3();
                f2.Location = new Point(0, 0);
                ShowWindow(f2.Handle, 4);
            }[code=C#]
    直接给代码 看看效果
      

  16.   


    没什么代码啊,F2设置topmost true,userwaitcursor false 然后f1上执行f2.show 让他显示就这简单啊
      

  17.   

    textBox1_TextChanged???????
      

  18.   

    你想f2什么时候出来  Form2 f2=new Form2();
                f2.Location=new Point(0,0);
                ShowWindow(f2.Handle,4);   就写那  我是写在textbox值变化的事件中,看效果的
      

  19.   

    public FormXX()
          {
              InitializeComponent();//把你这方法里的代码发上来
          }
      

  20.   

    [DllImportAttribute("user32.dll")]privatestaticextern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow);这东西放上去报错啊
      

  21.   

    using System.Runtime.InteropServices;
      

  22.   


    有空间啊,报错:错误 1 应输入 ; D:\学习\C#\作业\first\first\Form1.cs 32 71 first
      

  23.   


            [DllImportAttribute("user32.dll")]privatestaticextern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow);这个放哪都报错
      

  24.   

    例如 :
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
     public Form1()
            {
                
                InitializeComponent();
            }
            [DllImportAttribute("user32.dll")]         
    private static extern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow);
    }
      

  25.   

    可以这样,弹出的窗口虽然是获取焦点的窗口,你可以再它的Active事件里,将原先你操作的窗体Actived属性设为TRUE
      

  26.   

    在你的窗体里添加如下的重写:protected override bool ShowWithoutActivation
    {
    get
    {
    return true;
    }
    }
    这样后,使用正常的Show方法显示窗体,窗体不会得到输入焦点,除非你后来再使它得到焦点。
      

  27.   

    把下面代码放到你的FORM类中,根据你主贴的说明,这个代码就是答案。[DllImportAttribute("user32.dll")]
    public static extern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow);
    private void button1_Click(object sender, EventArgs e)
    {
        Form f2 = new Form();                                                     // Form类 换成你的FORM 
        f2.TopMost = true;
        f2.ControlBox = false; // 也可以显示
        f2.ShowInTaskbar = false;
        Control.FromHandle(f2.Handle).Location = new Point(Screen.PrimaryScreen.Bounds.Width - f2.Width, 0);
        ShowWindow(f2.Handle, 4);
        this.Focus();
    }
      

  28.   

    gSf.Owner = 你显示F2的父级窗口;
    gSf.Show();
    gSf.Owner.Activate();
      

  29.   

    f2.Owner = this;
    f2.Show();
    f2.Owner.Activate();
    试了,没效果,依然第一次不聚焦,之后一样聚焦
      

  30.   


    我qq472359106 或则可以告诉你的qq号吗?        private void timer1_Tick(object sender, EventArgs e)
            {
                try
                {
                    SqlConnection conn = new SqlConnection(yh_conn_str);
                    conn.Open();
                    SqlCommand cmd = conn.CreateCommand();
                    cmd.CommandText = yh_conn_sql;
                    cmd.CommandType = CommandType.Text;
                    SqlDataReader dd = cmd.ExecuteReader();                while (dd.Read())
                    {
                        bool go_check = true;
                        if (File.Exists(Application.StartupPath + "\\" + file_name_2))
                        {
                            string rw_str = show_text(file_name_2);                        String str_1 = rw_str;
                            String str_2 = dd["w_gx"].ToString();
                            if (str_1 == str_2) { go_check = false; }
                        }                    if (!cb_bhip.Checked && dd["w_ip"].ToString() == "不换") { go_check = false; }
                        if (!cb_hip.Checked && dd["w_ip"].ToString() == "需换") { go_check = false; }
                        if (!cb_zd.Checked && dd["w_zd"].ToString() == "自动") { go_check = false; }
                        if (!cb_sg.Checked && dd["w_zd"].ToString() == "手工") { go_check = false; }
                        if (!cb_qq.Checked && dd["w_lx"].ToString() == "QQ任务") { go_check = false; }                    if (go_check)
                        {
                            Form2 f2 = new Form2();
                            f2.Text = yh_name + "-新任务提醒窗口";
                            f2.tb_yh.Text = yh_url;
                            f2.ll_yh.Text = yh_name;
                            f2.tb_bc.Text = dd["w_bc"].ToString();
                            f2.tb_rj.Text = dd["w_rj"].ToString();
                            f2.tb_ht.Text = dd["w_ht"].ToString();                        f2.tb_jg.Text = "会员:" + dd["w_hy"].ToString();
                            f2.tb_jg.Text += "分,提成:" + dd["w_tc"].ToString();
                            f2.tb_jg.Text += "分,第一:" + dd["w_dy"].ToString() + "分";                        f2.tb_xz.Text = dd["w_zd"].ToString() + " " + dd["w_ip"].ToString() + "ip" + " " + dd["w_lx"].ToString();
                            f2.tb_gh.Text = dd["w_gh"].ToString() + this.textBox1.Text;
                            f2.tb_rw.Text = dd["w_bh"].ToString() + "/" + dd["w_rw"].ToString();
                            f2.tb_sj.Text = dd["w_sj"].ToString();                        WriteFile(dd["w_gx"].ToString(), file_name_2);
                            if (cb_sy.Checked) { my_music(); }                        //f2.Show();
                            //f2.ShowDialog();
                            //f2.ScrollShow();                        //f2.Owner = this;
                            f2.Show();
                            //f2.Owner.Activate();                        //Form f2 = new Form();                                                     // Form类 换成你的FORM 
                            //f2.TopMost = true;
                            //f2.ControlBox = false; // 也可以显示
                            //f2.ShowInTaskbar = false;
                           // Control.FromHandle(f2.Handle).Location = new Point(Screen.PrimaryScreen.Bounds.Width - f2.Width, 0);
                            //ShowWindow(f2.Handle, 4);
                            //this.Focus();
                            GC.Collect();
                        }
                    }
                    dd.Close();
                    conn.Close();
                    this.timer1.Interval = 6000;//0
                    this.Text = yh_name + "-任务提醒工具v" + banben;
                }
                catch 
                { 
                    this.Text="获取数据出错!";
                    this.timer1.Interval = 1000;
                }