当前位置: 首页>>代码示例>>C#>>正文


C# Form.Focus方法代码示例

本文整理汇总了C#中Form.Focus方法的典型用法代码示例。如果您正苦于以下问题:C# Form.Focus方法的具体用法?C# Form.Focus怎么用?C# Form.Focus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Form的用法示例。


在下文中一共展示了Form.Focus方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateGlWindow


//.........这里部分代码省略.........
            dmScreenSettings.dmPelsWidth = width;                           // Selected Screen Width
            dmScreenSettings.dmPelsHeight = height;                         // Selected Screen Height
            dmScreenSettings.dmBitsPerPel = bits;                           // Selected Bits Per Pixel
            dmScreenSettings.dmFields = Gdi.DM_BITSPERPEL | Gdi.DM_PELSWIDTH | Gdi.DM_PELSHEIGHT;

            // Try To Set Selected Mode And Get Results.  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
            fullscreen = true;
        }

        form = new QuadricDemo();                                              // Create The Window

        form.Width = width;                                                 // Set Window Width
        form.Height = height;                                               // Set Window Height
        form.Text = title;

        #region WINDOW CREATION STUFF
        Gdi.PIXELFORMATDESCRIPTOR pfd = new Gdi.PIXELFORMATDESCRIPTOR();    // pfd Tells Windows How We Want Things To Be
        pfd.nSize = (short)Marshal.SizeOf(pfd);                            // Size Of This Pixel Format Descriptor
        pfd.nVersion = 1;                                                   // Version Number
        pfd.dwFlags = Gdi.PFD_DRAW_TO_WINDOW |                              // Format Must Support Window
            Gdi.PFD_SUPPORT_OPENGL |                                        // Format Must Support OpenGl
            Gdi.PFD_DOUBLEBUFFER;                                           // Format Must Support Double Buffering
        pfd.iPixelType = (byte)Gdi.PFD_TYPE_RGBA;                          // Request An RGBA Format
        pfd.cColorBits = (byte)bits;                                       // Select Our Color Depth
        pfd.cRedBits = 0;                                                   // Color Bits Ignored
        pfd.cRedShift = 0;
        pfd.cGreenBits = 0;
        pfd.cGreenShift = 0;
        pfd.cBlueBits = 0;
        pfd.cBlueShift = 0;
        pfd.cAlphaBits = 0;                                                 // No Alpha Buffer
        pfd.cAlphaShift = 0;                                                // Shift Bit Ignored
        pfd.cAccumBits = 0;                                                 // No Accumulation Buffer
        pfd.cAccumRedBits = 0;                                              // Accumulation Bits Ignored
        pfd.cAccumGreenBits = 0;
        pfd.cAccumBlueBits = 0;
        pfd.cAccumAlphaBits = 0;
        pfd.cDepthBits = 16;                                                // 16Bit Z-Buffer (Depth Buffer)
        pfd.cStencilBits = 0;                                               // No Stencil Buffer
        pfd.cAuxBuffers = 0;                                                // No Auxiliary Buffer
        pfd.iLayerType = (byte)Gdi.PFD_MAIN_PLANE;                         // Main Drawing Layer
        pfd.bReserved = 0;                                                  // Reserved
        pfd.dwLayerMask = 0;                                                // Layer Masks Ignored
        pfd.dwVisibleMask = 0;
        pfd.dwDamageMask = 0;

        hDC = User.GetDC(form.Handle);                                      // Attempt To Get A Device Context
        if (hDC == IntPtr.Zero)
        {                                            // Did We Get A Device Context?
            KillGlWindow();                                                 // Reset The Display
            MessageBox.Show("Can't Create A Gl Device Context.", "ERROR",
                MessageBoxButtons.OK, MessageBoxIcon.Error);
            return false;
        }

        pixelFormat = Gdi.ChoosePixelFormat(hDC, ref pfd);                  // Attempt To Find An Appropriate Pixel Format
        if (pixelFormat == 0)
        {                                              // Did Windows Find A Matching Pixel Format?
            KillGlWindow();                                                 // Reset The Display
            MessageBox.Show("Can't Find A Suitable PixelFormat.", "ERROR",
                MessageBoxButtons.OK, MessageBoxIcon.Error);
            return false;
        }

        if (!Gdi.SetPixelFormat(hDC, pixelFormat, ref pfd))
        {                // Are We Able To Set The Pixel Format?
            KillGlWindow();                                                 // Reset The Display
            MessageBox.Show("Can't Set The PixelFormat.", "ERROR",
                MessageBoxButtons.OK, MessageBoxIcon.Error);
            return false;
        }

        hRC = Wgl.wglCreateContext(hDC);                                    // Attempt To Get The Rendering Context
        if (hRC == IntPtr.Zero)
        {                                            // Are We Able To Get A Rendering Context?
            KillGlWindow();                                                 // Reset The Display
            MessageBox.Show("Can't Create A Gl Rendering Context.", "ERROR",
                MessageBoxButtons.OK, MessageBoxIcon.Error);
            return false;
        }

        if (!Wgl.wglMakeCurrent(hDC, hRC))
        {                                 // Try To Activate The Rendering Context
            KillGlWindow();                                                 // Reset The Display
            MessageBox.Show("Can't Activate The Gl Rendering Context.", "ERROR",
                MessageBoxButtons.OK, MessageBoxIcon.Error);
            return false;
        }
        #endregion

        form.Show();                                                        // Show The Window
        form.Focus();                                                       // Focus The Window

        InitGl();                                                            //Initiate OpenGl

        setViewport(width, height);                                          // Set viewport
        setPerspective(width, height);                                       // Set Up Our Perspective Gl Screen

        return true;                                                         // Success
    }
开发者ID:jjaspe,项目名称:Libraries,代码行数:101,代码来源:Program.cs


注:本文中的Form.Focus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。