Friday, October 25, 2019

Text Over Progressbar

Transparent labels don't work in winforms so the text has to be manually drawn. From this article, you can add percents. Based on that code, here is a version with bolded custom text:

        private void UpdateProgressText(string ProgressText)
        {
            using (Graphics gr = prgStatus.CreateGraphics())
            {
                gr.DrawString(ProgressText,
                    new Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold),
                    Brushes.Black,
                    new PointF(prgStatus.Width / 2 - (gr.MeasureString(ProgressText,
                        SystemFonts.DefaultFont).Width / 2.0F),
                    prgStatus.Height / 2 - (gr.MeasureString(ProgressText,
                        SystemFonts.DefaultFont).Height / 2.0F)));
            }
        }

Make sure to call UpdateProgressText() in the ProgressChanged() handler after doing a prgBar.Update();

Tuesday, October 22, 2019

Unblock Files Recursively

If you run into this scenario:


It happens when executables and msi's are downloaded from a browser. 

To fix it, just run this command in powershell:

dir -Path C:\Temp -Recurse | Unblock-File

It will remove the blocking for all files and subdirectories under the specified path.