Exemple #1
0
        //	private void SetupSystemMenu()
        //	{
        //		//	SystemMenu SysMenu = SystemMenu.FromWindow(Process.GetCurrentProcess().MainWindowHandle);
        //		SystemMenu SysMenu = SystemMenu.FromWindow(this);
        //		SysMenu.DeleteMenu(6);
        //		SysMenu.DeleteMenu(5);
        //		SysMenu.DeleteMenu(4);
        //		SysMenu.DeleteMenu(3);
        //	}

        private void SetStartSize()
        {
            //Get file count (excluding hidden and system files
            int fileCount = new DirectoryInfo(FolderPath).EnumerateFileSystemInfos().Where(file => {
                return(!file.Attributes.HasFlag(FileAttributes.System) && !file.Attributes.HasFlag(FileAttributes.Hidden));
            }).Count();

            //Get index of size for the number of files
            int i           = fileCount;
            int highestSize = sizes.Best(kvp => kvp.Key).Key;

            if (i > highestSize)
            {
                i = highestSize;
            }
            else
            {
                while (!sizes.ContainsKey(i) && i >= 0)
                {
                    i--;
                }
            }

            //Get size from index or get default size
            Size size;

            if (i >= 0)
            {
                size = sizes[i];
            }
            else
            {
                size = new Size(7, 3);
            }

            //Set width and height, by working out the width/height of the FileGridItems, and then adding the borders
            this.Width = (
                //Size of items:
                (FileGridItem.StaticWidth * size.Width)

                //Left outer stuff
                + FileGridBorder.BorderThickness.Left
                + FileGridBorder.Margin.Left
                + FileGridBorder.Padding.Left
                + FileGridScrollViewer.Padding.Left
                + FileGridScrollViewer.BorderThickness.Left
                + FileGridScrollViewer.Margin.Left
                + MainWindowArea.Margin.Left
                + ShadowLeft.MaxWidth

                //Right outer stuff:
                + FileGridBorder.BorderThickness.Right
                + FileGridBorder.Margin.Right
                + 8                 //The value for FileGridBorder.Padding.Right when there is no scrollbar
                + (fileCount > highestSize ? 14 : 0)
                //^ An extra 14 if there will be a scrollbar
                //^ (This is necessary because the binding has not yet been calculated)
                + FileGridScrollViewer.Padding.Right
                + FileGridScrollViewer.BorderThickness.Right
                + FileGridScrollViewer.Margin.Right
                + MainWindowArea.Margin.Right
                + ShadowRight.MaxWidth
                );
            this.Height = (
                //Size of items:
                (FileGridItem.StaticHeight * size.Height)

                //Top outer stuff:
                + FileGridBorder.BorderThickness.Top
                + FileGridBorder.Margin.Top
                + FileGridBorder.Padding.Top
                + FileGridScrollViewer.Padding.Top
                + FileGridScrollViewer.BorderThickness.Top
                + FileGridScrollViewer.Margin.Top
                + TitleBar.MaxHeight
                + MainWindowArea.Margin.Top
                + ShadowTop.MaxHeight

                //Bottom outer stuff:
                + FileGridBorder.BorderThickness.Bottom
                + FileGridBorder.Margin.Bottom
                + FileGridBorder.Padding.Bottom
                + FileGridScrollViewer.Padding.Bottom
                + FileGridScrollViewer.BorderThickness.Bottom
                + FileGridScrollViewer.Margin.Bottom
                + MainWindowArea.Margin.Bottom
                + ShadowBottom.MaxHeight
                );
        }