Button AddMenuItem(MenuItemInfo menuItem)
        {
            ImageSource imageSource = null;

            if (!string.IsNullOrWhiteSpace(menuItem.IconPath))
            {
                imageSource = SystemIcon.GetImageSource($"{AppDomain.CurrentDomain.BaseDirectory}Images/{menuItem.IconPath}");
            }
            else if (System.IO.File.Exists(menuItem.FilePath))
            {
                imageSource = SystemIcon.GetImageSource(true, menuItem.FilePath);
            }
            var btn = new Button()
            {
                ToolTip = menuItem.Name,
                Content = new Image()
                {
                    Source = imageSource
                }
            };

            btn.Click += (s, e) => RunExe(menuItem);

            return(btn);
        }
Exemple #2
0
        /// <summary>
        /// 显示一个错误弹窗
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public ButtonResult ShowError(string message)
        {
            VectorImage image = SystemIcon.Instance().Error;
            string      title = DictionaryResource.GetString("Error");

            return(ShowMessage(image, title, message));
        }
Exemple #3
0
        private void PopulateTreeView()
        {
            foreach (var item in DriveInfo.GetDrives())
            {
                if (item.IsReady)
                {
                    var node = new TreeNode(string.Format("{0} ({1})", item.VolumeLabel == string.Empty ? "Local Disk" : item.VolumeLabel, item.Name.Substring(0, 2)));
                    var key  = "Direve:" + item.Name[0];
                    if (!imageList1.Images.ContainsKey(key))
                    {
                        this.imageList1.Images.Add(key, SystemIcon.GetDriverIcon(item.Name[0], true));
                    }

                    node.ImageKey         = key;
                    node.SelectedImageKey = key;
                    node.Tag = item.RootDirectory.FullName;
                    this.treeView1.Nodes.Add(node);
                }
            }
            //var shellItem = new ShellItem();
            //foreach (ShellItem item in shellItem.GetSubFolders())
            //{
            //    rootNode = new TreeNode(item.DisplayName);
            //    rootNode.ImageIndex = item.IconIndex;
            //    rootNode.SelectedImageIndex = item.IconIndex;
            //    rootNode.Tag = item.Path;
            //    treeView1.Nodes.Add(rootNode);
            //}
        }
Exemple #4
0
 public static SystemIcon Instance()
 {
     if (instance == null)
     {
         instance = new SystemIcon();
     }
     return(instance);
 }
Exemple #5
0
        /// <summary>
        /// Umwandlung in eine CSS-Klasse
        /// </summary>
        /// <returns>Die zum Icon gehörende CSS-KLasse</returns>
        public virtual string ToClass()
        {
            if (SystemIcon != TypeIcon.None)
            {
                return(SystemIcon.ToClass());
            }

            return(null);
        }
Exemple #6
0
        private void HYPDM_Load(object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(10000);
            tlCategoryList.DataSource = WcfServiceLocator.Create <IHyPdmMainService>().getHuayanPdmMainMenu();
            var imagelist = new ImageList();

            imagelist.Images.Add(SystemIcon.GetFolderIcon(true).ToBitmap());
            tlCategoryList.SelectImageList     = imagelist;
            tlCategoryList.Nodes[0].ImageIndex = 0;
        }
Exemple #7
0
        internal static ImageSource LoadIcon(SystemIcon systemIcon)
        {
            IntPtr icon = NativeMethods.LoadSystemIcon(IntPtr.Zero, new UIntPtr((uint)systemIcon));

            if (icon != IntPtr.Zero)
            {
                return((ImageSource)Imaging.CreateBitmapSourceFromHIcon(icon, Int32Rect.Empty, (BitmapSizeOptions)null));
            }
            return((ImageSource)null);
        }
