C#窗口关闭到最小化

希望能够帮助一些人

 

private DialogResult result = DialogResult.No;

//Yes关闭窗口,No最小化窗口
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (result == DialogResult.Yes)
{
e.Cancel = false;
Application.Exit();
}
else
{
e.Cancel = true;
this.Hide();
this.Visible = false;
}
}

//关闭按钮,给result赋值
private void btnExit_Click(object sender, EventArgs e)
{
result=MessageBox.Show("确认退出窗口吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
Application.Exit();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C# WinForm 中,您可以使用自定义绘制来调整窗口标题栏文字的位置。具体来说,您可以在窗口的 Paint 事件中绘制自定义标题栏,并使用 DrawString 方法来绘制标题栏中的文本,以便您可以自由控制文本的位置。 下面是一个简单的示例,演示如何在 C# WinForm 中实现自定义绘制窗口标题栏: ```csharp public partial class Form1 : Form { public Form1() { InitializeComponent(); this.FormBorderStyle = FormBorderStyle.None; this.DoubleBuffered = true; this.SetStyle(ControlStyles.ResizeRedraw, true); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); // 绘制标题栏 e.Graphics.FillRectangle(Brushes.DarkBlue, new Rectangle(0, 0, this.Width, 30)); // 绘制标题栏文本 Font font = new Font("Arial", 14, FontStyle.Bold); Brush brush = Brushes.White; string text = "Custom Title Bar"; SizeF size = e.Graphics.MeasureString(text, font); float x = (this.Width - size.Width) / 2; float y = (30 - size.Height) / 2; e.Graphics.DrawString(text, font, brush, x, y); } } ``` 在上面的示例中,我们将窗口的 FormBorderStyle 属性设置为 None,然后在窗口的 Paint 事件中编写了自定义绘制代码,以便绘制自己的标题栏。在绘制标题栏文本时,我们使用 MeasureString 方法来测量文本的大小,然后计算出文本的位置,最后使用 DrawString 方法将文本绘制到窗口上。 请注意,使用自定义绘制来调整窗口标题栏文字的位置可能会影响到窗口的默认行为,例如窗口的最大化、最小化关闭按钮可能会受到影响。因此,在实际应用中,请谨慎使用自定义绘制。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值