- [DEVEXPRESS] Chia sẻ code các tạo report in nhiều hóa đơn trên XtraReport C#
- [POWER AUTOMATE] Hướng dẫn gởi tin nhắn zalo từ file Excel - No code
- [C#] Chia sẻ code lock và unlock user trong domain Window
- [SOFTWARE] Giới thiệu bộ phần mềm tính Kết Cấu Thép HatteSale, Mộng Đơn, Dầm, Sàn, Móng Cọc, Vách, Xà Gồ, Tính Tải Trọng
- [DEVEXPRESS] Vẽ Biểu Đồ Stock Chứng Khoán - Công Cụ Thiết Yếu Cho Nhà Đầu Tư trên Winform
- [C#] Hướng dẫn bảo mật ứng dụng 2FA (Multi-factor Authentication) trên Winform
- [C#] Hướng dẫn convert HTML code sang PDF File trên NetCore 7 Winform
- [C#] Hướng dẫn viết ứng dụng chat với Gemini AI Google Winform
- Hướng dẫn khóa file bằng nhiều process id, không cho xóa tập tin
- Hướng dẫn cách tạo Product Id cho ứng dụng phần mềm XXXXX-XXXXX-XXXXX-XXXXX
- [SQLSERVER] Hướng dẫn tạo script sql từ ứng dụng Sqlserver management Studio
- [C#] Hướng dẫn sử dụng thư viện AutoITx lấy id và password Ultraviewer trên winform
- [VB.NET] Hướng dẫn lấy thông tin tài khoản đăng nhập windows và khởi động lại ứng dụng ở chế độ Administrator
- [C#] Sử dụng thư viện Polly gửi lại request api khi request bị lỗi hay rớt mạng
- [DEVEXPRESS] Chia sẻ source code tạo báo cáo report in tem nhãn label trên C# winform
- [DEVEXPRESS] Hướng dẫn vẽ biểu đồ Bar Chart trên Winform
- [C#] Tạo form đăng nhập và đăng ký với hiệu ứng Sliding Animation Effect
- [C#] Hướng dẫn tạo thanh toán đơn hàng qua mã vạch VietQR sử dụng API PayOS hoàn toàn miễn phí
- [C#] Hướng dẫn ghi log ra RichTextBox giống Console trên Winform sử dụng thư viện Serilog
- [C#] Hướng dẫn cách tạo mã QR Code trên file Excel
[C#] Show Modal Winform like Bootstrap
Xin chào các bạn, bài viết hôm nay mình tiếp tục hướng dẫn các bạn cách tạo hiệu ứng show Modal Effect giống Boottrap Website.
[C#] Show Modal Dialog Effect Like Bootstrap Winform
Dưới đây, video demo ứng dụng:
Source code FormMain.cs
:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace modal
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static int parentX, parentY;
private void button1_Click(object sender, EventArgs e)
{
Form modalBackground = new Form();
using (modalForm modal = new modalForm(this)) {
modalBackground.StartPosition = FormStartPosition.Manual;
modalBackground.FormBorderStyle = FormBorderStyle.None;
modalBackground.Opacity = .50d;
modalBackground.BackColor = Color.Black;
modalBackground.Size = this.Size;
modalBackground.Location = this.Location;
modalBackground.ShowInTaskbar = false;
modalBackground.Show();
modal.Owner = modalBackground;
parentX = this.Location.X;
parentY = this.Location.Y;
modal.ShowDialog();
modalBackground.Dispose();
}
}
}
}
Source code FormModal.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace modal
{
public partial class modalForm : Form
{
public Form _parent;
public modalForm(Form parent)
{
InitializeComponent();
this._parent = parent;
}
public bool isShow = true;
private void modalEffect_Timer_Tick(object sender, EventArgs e)
{
if (isShow)
{
if (Opacity >= 1)
{
modalEffect_Timer.Stop();
}
else
{
Opacity += .04;
}
int y = Form1.parentY += 6; //INCREMENT
this.Location = new Point(childFormX, y);
if (y >= i)
{
modalEffect_Timer.Stop();
}
}
else {
if (Opacity <= 0)
{
modalEffect_Timer.Stop();
this.Close();
}
else
{
Opacity -= .04;
}
int y = Form1.parentY -= 6; //DECREMENT
this.Location = new Point(childFormX, y);
if (y == i)
{
modalEffect_Timer.Stop();
this.Close();
}
}
}
int i, childFormX, childFormY;
private void button2_Click(object sender, EventArgs e)
{
button1_Click(sender, e);
}
private void modalForm_Load(object sender, EventArgs e)
{
int parentFormX = _parent.Location.X;
int parentFormY = _parent.Location.Y;
childFormX = parentFormX + (_parent.Width - this.Width) / 2;
childFormY = parentFormY + (_parent.Height - this.Height) / 2;
i = childFormY;
this.Location = new Point(childFormX, childFormY);
}
private void button1_Click(object sender, EventArgs e)
{
i = 0;
isShow = false;
modalEffect_Timer.Start();
//this.Close();
}
}
}
Thanks for watching!