📄 d3dsettingsform.cs
字号:
//
// windowedRadioButton
//
this.windowedRadioButton.Location = new System.Drawing.Point(9, 14);
this.windowedRadioButton.Name = "windowedRadioButton";
this.windowedRadioButton.Size = new System.Drawing.Size(152, 24);
this.windowedRadioButton.TabIndex = 0;
this.windowedRadioButton.Text = "&Windowed";
this.windowedRadioButton.CheckedChanged += new System.EventHandler(this.WindowedFullscreenChanged);
//
// resolutionLabel
//
this.resolutionLabel.Location = new System.Drawing.Point(8, 94);
this.resolutionLabel.Name = "resolutionLabel";
this.resolutionLabel.Size = new System.Drawing.Size(152, 23);
this.resolutionLabel.TabIndex = 4;
this.resolutionLabel.Text = "&Resolution:";
//
// refreshRateComboBox
//
this.refreshRateComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.refreshRateComboBox.DropDownWidth = 144;
this.refreshRateComboBox.Location = new System.Drawing.Point(161, 118);
this.refreshRateComboBox.MaxDropDownItems = 14;
this.refreshRateComboBox.Name = "refreshRateComboBox";
this.refreshRateComboBox.Size = new System.Drawing.Size(232, 21);
this.refreshRateComboBox.TabIndex = 7;
this.refreshRateComboBox.SelectedIndexChanged += new System.EventHandler(this.RefreshRateChanged);
//
// adapterFormatLabel
//
this.adapterFormatLabel.Location = new System.Drawing.Point(8, 72);
this.adapterFormatLabel.Name = "adapterFormatLabel";
this.adapterFormatLabel.Size = new System.Drawing.Size(152, 23);
this.adapterFormatLabel.TabIndex = 2;
this.adapterFormatLabel.Text = "Adapter F&ormat:";
//
// refreshRateLabel
//
this.refreshRateLabel.Location = new System.Drawing.Point(8, 118);
this.refreshRateLabel.Name = "refreshRateLabel";
this.refreshRateLabel.Size = new System.Drawing.Size(152, 23);
this.refreshRateLabel.TabIndex = 6;
this.refreshRateLabel.Text = "R&efresh Rate:";
//
// okButton
//
this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
this.okButton.Location = new System.Drawing.Point(112, 464);
this.okButton.Name = "okButton";
this.okButton.TabIndex = 3;
this.okButton.Text = "OK";
//
// modeSettingsGroupBox
//
this.modeSettingsGroupBox.Controls.AddRange(new System.Windows.Forms.Control[] {
this.adapterFormatLabel,
this.refreshRateLabel,
this.resolutionComboBox,
this.adapterFormatComboBox,
this.resolutionLabel,
this.refreshRateComboBox,
this.windowedRadioButton,
this.fullscreenRadioButton});
this.modeSettingsGroupBox.Location = new System.Drawing.Point(16, 96);
this.modeSettingsGroupBox.Name = "modeSettingsGroupBox";
this.modeSettingsGroupBox.Size = new System.Drawing.Size(400, 160);
this.modeSettingsGroupBox.TabIndex = 1;
this.modeSettingsGroupBox.TabStop = false;
this.modeSettingsGroupBox.Text = "Display mode settings";
//
// adapterFormatComboBox
//
this.adapterFormatComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.adapterFormatComboBox.DropDownWidth = 121;
this.adapterFormatComboBox.Location = new System.Drawing.Point(161, 70);
this.adapterFormatComboBox.MaxDropDownItems = 14;
this.adapterFormatComboBox.Name = "adapterFormatComboBox";
this.adapterFormatComboBox.Size = new System.Drawing.Size(232, 21);
this.adapterFormatComboBox.TabIndex = 3;
this.adapterFormatComboBox.SelectedValueChanged += new System.EventHandler(this.AdapterFormatChanged);
//
// D3DSettingsForm
//
this.AcceptButton = this.okButton;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(438, 512);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.cancelButton,
this.okButton,
this.adapterDeviceGroupBox,
this.modeSettingsGroupBox,
this.otherSettingsGroupBox});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "D3DSettingsForm";
this.Text = "Direct3D Settings";
this.adapterDeviceGroupBox.ResumeLayout(false);
this.otherSettingsGroupBox.ResumeLayout(false);
this.modeSettingsGroupBox.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// Respond to a change of selected adapter by rebuilding the device
/// list. Updating the selected device will trigger updates of the
/// rest of the dialog.
/// </summary>
private void AdapterChanged(object sender, System.EventArgs e) {
GraphicsAdapterInfo adapterInfo = (GraphicsAdapterInfo)adapterComboBox.SelectedItem;
settings.AdapterInfo = adapterInfo;
// Update device combo box
deviceComboBox.Items.Clear();
foreach (GraphicsDeviceInfo deviceInfo in adapterInfo.DeviceInfoList) {
deviceComboBox.Items.Add(deviceInfo);
if (deviceInfo.DevType == settings.DevType)
deviceComboBox.SelectedItem = deviceInfo;
}
if (deviceComboBox.SelectedItem == null && deviceComboBox.Items.Count > 0)
deviceComboBox.SelectedIndex = 0;
}
/// <summary>
/// Respond to a change of selected device by resetting the
/// fullscreen/windowed radio buttons. Updating these buttons
/// will trigger updates of the rest of the dialog.
/// </summary>
private void DeviceChanged(object sender, System.EventArgs e) {
GraphicsAdapterInfo adapterInfo = (GraphicsAdapterInfo)adapterComboBox.SelectedItem;
GraphicsDeviceInfo deviceInfo = (GraphicsDeviceInfo)deviceComboBox.SelectedItem;
settings.DeviceInfo = deviceInfo;
// Update fullscreen/windowed radio buttons
bool HasWindowedDeviceCombo = false;
bool HasFullscreenDeviceCombo = false;
foreach (DeviceCombo deviceCombo in deviceInfo.DeviceComboList) {
if (deviceCombo.IsWindowed)
HasWindowedDeviceCombo = true;
else
HasFullscreenDeviceCombo = true;
}
windowedRadioButton.Enabled = HasWindowedDeviceCombo;
fullscreenRadioButton.Enabled = HasFullscreenDeviceCombo;
if (settings.IsWindowed && HasWindowedDeviceCombo) {
windowedRadioButton.Checked = true;
}
else {
fullscreenRadioButton.Checked = true;
}
WindowedFullscreenChanged(null, null);
}
/// <summary>
/// Respond to a change of windowed/fullscreen state by rebuilding the
/// adapter format list, resolution list, and refresh rate list.
/// Updating the selected adapter format will trigger updates of the
/// rest of the dialog.
/// </summary>
private void WindowedFullscreenChanged(object sender, System.EventArgs e) {
GraphicsAdapterInfo adapterInfo = (GraphicsAdapterInfo)adapterComboBox.SelectedItem;
GraphicsDeviceInfo deviceInfo = (GraphicsDeviceInfo)deviceComboBox.SelectedItem;
if (windowedRadioButton.Checked) {
settings.IsWindowed = true;
settings.WindowedAdapterInfo = adapterInfo;
settings.WindowedDeviceInfo = deviceInfo;
// Update adapter format combo box
adapterFormatComboBox.Items.Clear();
adapterFormatComboBox.Items.Add(settings.WindowedDisplayMode.Format);
adapterFormatComboBox.SelectedIndex = 0;
adapterFormatComboBox.Enabled = false;
// Update resolution combo box
resolutionComboBox.Items.Clear();
resolutionComboBox.Items.Add(FormatResolution(settings.WindowedDisplayMode.Width,
settings.WindowedDisplayMode.Height));
resolutionComboBox.SelectedIndex = 0;
resolutionComboBox.Enabled = false;
// Update refresh rate combo box
refreshRateComboBox.Items.Clear();
refreshRateComboBox.Items.Add(FormatRefreshRate(settings.WindowedDisplayMode.RefreshRate));
refreshRateComboBox.SelectedIndex = 0;
refreshRateComboBox.Enabled = false;
}
else {
settings.IsWindowed = false;
settings.FullscreenAdapterInfo = adapterInfo;
settings.FullscreenDeviceInfo = deviceInfo;
// Update adapter format combo box
adapterFormatComboBox.Items.Clear();
foreach (DeviceCombo deviceCombo in deviceInfo.DeviceComboList) {
if (deviceCombo.IsWindowed)
continue;
if (!adapterFormatComboBox.Items.Contains(deviceCombo.AdapterFormat)) {
adapterFormatComboBox.Items.Add(deviceCombo.AdapterFormat);
if (deviceCombo.AdapterFormat == (settings.IsWindowed ?
settings.WindowedDisplayMode.Format : settings.FullscreenDisplayMode.Format)) {
adapterFormatComboBox.SelectedItem = deviceCombo.AdapterFormat;
}
}
}
if (adapterFormatComboBox.SelectedItem == null && adapterFormatComboBox.Items.Count > 0)
adapterFormatComboBox.SelectedIndex = 0;
adapterFormatComboBox.Enabled = true;
// Update resolution combo box
resolutionComboBox.Enabled = true;
// Update refresh rate combo box
refreshRateComboBox.Enabled = true;
}
}
/// <summary>
/// Converts the given width and height into a formatted string
/// </summary>
private string FormatResolution(int width, int height) {
System.Text.StringBuilder sb = new System.Text.StringBuilder(20);
sb.AppendFormat("{0} by {1}", width, height);
return sb.ToString();
}
/// <summary>
/// Converts the given refresh rate into a formatted string
/// </summary>
private string FormatRefreshRate(int refreshRate) {
if (refreshRate == 0) {
return "Default Rate";
}
else {
System.Text.StringBuilder sb = new System.Text.StringBuilder(20);
sb.AppendFormat("{0} Hz", refreshRate);
return sb.ToString();
}
}
/// <summary>
/// Respond to a change of selected adapter format by rebuilding the
/// resolution list and back buffer format list. Updating the selected
/// resolution and back buffer format will trigger updates of the rest
/// of the dialog.
/// </summary>
private void AdapterFormatChanged(object sender, System.EventArgs e) {
if (!windowedRadioButton.Checked) {
GraphicsAdapterInfo adapterInfo = (GraphicsAdapterInfo)adapterComboBox.SelectedItem;
Format adapterFormat = (Format)adapterFormatComboBox.SelectedItem;
settings.FullscreenDisplayMode.Format = adapterFormat;
System.Text.StringBuilder sb = new System.Text.StringBuilder(20);
resolutionComboBox.Items.Clear();
foreach (DisplayMode displayMode in adapterInfo.DisplayModeList) {
if (displayMode.Format == adapterFormat) {
string resolutionString = FormatResolution(displayMode.Width, displayMode.Height);
if (!resolutionComboBox.Items.Contains(resolutionString)) {
resolutionComboBox.Items.Add(resolutionString);
if (settings.FullscreenDisplayMode.Width == displayMode.Width &&
settings.FullscreenDisplayMode.Height == displayMode.Height) {
resolutionComboBox.SelectedItem = resolutionString;
}
}
}
}
if (resolutionComboBox.SelectedItem == null && resolutionComboBox.Items.Count > 0)
resolutionComboBox.SelectedIndex = 0;
}
// Update backbuffer format combo box
GraphicsDeviceInfo deviceInfo = (GraphicsDeviceInfo)deviceComboBox.SelectedItem;
backBufferFormatComboBox.Items.Clear();
foreach (DeviceCombo deviceCombo in deviceInfo.DeviceComboList) {
if (deviceCombo.IsWindowed == settings.IsWindowed &&
deviceCombo.AdapterFormat == settings.DisplayMode.Format) {
if (!backBufferFormatComboBox.Items.Contains(deviceCombo.BackBufferFormat)) {
backBufferFormatComboBox.Items.Add(deviceCombo.BackBufferFormat);
if (deviceCombo.BackBufferFormat == settings.BackBufferFormat)
backBufferFormatComboBox.SelectedItem = deviceCombo.BackBufferFormat;
}
}
}
if (backBufferFormatComboBox.SelectedItem == null && backBufferFormatComboBox.Items.Count > 0)
backBufferFormatComboBox.SelectedIndex = 0;
}
/// <summary>
/// Respond to a change of selected resolution by rebuilding the
/// refresh rate list.
/// </summary>
private void ResolutionChanged(object sender, System.EventArgs e) {
if (settings.IsWindowed)
return;
GraphicsAdapterInfo adapterInfo = (GraphicsAdapterInfo)adapterComboBox.SelectedItem;
// Update settings with new resolution
string resolution = (string)resolutionComboBox.SelectedItem;
string[] resolutionSplitStringArray = resolution.Split();
int width = int.Parse(resolutionSplitStringArray[0]);
int height = int.Parse(resolutionSplitStringArray[2]);
settings.FullscreenDisplayMode.Width = width;
settings.FullscreenDisplayMode.Height = height;
// Update refresh rate list based on new resolution
Format adapterFormat = (Format)adapterFormatComboBox.SelectedItem;
refreshRateComboBox.Items.Clear();
foreach (DisplayMode displayMode in adapterInfo.DisplayModeList) {
if (displayMode.Format == adapterFormat &&
displayMode.Width == width &&
displayMode.Height == height) {
string refreshRateString = FormatRefreshRate(displayMode.RefreshRate);
if (!refreshRateComboBox.Items.Contains(refreshRateString)) {
refreshRateComboBox.Items.Add(refreshRateString);
if (settings.FullscreenDisplayMode.RefreshRate == displayMode.RefreshRate)
refreshRateComboBox.SelectedItem = refreshRateString;
}
}
}
if (refreshRateComboBox.SelectedItem == null && refreshRateComboBox.Items.Count > 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -