Use DPI for adjusting row & column sizes.
This commit is contained in:
parent
0189d7759b
commit
af15309bda
@ -89,9 +89,9 @@ namespace Volian.Controls.Library
|
||||
if (this.TableCellEditor.Text.Contains("<NewID>"))
|
||||
return false;
|
||||
XmlDocument XdOld = new XmlDocument();
|
||||
XdOld.LoadXml(oldXml);
|
||||
XdOld.LoadXml(AdjustHeightAndWidthForDPI(oldXml));
|
||||
XmlDocument XdNew = new XmlDocument();
|
||||
XdNew.LoadXml(newXml);
|
||||
XdNew.LoadXml(AdjustHeightAndWidthForDPI(newXml));
|
||||
//check volian borders 1st
|
||||
if (XdNew.SelectSingleNode("C1FlexGrid/Control/MyBorderDetailString").InnerText != XdOld.SelectSingleNode("C1FlexGrid/Control/MyBorderDetailString").InnerText)
|
||||
return true;
|
||||
@ -793,16 +793,71 @@ namespace Volian.Controls.Library
|
||||
MergedRanges.Clear();
|
||||
_ReadingXml = true;
|
||||
//Console.WriteLine("LoadGrid - Before ReadXML");
|
||||
ReadXml(str);
|
||||
//Console.WriteLine("LoadGrid - After ReadXML");
|
||||
_ReadingXml = false;
|
||||
Select(-1, -1); // this keeps the cell from being selected when the grid is first displayed
|
||||
Visible = true;
|
||||
}
|
||||
|
||||
private void ReadXml(string str)
|
||||
{
|
||||
// Get the height/width adjusted for the DPI. Depending on if the DPI setting for the current user's
|
||||
// monitor is different than the DPI setting saved in the grid record, table height/width of rows/columns
|
||||
// will be incorrect, i.e. lots of extra white space. The reason behind this is that the height/width
|
||||
// of table cells are stored as dots (from the monitor) in the underlying component one flexgrid.
|
||||
str = AdjustHeightAndWidthForDPI(str);
|
||||
using (StringReader sr = new StringReader(str))
|
||||
{
|
||||
ReadXml(sr);
|
||||
this.BorderStyle = C1.Win.C1FlexGrid.Util.BaseControls.BorderStyleEnum.None;
|
||||
sr.Close();
|
||||
}
|
||||
//Console.WriteLine("LoadGrid - After ReadXML");
|
||||
_ReadingXml = false;
|
||||
Select(-1, -1); // this keeps the cell from being selected when the grid is first displayed
|
||||
Visible = true;
|
||||
}
|
||||
|
||||
private string AdjustHeightAndWidthForDPI(string str)
|
||||
{
|
||||
// create a graphics to get the DPI and then compare it to the DPI that is stored in the grid.
|
||||
// if they are the same, we don't need to do anything.
|
||||
int DPIscreen = 0;
|
||||
using (Graphics gr = this.CreateGraphics())
|
||||
{
|
||||
DPIscreen = (int)gr.DpiX;
|
||||
}
|
||||
XmlDocument xd = new XmlDocument();
|
||||
xd.LoadXml(str);
|
||||
XmlNode xn = xd.SelectSingleNode("//DPI");
|
||||
if (xn != null && xn.InnerText != DPIscreen.ToString())
|
||||
{
|
||||
int DPIgrid = int.Parse(xn.InnerText);
|
||||
xn.InnerText = DPIscreen.ToString();
|
||||
// adjust heights and widths based on the difference in DPIs between that what was saved
|
||||
// in the database(grid) and the current DPI from the screen. Without doing this the
|
||||
// heights/widths will be 'off', i.e. lots of white space.
|
||||
XmlNodeList xnl = xd.SelectNodes("//Height");
|
||||
foreach (XmlNode xni in xnl)
|
||||
{
|
||||
int measurement = int.Parse(xni.InnerText);
|
||||
if (measurement != -1)
|
||||
xni.InnerText = ((measurement * DPIscreen) / DPIgrid).ToString();
|
||||
}
|
||||
xnl = xd.SelectNodes("//Width");
|
||||
foreach (XmlNode xni in xnl)
|
||||
{
|
||||
int measurement = int.Parse(xni.InnerText);
|
||||
if (measurement != -1)
|
||||
xni.InnerText = ((measurement * DPIscreen) / DPIgrid).ToString();
|
||||
}
|
||||
xnl = xd.SelectNodes("//DefaultSize");
|
||||
foreach (XmlNode xni in xnl)
|
||||
{
|
||||
int measurement = int.Parse(xni.InnerText);
|
||||
if (measurement != -1)
|
||||
xni.InnerText = ((measurement * DPIscreen) / DPIgrid).ToString();
|
||||
}
|
||||
str = xd.OuterXml;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
private void SetupGrid(int numrows, int numcols) //C1FlexGrid NewGrid()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user