- [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
[DEVEXPRESS] Hướng dẫn phóng lớn zoom image trong PictureEdit C#
Xin chào các bạn, bài viết hôm nay mình sẻ tiếp tục hướng dẫn các bạn cách zoom lớn hình ảnh giống phóng lớn sản phẩm hình ảnh trên website trên PictureEdit Devexpress.
[DEVEXPRESS] Zoom Image in PictureEdit C#
Các bạn lướt web các trang thương mại điện tử, hay mua hàng sản phẩm, các bạn thường thấy khi cửa hàng show hình ảnh của họ lên website.
Bạn có thể rê chuột vào tấm hình nhỏ và hiện hình lớn ở góc kế bên, giúp cho người dùng mua hàng dễ dàng xem được chi tiết của sản phẩm.
Dưới đây là hình ảnh demo ứng dụng Zoom image pictureedit devexpress c#:
Để sử dụng chúng ta sẽ sử dụng 3 componnet:
- Hai Picture Edit
- Một Flyout Panel
Cách thức hoạt động của ứng dụng, khi hover vào pictureEdit1, chúng ta sẽ crop cắt xén hình lại của pictureBox1 và hiển thị vào pictureBox2
Và sau đó chúng ta sẽ sử dụng Flyout Panel để showdialog.
Full source code zoom image c#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace zoomPicture
{
public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
pictureEdit1.Image = Properties.Resources.hotgirl2;
pictureEdit1.Properties.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Zoom;
pictureEdit1.MouseEnter += PictureEdit1_MouseEnter;
pictureEdit1.MouseMove += PictureEdit1_MouseMove;
pictureEdit1.MouseLeave += PictureEdit1_MouseLeave;
// pictureEdit1.Size = new Size(300, 300);
pictureEdit2.Properties.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Stretch;
flyoutPanel1.OwnerControl = this;
flyoutPanel1.Size = new Size(500, 500);
flyoutPanel1.Options.Location = new Point(250, 22);
flyoutPanel1.Options.AnchorType = DevExpress.Utils.Win.PopupToolWindowAnchor.Manual;
flyoutPanel1.Options.AnimationType = DevExpress.Utils.Win.PopupToolWindowAnimation.Fade;
}
int zoomFacet = 150;
private void PictureEdit1_MouseMove(object sender, MouseEventArgs e)
{
if (!flyoutPanel1.IsPopupOpen)
flyoutPanel1.ShowPopup();
Point offsetLocation = pictureEdit1.ViewportToImage(e.Location);
offsetLocation.X -= zoomFacet / 2;
offsetLocation.Y -= zoomFacet / 2;
offsetLocation.X = offsetLocation.X + zoomFacet > pictureEdit1.Image.Width
? pictureEdit1.Image.Width - zoomFacet : offsetLocation.X;
offsetLocation.X = offsetLocation.X < 0 ? 0 : offsetLocation.X;
offsetLocation.Y = offsetLocation.Y + zoomFacet > pictureEdit1.Image.Height
? pictureEdit1.Image.Height - zoomFacet : offsetLocation.Y;
offsetLocation.Y = offsetLocation.Y < 0 ? 0 : offsetLocation.Y;
pictureEdit2.Image = cropImage(pictureEdit1.Image,
new Rectangle(offsetLocation, new Size(zoomFacet, zoomFacet)));
}
private static Image cropImage(Image img, Rectangle cropArea)
{
using(Bitmap bmpImage = new Bitmap(img))
{
return bmpImage.Clone(cropArea, bmpImage.PixelFormat);
}
}
private void PictureEdit1_MouseLeave(object sender, EventArgs e)
{
flyoutPanel1.HidePopup();
}
private void PictureEdit1_MouseEnter(object sender, EventArgs e)
{
flyoutPanel1.ShowPopup();
}
}
}
Thanks for watching!