Exemple #8
0
        /// <summary>
        /// Gets a native system icon as a managed <see cref="BitmapSource"/>.
        /// </summary>
        /// <param name="icon">The system icon.</param>
        /// <param name="iconSize">The system icon size.</param>
        /// <returns>Returns the system icon as <see cref="BitmapSource"/>.</returns>
        public static BitmapSource GetSystemIcon(SystemIcon icon, SystemIconSize iconSize)
        {
            NativeMethods.SHSTOCKICONINFO sii = default(NativeMethods.SHSTOCKICONINFO);
            sii.cbSize = (uint)Marshal.SizeOf(typeof(NativeMethods.SHSTOCKICONINFO));

            Marshal.ThrowExceptionForHR(NativeMethods.SHGetStockIconInfo((NativeMethods.SHSTOCKICONID)icon, (NativeMethods.SHGSI)iconSize | NativeMethods.SHGSI.SHGSI_ICON, ref sii));

            var iconSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(sii.hIcon, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            NativeMethods.DestroyIcon(sii.hIcon);
            return(iconSource);
        }
        private void mIconButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog lOpenFileDialog = new OpenFileDialog();

            lOpenFileDialog.Multiselect = false;
            lOpenFileDialog.Filter      = "Icon File(*.ico;*.icl;*.exe;*.dll)|*.ico;*.icl;*.exe;*.dll";
            lOpenFileDialog.ShowDialog();
            if (!string.IsNullOrEmpty(lOpenFileDialog.FileName))
            {
                this.mIconPath         = lOpenFileDialog.FileName;
                this.mIconButton.Image = SystemIcon.GetFileIcon(lOpenFileDialog.FileName, false).ToBitmap();
            }
        }
Exemple #10
0
        public BaseDialogViewModel()
        {
            #region 属性初始化

            Title     = new AppInfo().Name;
            CloseIcon = new VectorImage
            {
                Height = SystemIcon.Instance().Close.Height,
                Width  = SystemIcon.Instance().Close.Width,
                Data   = SystemIcon.Instance().Close.Data,
                Fill   = SystemIcon.Instance().Close.Fill
            };

            #endregion
        }
Exemple #11
0
        void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            TreeNode newSelected = e.Node;
            var      dirPath     = newSelected.Tag.ToString();

            if (string.IsNullOrEmpty(dirPath))
            {
                return;
            }
            DirectoryInfo dir = new DirectoryInfo(dirPath);

            if (!dir.Exists)
            {
                return;
            }
            try
            {
                LoadTreeDir(newSelected, dir);
                loadListDir(dir);

                foreach (FileInfo file in dir.GetFiles())
                {
                    var key = file.Extension.ToLower();
                    if (key == ".exe")
                    {
                        key = file.Name;
                    }
                    if (!imageList1.Images.ContainsKey(key))
                    {
                        this.imageList1.Images.Add(key, SystemIcon.GetFileIcon(file.FullName, true));
                    }
                    var item = new ListViewItem(file.Name, key);
                    item.Tag = file.FullName;
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "File"));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, file.LastAccessTime.ToShortDateString()));
                    listView1.Items.Add(item);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
        }
Exemple #12
0
        Button AddMenuItem(MenuItemInfo menuItem)
        {
            ImageSource imageSource = null;

            if (!string.IsNullOrWhiteSpace(menuItem.IconPath))
            {
                imageSource = SystemIcon.GetImageSource($"{AppDomain.CurrentDomain.BaseDirectory}Images/{menuItem.IconPath}");
            }
            else if (System.IO.File.Exists(menuItem.FilePath))
            {
                imageSource = SystemIcon.GetImageSource(true, menuItem.FilePath);
            }

            StackPanel sp = new StackPanel();

            sp.Orientation = Orientation.Vertical;
            Image img = new Image
            {
                Source = imageSource,
                Width  = 36,
                Height = 36,
                Tag    = menuItem
            };

            sp.Children.Add(img);

            TextBlock tb = new TextBlock
            {
                Text = menuItem.Name,
                HorizontalAlignment = HorizontalAlignment.Center
            };

            sp.Children.Add(tb);

            var btn = new Button()
            {
                ToolTip = menuItem.Name,
                Content = sp
            };

            btn.Click += (s, e) => RunExe(menuItem);

            return(btn);
        }
