/// <summary> /// Gets the index of the specified resolution if available /// </summary> /// <param name="g">The graphics mode</param> /// <param name="displayCompatableOnly">Include modes the video card can produce, but the monitor can't use.</param> /// <returns>Returns -1 if mode is not supported</returns> public int getIndexOfMode(graphicsMode g, bool displayCompatableOnly) { int i; graphicsMode[] modes = enumerateModes(displayCompatableOnly); for (i = 0; i < modes.Length; i++) { if (g.compare(modes[i]) == 0) { return(i); } } return(-1); }
/// <summary> /// Nearest Mode of less than or equal specs /// </summary> /// <param name="width">width of display mode</param> /// <param name="height">height of display mode</param> /// <param name="useNearest">find nearest is exact nt possible</param> /// <param name="newSize">The new display size</param> /// <returns>True if sucsessful, otherwise false.</returns> public bool changeToMode(int width, int height, bool useNearest, out Size newSize) { graphicsMode[] modes = availableModes; newSize = this.Bounds.Size; if (modes.Length <= 0) { return(false); } //are we already in a similar mode if ((this.Bounds.Size.Width == width) && (this.Bounds.Size.Height == height)) { return(true); } //lets not exceed 75Hz graphicsMode g = graphicsMode.fromSpecs(width, height, 32, 75); //changeResolution int nearest = -1; int i; for (i = 0; i < modes.Length; i++) { //-1 if other is less than, 1 if greater than, 0 if equal if (g.compare(modes[i]) <= 0) { if (nearest == -1) { nearest = i; } else { if (modes[nearest].compare(modes[i]) > 0) { nearest = i; } } } } //end for if (nearest == -1) { return(false); } if (!useNearest) { if (modes[nearest].dimensions.Width != width) { return(false); } if (modes[nearest].dimensions.Height != height) { return(false); } } ChangeDisplaySettingsReturnValue r = changeResolution(nearest, true, displayChangeType.noStartMenuOrToolBars); if (r == ChangeDisplaySettingsReturnValue.DISP_CHANGE_SUCCESSFUL) { newSize = modes[nearest].dimensions; return(true); } else { return(false); } }