mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-28 00:15:47 +02:00
127 lines
4.2 KiB
C#
127 lines
4.2 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace TweetDck.Core.Other{
|
|
sealed partial class FormMessage : Form{
|
|
public Button ClickedButton { get; private set; }
|
|
|
|
private readonly Icon icon;
|
|
private readonly bool isReady;
|
|
|
|
private int realFormWidth, minFormWidth;
|
|
private int buttonCount;
|
|
private int prevLabelWidth, prevLabelHeight;
|
|
private bool wasLabelMultiline;
|
|
|
|
public FormMessage(string caption, string text, MessageBoxIcon messageIcon){
|
|
InitializeComponent();
|
|
|
|
this.prevLabelWidth = labelMessage.Width;
|
|
this.prevLabelHeight = labelMessage.Height;
|
|
this.minFormWidth = 20;
|
|
|
|
switch(messageIcon){
|
|
case MessageBoxIcon.Information:
|
|
icon = SystemIcons.Information;
|
|
break;
|
|
|
|
case MessageBoxIcon.Warning:
|
|
icon = SystemIcons.Warning;
|
|
break;
|
|
|
|
case MessageBoxIcon.Error:
|
|
icon = SystemIcons.Error;
|
|
break;
|
|
|
|
case MessageBoxIcon.Question:
|
|
icon = SystemIcons.Question;
|
|
break;
|
|
|
|
default:
|
|
icon = null;
|
|
labelMessage.Location = new Point(labelMessage.Location.X-37, labelMessage.Location.Y);
|
|
break;
|
|
}
|
|
|
|
this.isReady = true;
|
|
|
|
this.Text = caption;
|
|
this.labelMessage.Text = text;
|
|
}
|
|
|
|
private void FormMessage_SizeChanged(object sender, EventArgs e){
|
|
for(int index = 0; index < buttonCount; index++){
|
|
Control control = panelActions.Controls[index];
|
|
control.Location = new Point(Width-110-index*96, control.Location.Y);
|
|
}
|
|
}
|
|
|
|
public Button AddButton(string title, DialogResult result = DialogResult.OK){
|
|
Button button = new Button{
|
|
Anchor = AnchorStyles.Bottom,
|
|
Font = SystemFonts.MessageBoxFont,
|
|
Location = new Point(Width-110-buttonCount*96, 12),
|
|
Size = new Size(88, 26),
|
|
TabIndex = buttonCount,
|
|
Text = title,
|
|
UseVisualStyleBackColor = true
|
|
};
|
|
|
|
button.Click += (sender, args) => {
|
|
ClickedButton = (Button)sender;
|
|
DialogResult = result;
|
|
Close();
|
|
};
|
|
|
|
panelActions.Controls.Add(button);
|
|
|
|
minFormWidth += 96;
|
|
Width = Math.Max(realFormWidth, minFormWidth);
|
|
|
|
++buttonCount;
|
|
return button;
|
|
}
|
|
|
|
public void AddActionControl(Control control){
|
|
panelActions.Controls.Add(control);
|
|
|
|
minFormWidth += control.Width+control.Margin.Horizontal;
|
|
Width = Math.Max(realFormWidth, minFormWidth);
|
|
}
|
|
|
|
private void labelMessage_SizeChanged(object sender, EventArgs e){
|
|
if (!isReady){
|
|
return;
|
|
}
|
|
|
|
bool isMultiline = labelMessage.Height > labelMessage.MinimumSize.Height;
|
|
|
|
if (isMultiline && !wasLabelMultiline){
|
|
labelMessage.Location = new Point(labelMessage.Location.X, labelMessage.Location.Y-8);
|
|
prevLabelHeight += 8;
|
|
}
|
|
else if (!isMultiline && wasLabelMultiline){
|
|
labelMessage.Location = new Point(labelMessage.Location.X, labelMessage.Location.Y+8);
|
|
prevLabelHeight -= 8;
|
|
}
|
|
|
|
realFormWidth = Width-(icon == null ? 67+(labelMessage.Margin.Left-labelMessage.Margin.Right) : 46)+labelMessage.Margin.Right+labelMessage.Width-prevLabelWidth;
|
|
Width = Math.Max(realFormWidth, minFormWidth);
|
|
Height += labelMessage.Height-prevLabelHeight;
|
|
|
|
prevLabelWidth = labelMessage.Width;
|
|
prevLabelHeight = labelMessage.Height;
|
|
wasLabelMultiline = isMultiline;
|
|
}
|
|
|
|
protected override void OnPaint(PaintEventArgs e){
|
|
if (icon != null){
|
|
e.Graphics.DrawIcon(icon, 25, 26);
|
|
}
|
|
|
|
base.OnPaint(e);
|
|
}
|
|
}
|
|
}
|