-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTextMessageBox.cs
39 lines (34 loc) · 1.23 KB
/
TextMessageBox.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Windows.Forms;
namespace HgmViewer
{
/// <summary>
/// Message box dialog with room for more text
/// </summary>
public partial class TextMessageBox : Form
{
public string Title { get => Text; set => Text = value; }
public string ShortMessage
{
get => tbShortMessage.Text;
set { tbShortMessage.Text = value; OnShortMessageSet(); }
}
public string Message { get => tbMessage.Text; set => tbMessage.Text = value; }
public TextMessageBox()
{
InitializeComponent();
}
private void OnShortMessageSet()
{
using var g = tbShortMessage.CreateGraphics();
var strHeight = (int)Math.Round(g.MeasureString(tbShortMessage.Text, tbShortMessage.Font).Height);
var strHeight2 = (int)Math.Round(g.MeasureString("ABC", tbShortMessage.Font).Height);
var strHeight3 = tbShortMessage.PreferredHeight;
tbShortMessage.Height = strHeight3 - strHeight2 + strHeight;
var newTop = tbShortMessage.Bottom + 5;
var diff = tbMessage.Top - newTop;
tbMessage.Top = newTop;
tbMessage.Height += diff;
}
}
}