Posts

How to dynamically resize WPF tab items to fit available width

Image
Useful StackOverflow link: https://stackoverflow.com/questions/28496809/wpf-flexible-tabcontrol-header Step 1: Create a new WPF application Step 2: Create an example adjustable window with tab items Update the MainWindow.xaml to create a grid with a column section containing the tab items and a grid splitter to adjust the width of the tab item area. MainWindow.xaml We will get on to the step of creating the tab control style in a minute... [code language="xml"] <Window x:Class="TabItemResize.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Title="MainWindow" Height="450" Width="700...

How to wrap text around another control in WPF

Image
First things first, credit where it's due: the StackOverflow link I eventually found that enabled me to solve this problem: https://stackoverflow.com/questions/3339051/wrapping-text-around-an-image-or-linking-two-textblocks-in-c-sharp-wpf The trick is not use use a TextBlock as conventional wisdom would indicate, but to use a FlowDocument to achieve this kind of layout. For future reference (I am going to need something like this fairly soon), try the following XAML snippet and the resulting WPF app screenshot to demonstrate how to display a button in the top right hand corner with text wrapped around it. In my real-world apps I am using the MVVM pattern with all sorts of bindings and events etc, but this should hopefully enable me to get there: MainWindow.xaml [code language="xml"] <Window x:Class="WpfApp1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.mi...

Removing duplicate lines in a text file using notepad++

Image
First ensure the TextFx plugin has been installed in your version of notepad++. Some example text: I then copy and paste that block of text to ensure there are duplicate lines: Removing the duplicates involves THREE steps: 1. If you have not already done so, ensure the appropriate TextFX plugin is checked. Select TextFX > TextFX Tools > Sort outputs only UNIQUE at column lines: 2. Select ALL of your text (select Control + A) 3. Select TextFX > TextFX Tools > Sort lines case sensitive (at column): See that the duplicate lines have been identified and removed:

Using robocopy to transfer files: tips and tricks

Image
1. To copy a single file [code language="xml"] robocopy c:\this_folder d:\that_folder file.txt [/code]   2. To copy multiple files [code language="xml"] robocopy c:\this_folder d:\that_folder file1.txt file2.txt [/code]   3. To copy all files of a given extension [code language="xml"] robocopy c:\this_folder d:\that_folder *.txt [/code]   4. To copy the contents of an entire directory Robocopy creates the d:\that_folder\a directory and copies the files from the c:\this_folder\a directory into it. Use the E/ switch to copy the entire directory tree under c:\this_folder\a [code language="xml"] robocopy c:\this_folder\a d:\that_folder\a /E [/code]   5. To exclude existing files from the copy A really good tip taken from this GitHub link : This can save a lot of time particularly if you have to copy many large sized files. [code language="xml"] robocopy c:\this_folder d:\that_folder /E /XC /XN /XO [/code] /E - ...

How to remove lines containing specific text in Notepad++ using the Bookmarks method

Image
How to use Notepad++ to remove all lines containing a specific text. First install Notepad++ if you have not already done so, given that it really is a powerful piece of software: https://notepad-plus-plus.org/download/ Now we can demonstrate an example with the following XML-style text: Suppose we wish to remove all lines containing the text "wpdm" To do this select Control+F to fire up the Find dialog. Select the Mark tab, enter the text you wish to search for and make sure the Bookmark line checkbox is set: Select the Mark all button and close the dialog. Observe that all lines containing "wpdm" are bookmarked: To remove the bookmarked lines, select Search > Bookmarks > Remove bookmarked lines: So that the bookmarked lines are removed as shown:

How to programmatically control access to files in C# using FileSecurity objects

Image
A quick demonstration on how to control access to files in real-time. As described in the Microsoft documentation , the control access to a file can be added or removed by obtaining the FileSecurity object from that file, then modified, and then applied back to the file. In this example I choose to change the file access properties of a simple icon file "icon.ico": So that before modifying the properties it can be opened straightforwardly as follows: To demonstrate how we can alter the access properties in real-time, create a C# console application in Visual Studio and add the following code. Note the use of WindowsIdentity.GetCurrent() api used to obtain the necessary username/domain details of the current Windows user: [code language="csharp"] using System; using System.IO; using System.Security.AccessControl; using System.Security.Principal; namespace FileControlAccess { class Program { static void Main(string[] args) { ...

Using OpenCV for image handling operations

1. Load an image and display it [code language="cpp"] //Loads image and displays #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> int main() { cv::Mat image = cv::imread("spots2.jpg", CV_LOAD_IMAGE_COLOR); if( false == image.data ) { std::cout << "Could not open or find the image" << std::endl ; return -1; } cv::namedWindow( "Display window", cv::WINDOW_AUTOSIZE ); cv::imshow( "Display window", image ); cv::waitKey(0); return 0; } [/code] 2. Add a trackbar to blend two images [code language="cpp"] #include <cv.h> #include <highgui.h> const int alpha_slider_max = 100; int alpha_slider; double alpha; double beta; cv::Mat src1; cv::Mat src2; cv::Mat dst; void on_trackbar( int, void* ) { alpha = (double) alpha_slider/alpha_slider_max ; beta = ( 1.0 - alpha ); cv::add...