- [C#] Di chuyển và thay đổi kích thước Control Winform khi ứng dụng đang chạy
- [VB.NET] Chia sẻ source tạo sắp xếp đội hình bóng đá Line-ups đội bóng
- [C#] Hướng dẫn chỉnh sửa Text của label trực tiếp trên winform
- [C#] Hướng dẫn custom TextBox giống Ultraviewer trên Winform
- [C#] Show Modal Winform like Bootstrap
- [DATABASE] Thứ tự thực hiện mệnh đề truy vấn SELECT trong Sqlserver
- [C#] Hướng dẫn viết addin Excel Lấy hình ảnh từ URL internet vào Excel
- [DATABASE] TSQL view max length all column data trên table Sqlserver
- [DEVEXPRESS] Hướng dẫn sử dụng MailMerge kèm Hình ảnh trên Winform
- [DATABASE] Hướng dẫn truy vấn xem kích thước lưu trữ của từng bảng ghi Table trên sqlserver
- [C#] Hướng dẫn Fake Date Time sử dụng thư viện Harmony
- [DATABASE] Phân biệt câu lệnh DDL và DML trong sqlserver
- [C#] Hướng dẫn convert file mã HTML sang file Pdf trên winform
- [DEVEXPRESS] Tạo các loại mã vạch Barcode trực tiếp trên Devexpress Barcode API
- [DEVEXPRESS] Hướng dẫn custom Simple button thành Progressbar
- [DATABASE] Tách số và chữ từ chuỗi - hàm tối ưu hóa tách số và chữ trong Sqlserver
- [C#] Tìm kiếm gần đúng Full Text Search sử dụng thư viện Lucene.NET
- [C#] Chia sẻ tài liệu, sdk và source code máy chấm công dòng máy ZKTeco
- [C#] Memory Cache là gì, và sử dụng trong ứng dụng Winform
- [DATABASE] Khóa chính Primary Key trong Sqlserver
[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!