Fixed problems with DataGridView DoubleBuffered property using reflection

This commit is contained in:
AdAstra-LD 2021-01-31 02:12:34 +01:00
parent 6046ae6712
commit bfdfe89279
5 changed files with 28 additions and 22 deletions

View File

@ -92,6 +92,7 @@
<Compile Include="AB.cs" />
<Compile Include="AreaData.cs" />
<Compile Include="DSUtils.cs" />
<Compile Include="ExtensionMethods.cs" />
<Compile Include="PokeDatabase.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
@ -179,9 +180,6 @@
<Compile Include="ScriptFile.cs" />
<Compile Include="Matrix.cs" />
<Compile Include="EventFile.cs" />
<Compile Include="DataGridViewDoubleBuffered.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="LibNDSFormats\bytearrayoutputstream.cs" />
<Compile Include="LibNDSFormats\convertir.cs" />
<Compile Include="LibNDSFormats\EndianBinaryReader.cs" />

View File

@ -1,12 +0,0 @@
// DataGridView with double buffering to speed up performance
using System.Windows.Forms;
namespace DSPRE
{
public class DataGridViewDoubleBuffered : DataGridView {
public DataGridViewDoubleBuffered() {
DoubleBuffered = true;
}
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DSPRE {
public static class ExtensionMethods {
public static void DoubleBuffered(this DataGridView dgv, bool setting) {
Type dgvType = dgv.GetType();
PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
pi.SetValue(dgv, setting, null);
}
}
}

View File

@ -592,9 +592,9 @@
this.headerSearchToolStripButton = new System.Windows.Forms.ToolStripButton();
this.versionLabel = new System.Windows.Forms.Label();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.headersGridView = new DSPRE.DataGridViewDoubleBuffered();
this.heightsGridView = new DSPRE.DataGridViewDoubleBuffered();
this.mapFilesGridView = new DSPRE.DataGridViewDoubleBuffered();
this.headersGridView = new System.Windows.Forms.DataGridView();
this.heightsGridView = new System.Windows.Forms.DataGridView();
this.mapFilesGridView = new System.Windows.Forms.DataGridView();
this.mainTabControl.SuspendLayout();
this.headerEditorTabPage.SuspendLayout();
this.worldmapCoordsGroupBox.SuspendLayout();
@ -7424,6 +7424,7 @@
//
// headersGridView
//
this.headersGridView.DoubleBuffered(true);
this.headersGridView.AllowUserToAddRows = false;
this.headersGridView.AllowUserToDeleteRows = false;
this.headersGridView.AllowUserToResizeColumns = false;
@ -7480,6 +7481,7 @@
//
// heightsGridView
//
this.heightsGridView.DoubleBuffered(true);
this.heightsGridView.AllowUserToAddRows = false;
this.heightsGridView.AllowUserToDeleteRows = false;
this.heightsGridView.AllowUserToResizeColumns = false;
@ -7534,6 +7536,7 @@
//
// mapFilesGridView
//
this.mapFilesGridView.DoubleBuffered(true);
this.mapFilesGridView.AllowUserToAddRows = false;
this.mapFilesGridView.AllowUserToDeleteRows = false;
this.mapFilesGridView.AllowUserToResizeColumns = false;
@ -7822,9 +7825,9 @@
private System.Windows.Forms.TabControl matrixTabControl;
private System.Windows.Forms.TabPage headersTabPage;
private System.Windows.Forms.TabPage heightsTabPage;
private DSPRE.DataGridViewDoubleBuffered heightsGridView;
private System.Windows.Forms.DataGridView heightsGridView;
private System.Windows.Forms.TabPage mapFilesTabPage;
private DSPRE.DataGridViewDoubleBuffered mapFilesGridView;
private System.Windows.Forms.DataGridView mapFilesGridView;
private System.Windows.Forms.TextBox matrixNameTextBox;
private System.Windows.Forms.NumericUpDown heightUpDown;
private System.Windows.Forms.NumericUpDown widthUpDown;
@ -7832,7 +7835,7 @@
private System.Windows.Forms.Label widthLabel;
private System.Windows.Forms.ComboBox selectMatrixComboBox;
private System.Windows.Forms.Button saveMatrixButton;
private DSPRE.DataGridViewDoubleBuffered headersGridView;
private System.Windows.Forms.DataGridView headersGridView;
private System.Windows.Forms.Button addHeadersButton;
private System.Windows.Forms.Button addHeightsButton;
private System.Windows.Forms.Button removeHeadersButton;

View File

@ -2340,7 +2340,7 @@ namespace DSPRE {
if (disableHandlers)
return;
disableHandlers = true;
/* Add or remove rows in DataGridView control */
int delta = (int)widthUpDown.Value - currentMatrix.width;
for (int i = 0; i < Math.Abs(delta); i++) {