NEWS

[C#] Mở hộp thoại Property Dialog File Win32 trong Windows

[C#] Mở hộp thoại Property Dialog File  Win32 trong Windows
Đăng bởi: Thảo Meo - Lượt xem: 3883 11:14:43, 22/10/2019DEVEXPRESS   In bài viết

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ác mở hộp thoại thuộc tính file (Property Dialog File trong Windows) bằng ngôn ngữ lập trình C#.

[C#] Mở hộp thoại Property Dialog File Windows

Trong lập trình ứng dụng, ví dụ, mình đang viết ứng dụng xem hình ảnh Photo Viewer.

Khi mình duyệt qua các hình ảnh, và mình muốn là right click chuột phải và chọn property, thì cửa sổ thuộc tính của hình ảnh file đó sẽ xuất hiện.

Và active tab Details file cho mình.

Dưới đây là giao diện demo chương trình xem thuộc tính File của mình:

Show_File_Property_demo

Source code show Property Dialog File C#:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Show_File_Property
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btn_showproperty_Click(object sender, EventArgs e)
        {
            string path = lbl_uri.Text;
            ShowFileProperties(path);
        }

        [DllImport("shell32.dll", CharSet = CharSet.Auto)]
        static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);

        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public struct SHELLEXECUTEINFO
        {
            public int cbSize;
            public uint fMask;
            public IntPtr hwnd;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string lpVerb;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string lpFile;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string lpParameters;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string lpDirectory;
            public int nShow;
            public IntPtr hInstApp;
            public IntPtr lpIDList;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string lpClass;
            public IntPtr hkeyClass;
            public uint dwHotKey;
            public IntPtr hIcon;
            public IntPtr hProcess;
        }

        private const int SW_SHOW = 5;
        private const uint SEE_MASK_INVOKEIDLIST = 12;
        public static bool ShowFileProperties(string Filename)
        {
            SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
            info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
            info.lpVerb = "properties";
            info.lpParameters = "Details";
            info.lpFile = Filename;
            info.nShow = SW_SHOW;
            info.fMask = SEE_MASK_INVOKEIDLIST;
            return ShellExecuteEx(ref info);
        }

        private void btn_browser_Click(object sender, EventArgs e)
        {
            var dlg = new OpenFileDialog();
            if(dlg.ShowDialog() == DialogResult.OK)
            {
                lbl_uri.Text = dlg.FileName;
                
            }
        }
    }
}

 

Nếu bạn muốn Active Tab nào thì các bạn chọn Tab đó qua thuộc tính: info.lpParameters nhé.

Thanks for watching!

DOWNLOAD SOURCE

THÔNG TIN TÁC GIẢ

BÀI VIẾT LIÊN QUAN

[C#] Mở hộp thoại Property Dialog File  Win32 trong Windows
Đăng bởi: Thảo Meo - Lượt xem: 3883 11:14:43, 22/10/2019DEVEXPRESS   In bài viết

CÁC BÀI CÙNG CHỦ ĐỀ

Đọc tiếp
.