Fix description form location

This commit is contained in:
Michael Bucari-Tovo 2022-05-09 17:50:47 -06:00
parent 8763d63a93
commit 6474ef98f5
3 changed files with 12 additions and 8 deletions

View File

@ -13,15 +13,13 @@ namespace LibationWinForms
{
public partial class DescriptionDisplay : Form
{
public Point SpawnLocation { get; init; }
public string DescriptionText { get => textBox1.Text; set => textBox1.Text = value; }
public Point SpawnLocation { get; set; }
public DescriptionDisplay()
{
InitializeComponent();
textBox1.LostFocus += (_, _) => Close();
Shown += DescriptionDisplay_Shown;
var textHeight = TextRenderer.MeasureText("\n", textBox1.Font).Height;
}
private void DescriptionDisplay_Shown(object sender, EventArgs e)
@ -34,11 +32,15 @@ namespace LibationWinForms
{
base.OnLoad(e);
int lineCount = textBox1.GetLineFromCharIndex(int.MaxValue) + 2;
Height = Height - textBox1.Height + lineCount * TextRenderer.MeasureText(textBox1.Text, textBox1.Font).Height;
Height = Height - textBox1.Height + lineCount * TextRenderer.MeasureText("X", textBox1.Font).Height;
int screenHeight = Screen.PrimaryScreen.WorkingArea.Height;
Location = new Point(SpawnLocation.X + 10, Math.Min(SpawnLocation.Y, screenHeight - Height));
var tboxLocation = PointToScreen(textBox1.Location);
var tboxOffset = new Size(tboxLocation.X - Location.X, tboxLocation.Y - Location.Y);
Location = new Point(SpawnLocation.X - tboxOffset.Width, Math.Min(SpawnLocation.Y - tboxOffset.Height, screenHeight - Height));
}
[DllImport("user32.dll")]

View File

@ -265,7 +265,7 @@ namespace LibationWinForms
private static string GetDescriptionDisplay(Book book)
{
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(book?.Description ?? "");
doc.LoadHtml(book?.Description?.Replace("</p> ", "\r\n\r\n</p>") ?? "");
return doc.DocumentNode.InnerText;
}

View File

@ -69,7 +69,7 @@ namespace LibationWinForms
else if (propertyName == tagAndDetailsGVColumn.DataPropertyName)
Details_Click(getGridEntry(e.RowIndex));
else if (propertyName == descriptionGVColumn.DataPropertyName)
DescriptionClick(getGridEntry(e.RowIndex), _dataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex,false));
DescriptionClick(getGridEntry(e.RowIndex), _dataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false));
}
private void DescriptionClick(GridEntry liveGridEntry, Rectangle cell)
@ -77,10 +77,12 @@ namespace LibationWinForms
var displayWindow = new DescriptionDisplay
{
Text = $"{liveGridEntry.Title} description",
SpawnLocation = cell.Location + cell.Size,
SpawnLocation = PointToScreen(cell.Location + new Size(cell.Width, 0)),
DescriptionText = liveGridEntry.LongDescription
};
displayWindow.RestoreSizeAndLocation(Configuration.Instance);
displayWindow.Show(this);
displayWindow.FormClosing += (_, _) => displayWindow.SaveSizeAndLocation(Configuration.Instance);
}
private static async Task Liberate_Click(GridEntry liveGridEntry)