Exemple #13
0
        public void FileIcon(uint id, RectangleF rect, string path)
        {
            var systemIcon = SystemIcon.Get(path, true);

            //throw new NotImplementedException();
            if (systemIcon.ImageList == IntPtr.Zero)
            {
                return;
            }

            int w = 0;
            int h = 0;

            if (!Comctl32.ImageList_GetIconSize(systemIcon.ImageList, ref w, ref h))
            {
                return;
            }

            Bitmap bitmap;

            if (!m_imageListMap.TryGetValue(systemIcon.ImageListIndex, out bitmap))
            {
                using (var memoryBitmap = new MemoryBitmap(w, h))
                {
                    Comctl32.ImageList_Draw(systemIcon.ImageList, systemIcon.ImageListIndex,
                                            memoryBitmap.DC, 0, 0, ILD.NORMAL);

                    var bytes = memoryBitmap.GetBitmap();
                    if (bytes != null)
                    {
                        using (var s = new DataStream(w * h * 4, true, true))
                        {
                            s.Write(bytes, 0, bytes.Length);
                            s.Position = 0;
                            bitmap     = new Bitmap(m_device.D2DDeviceContext, new Size2(w, h), s, w * 4, GetBP);
                            m_imageListMap.Add(systemIcon.ImageListIndex, bitmap);
                        }
                    }
                }
            }

            //m_device.D2DDeviceContext.DrawBitmap(bitmap, new RectangleF(rect.X, rect.Y, w, h), 1.0f, BitmapInterpolationMode.Linear);
        }
Exemple #14
0
        private static MessageBoxIcon SystemIconToMessageBoxIcon(SystemIcon icon)
        {
            switch (icon)
            {
            case SystemIcon.Error:
                return(System.Windows.Forms.MessageBoxIcon.Error);

            case SystemIcon.Info:
                return(System.Windows.Forms.MessageBoxIcon.Information);

            case SystemIcon.Warning:
                return(System.Windows.Forms.MessageBoxIcon.Warning);

            case SystemIcon.Question:
                return(System.Windows.Forms.MessageBoxIcon.Question);

            default:
                return(System.Windows.Forms.MessageBoxIcon.None);
            }
        }
Exemple #15
0
        public WND_ConfFileContent()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();
            this.Closing += new CancelEventHandler(WND_CLosing);
            //
            // TODO: Add constructor code after the InitializeComponent() call.
            //

            ImageList il = new ImageList();

            il.Images.Add("folder", SystemIcon.GetDirectoryIcon(true));
            il.Images.Add("other", SystemIcon.GetIcon(".other", false));
            il.Images.Add("swf", SystemIcon.GetIcon(".swf", false));
            il.Images.Add("xml", SystemIcon.GetIcon(".xml", false));
            il.Images.Add("jar", SystemIcon.GetIcon(".jar", false));
            this.treeView1.ImageList = il;
        }
Exemple #16
0
        public UC05_OverView()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            //
            // TODO: Add constructor code after the InitializeComponent() call.
            //

            ImageList il = new ImageList();

            il.Images.Add("folder", SystemIcon.GetDirectoryIcon(true));
            il.Images.Add("other", SystemIcon.GetIcon(".other", false));
            il.Images.Add("swf", SystemIcon.GetIcon(".swf", false));
            il.Images.Add("xml", SystemIcon.GetIcon(".xml", false));
            il.Images.Add("jar", SystemIcon.GetIcon(".jar", false));
            this.treeView1.ImageList = il;
            //inittree();
        }
