写了一个小播放器,想在玩游戏的时候用,但是一进游戏就没法置顶了。求方法,this.TopMost = true;也不管用C#

解决方案 »

  1.   

    没有办法,有些游戏是使用directx绘制屏幕的。dx的屏幕和gdi绘制的界面根本就不能在一起。建议你用多个显示器,一边运行你的程序,一边玩吧。
      

  2.   

    添加引用和代码,
     using System.Runtime.InteropServices;        [DllImport("user32.dll", EntryPoint = "SetWindowPos")]        public static extern int SetWindowPos(        int hwnd,        int hWndInsertAfter,        int x,        int y,        int cx,        int cy,       int wFlags        );        [DllImport("user32.dll", EntryPoint = "FindWindow")]        public static extern int FindWindow(        string lpClassName,        string lpWindowName        );然后在
    Form_Load中加入如下语句即可: retValue = SetWindowPos(Me.hwnd, HWND_TOPMOST, Me.CurrentX, Me.CurrentY, 300, 300, SWP_SHOWWINDOW)   这样窗体就能保持在所有窗体的前面了。
    C#窗口前置 前端显示 .NET技术 
    作者:王铭    出处:夜来居    2009-6-12 22:27:10 
      

  3.   

    刚才有个参数错了,using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;namespace text
    {
        public partial class Form1 : Form
        {
            [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
            public static extern int SetWindowPos(
                IntPtr hwnd,
                int hWndInsertAfter,
                int x,
                int y,
                int cx,
                int cy,
                int wFlags
            );
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                int a = SetWindowPos(this.Handle, -1, Screen.PrimaryScreen.Bounds.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2, this.Width, this.Height, 0);
            }
        }
    }新建了一个窗体,完整代码,测试可用。
      

  4.   


    知道这代码什么意思比“完整代码,测试可用”有效多了。这个“作者:王铭”似乎有了大发现,可喜可贺。可是人家微软早就把SetWindowPos(SWP_TOPMOST)封装到了Form的TopMost属性中啦。
      

  5.   

    5楼估计是对的,我只在MFC中将窗口置顶过,也是在生产窗口的代码里添加了一段代码
      

  6.   


    惊现版主!感谢指点~
    虽然没查过内人是谁,但是当初靠这方法解决了很多问题~
    作为伸手党,直接copy了网页代码留档,
    如今有人问了就发出来交流交流~
    嘛~只是现在才知道form自带顶置~ 囧~~~
    另外,电脑只有一个显示器接口的话,只能插一个显示器,换个带双接口的显卡吧~