我试图找到一种方法让窗口始终位于顶部。 (它必须处于窗口模式) 我目前正在使用 OpenTk.NetCore 库在.net核心中创建一个窗口。 是否可以使用OpenTk将此窗口保持在顶部或是否有其他方式?它必须是 in .Net core ...
我目前的代码:
public class Display : GameWindow
{
public Display() : base(400, 300, GraphicsMode.Default)
{
//display window in top left corner
this.X = 0;
this.Y = 0;
//TODO : window should always been displayed on top
VSync = VSyncMode.On;
WindowBorder = WindowBorder.Hidden; //no title & border
//WindowState = WindowState.Fullscreen;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
GL.Enable(EnableCap.DepthTest);
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
GL.Viewport(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height);
Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, Width / (float)Height, 1.0f, 64.0f);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadMatrix(ref projection);
}
protected override void OnUpdateFrame(FrameEventArgs e)
{
base.OnUpdateFrame(e);
if (Keyboard[Key.Escape])
Exit();
}
protected override void OnRenderFrame(FrameEventArgs e)
{
base.OnRenderFrame(e);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadMatrix(ref modelview);
GL.Begin(PrimitiveType.Triangles);
GL.Color3(1.0f, 0.0f, 0.0f); GL.Vertex3(2.0f, 1.0f, 4.0f);
GL.Color3(1.0f, 0.0f, 0.0f); GL.Vertex3(1.2f, 1.0f, 4.0f);
GL.Color3(1.0f, 0.0f, 0.0f); GL.Vertex3(1.6f, 1.5f, 4.0f);
GL.End();
SwapBuffers();
}
}
public class Program
{
[STAThread]
public static void Main(string[] args)
{
/*
* The 'using' idiom guarantees proper resource cleanup.
* We request 30 UpdateFrame events per second, and 30
* RenderFrame events.
*/
using (Display display = new Display())
{
display.Run(30.0,30.0);
}
}
}
答案 0 :(得分:1)
OpenTK并不支持此功能。您可以检测窗口的焦点,位置,大小等何时发生变化,但我不相信您可以直接影响焦点。
此外,至少在Windows上,并不存在任何合法的"实现这一目标的方法是,无法保证Windows中的任何一个程序始终高于其他程序。您可以尝试尝试各种事情,例如检测窗口焦点何时丢失(NativeWindow.FocusChanged
),然后调用某些user32函数,如SetForegroundWindow,BringWindowToTop等,但它可以尝试一场艰苦的战斗并不是真的可取。其他操作系统/窗口管理器可能对此有不同的支持。