Exemple #17
0
        void LoadTreeDir(TreeNode newSelected, DirectoryInfo dir)
        {
            var key = "folder";

            if (newSelected.Nodes.Count == 0)
            {
                foreach (var subDir in dir.GetDirectories().Where(m => !m.Attributes.HasFlag(FileAttributes.Hidden)))
                {
                    var node = new TreeNode(subDir.Name);

                    if (!imageList1.Images.ContainsKey(key))
                    {
                        this.imageList1.Images.Add(key, SystemIcon.GetFolderIcon(true));
                    }
                    node.ImageKey         = key;
                    node.SelectedImageKey = key;
                    node.Tag = subDir.FullName;
                    newSelected.Nodes.Add(node);
                }
            }
        }
        private void Grid_Drop(object sender, DragEventArgs e)
        {
            try
            {
                var          fileName = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
                MenuItemInfo menuItem = new MenuItemInfo()
                {
                    FilePath = fileName
                };

                // 快捷方式需要获取目标文件路径
                if (fileName.ToLower().EndsWith("lnk"))
                {
                    WshShell     shell       = new WshShell();
                    IWshShortcut wshShortcut = (IWshShortcut)shell.CreateShortcut(fileName);
                    menuItem.FilePath = wshShortcut.TargetPath;
                }
                ImageSource        imageSource = SystemIcon.GetImageSource(true, menuItem.FilePath);
                System.IO.FileInfo file        = new System.IO.FileInfo(fileName);
                if (string.IsNullOrWhiteSpace(file.Extension))
                {
                    menuItem.Name = file.Name;
                }
                else
                {
                    menuItem.Name = file.Name.Substring(0, file.Name.Length - file.Extension.Length);
                }
                menuItem.Type = MenuItemType.Exe;

                if (ConfigHelper.AddNewMenuItem(menuItem))
                {
                    var btn = AddMenuItem(menuItem);
                    fishButtons.Children.Add(btn);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public UC02_Select()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            //
            // TODO: Add constructor code after the InitializeComponent() call.
            //
            this.textBox1.Enabled = false;
            this.button1.Enabled  = false;
            this.button3.Enabled  = false;
            ImageList il = new ImageList();

            il.Images.Add("folder", SystemIcon.GetDirectoryIcon(true));
            il.Images.Add("other", SystemIcon.GetIcon(".other", false));
            il.Images.Add("swf", SystemIcon.GetIcon(".swf", false));
            il.Images.Add("xml", SystemIcon.GetIcon(".xml", false));
            il.Images.Add("jar", SystemIcon.GetIcon(".jar", false));
            this.treeView1.ImageList = il;
        }
Exemple #20
0
        //public async Task<SystemIcon> CreateOrEditSystemIcon(SystemIcon model)
        //{
        //    var Item = this.server.GetSingle(model.Id);
        //    if(Item)
        //}

        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <SystemIcon> EditSystemIcon(SystemIcon model)
        {
            return(await this.server.EditAsync(model).ConfigureAwait(false));
        }
Exemple #21
0
 /// <summary>
 /// 新增
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public async Task <SystemIcon> CreateSystemIcon(SystemIcon model)
 {
     return(await this.server.AddAsync(model).ConfigureAwait(false));
 }
Exemple #22
0
 public static IntPtr LoadIcon(IntPtr hInstance, SystemIcon icon)
 {
     return(User32Methods.LoadIcon(hInstance, new IntPtr((int)icon)));
 }
        public MainWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
        {
            this.eventAggregator = eventAggregator;

            #region 属性初始化

            Window mainWindow = Application.Current.MainWindow;

            WinState = WindowState.Normal;

            MinimizeIcon = SystemIcon.Instance().Minimize;
            ResizeIcon   = SystemIcon.Instance().Maximize;
            CloseIcon    = SystemIcon.Instance().Close;
            SkinIcon     = SystemIcon.Instance().Skin;

            #endregion

            #region 订阅

            // 订阅导航事件
            eventAggregator.GetEvent <NavigationEvent>().Subscribe((view) =>
            {
                var param = new NavigationParameters
                {
                    { "Parent", view.ParentViewName },
                    { "Parameter", view.Parameter }
                };
                regionManager.RequestNavigate("ContentRegion", view.ViewName, param);
            });

            // 订阅消息发送事件
            string oldMessage;
            eventAggregator.GetEvent <MessageEvent>().Subscribe((message) =>
            {
                MessageVisibility = Visibility.Visible;

                oldMessage = Message;
                Message    = message;
                int sleep  = 2000;
                if (oldMessage == Message)
                {
                    sleep = 1500;
                }

                Thread.Sleep(sleep);

                MessageVisibility = Visibility.Hidden;
            }, ThreadOption.BackgroundThread);

            #endregion

            #region 命令定义

            // window加载后执行的事件
            LoadedCommand = new DelegateCommand(() =>
            {
                clipboardHooker = new ClipboardHooker(Application.Current.MainWindow);
                clipboardHooker.ClipboardUpdated += OnClipboardUpdated;

                // 进入首页
                var param = new NavigationParameters
                {
                    { "Parent", "" },
                    { "Parameter", "start" }
                };
                regionManager.RequestNavigate("ContentRegion", ViewIndexViewModel.Tag, param);

                // 关闭欢迎页
                if (App.Dictionary.ContainsKey("SplashWindow"))
                {
                    Views.SplashWindow sw = App.Dictionary["SplashWindow"] as Views.SplashWindow;
                    // 在sw的线程上关闭SplashWindow
                    sw.Dispatcher.Invoke(() => sw.Close());
                }

                // 设置焦点
                Application.Current.MainWindow.Activate();
            });

            // 顶部caption栏的点击事件,包括双击和拖动
            int times = 0;
            DragMoveCommand = new DelegateCommand(() =>
            {
                // caption 双击事件
                times += 1;
                DispatcherTimer timer = new DispatcherTimer
                {
                    Interval = new TimeSpan(0, 0, 0, 0, 300)
                };
                timer.Tick     += (s, e) => { timer.IsEnabled = false; times = 0; };
                timer.IsEnabled = true;

                if (times % 2 == 0)
                {
                    timer.IsEnabled = false;
                    times           = 0;
                    WinState        = WinState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
                }

                // caption 拖动事件
                try
                {
                    mainWindow.DragMove();
                }
                catch { }
            });

            // 最小化窗口事件
            MinimizeCommand = new DelegateCommand(() =>
            {
                mainWindow.WindowState = WindowState.Minimized;
            });
            MinimizeEnterCommand = new DelegateCommand(() =>
            {
                SetEnterStyle(MinimizeIcon);
            });
            MinimizeLeaveCommand = new DelegateCommand(() =>
            {
                SetLeaveStyle(MinimizeIcon);
            });

            // 最大化/还原窗口事件
            ResizeCommand = new DelegateCommand(() =>
            {
                WinState = WinState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
            });
            ResizeEnterCommand = new DelegateCommand(() =>
            {
                SetEnterStyle(ResizeIcon);
            });
            ResizeLeaveCommand = new DelegateCommand(() =>
            {
                SetLeaveStyle(ResizeIcon);
            });

            // 关闭窗口事件
            CloseCommand = new DelegateCommand(() =>
            {
                if (clipboardHooker != null)
                {
                    clipboardHooker.ClipboardUpdated -= OnClipboardUpdated;
                    clipboardHooker.Dispose();
                }

                mainWindow.Close();
            });
            CloseEnterCommand = new DelegateCommand(() =>
            {
                SetEnterStyle(CloseIcon);
            });
            CloseLeaveCommand = new DelegateCommand(() =>
            {
                SetLeaveStyle(CloseIcon);
            });

            // 皮肤按钮点击事件
            SkinCommand = new DelegateCommand(() =>
            {
                // 设置主题
                DictionaryResource.LoadTheme("ThemeDiy");

                // 切换语言
                DictionaryResource.LoadLanguage("en_US");
            });
            SkinEnterCommand = new DelegateCommand(() =>
            {
                SetEnterStyle(SkinIcon);
            });
            SkinLeaveCommand = new DelegateCommand(() =>
            {
                SetLeaveStyle(SkinIcon);
            });

            #endregion
        }
Exemple #24
0
 public static ImageSource?GetImageSource(SystemIcon systemIcon, int width, int height)
 {
     return(GetImageSource(systemIcon.Origin, systemIcon.IconIdOrIndex, width, height));
 }
Exemple #25
0
 public static ImageSource LoadIcon(SystemIcon systemIcon)
 {
     return(NativeMethods.LoadIcon(systemIcon));
 }