The maximum value of a scrollbar can only be reached programmatically. The value of a scroll bar cannot reach its maximum value through user interaction at run time. The maximum value that can be reached through user interaction is equal to 1 plus the Maximum property value minus the LargeChange property value. If necessary, you […]
All posts by
Getting Arguments Passed To The Application Exe
//N.B. You can do this anywhere in the application – it doesn’t have to be in the main function. array<String^> ^arguments = Environment::GetCommandLineArgs(); if (arguments != nullptr) { for each (String ^argument in arguments) { //CHECK THE NEXT ARGUMENT //Note that if there we’re no arguments you still get the exe filename / path as […]
.Useful Things
DO EVENTS Whilst your application will be multi threaded if you hold waiting for something you need to use this to allow other tasks on the same thread to execute, and to tell the OS that your holding so it’s OK for it to attend to other things. System::Windows::Forms::Application::DoEvents(); Warning! Remember that using this can […]
Open File Dialog
using namespace System::IO; Open File Dialog Example String ^LastFileDirectory; String ^Filename; //If last directory is not valid then default to My Documents (if you don’t include this the catch below won’t occur for null strings so the start directory is undefined) if (!Directory::Exists(LastFileDirectory)) LastFileDirectory = Environment::GetFolderPath(Environment::SpecialFolder::MyDocuments); //—– FILE OPEN DIALOG BOX —– OpenFileDialog ^SelectFileDialog = […]
Create New Form
Creating The Form Project > Add New Item > Windows Form. Name it using 'frm' at the start (our convention) Set the 'Form Border Style' Set 'MaximiseBox' and 'MinimizeBox' properties Set StartPostion Set 'Text' Set 'icon' (or turn off ShowIcon) Nice Things To Do Add this before the constructor //********************************* //********************************* //********** CONSTRUCTOR ********** //********************************* //********************************* […]
Working With Strings
String Special Characters sTemp += "\r\n" //Add a newline String ^sTemp = = "\x7"; // ‘\x’ means ‘0x’ and the 1 of 2 digits that follow are a hex value for the character requried newline( LF) \n horizontal tab (TAB) \t vertical tab \v backspace \b carriage return (CR) \r formfeed \f alert (bell) \a […]
Pointers General
Dealing with pointers that haven’t been created yet To determin if the pointer myFile has been created use (for instance can be useful when trying to say close a file in an error handler if its been created): if (myFile != nullptr)
Using Error Catching
Typical Try Catch try { } catch (Exception ^e) { MessageBox::Show(L”Error:\n” + e, L”Error”, MessageBoxButtons::OK, MessageBoxIcon::Error); } Try Catch Without Error Code try { } catch (Exception ^) { } Finally //The ‘finally’ section is optional and goes after the catch section(s) finally { //Any code here will always be run, even if the catch […]
Working With Files
using namespace System::IO; Does file exist? if (File::Exists(“c:\\temp.txt”)) Copy File File::Copy(“c:\\temp1.txt”, “c:\\temp2.txt”); Move File File::Move(“c:\\dir1\\temp1.txt”, “c:\\dir2\\temp1.txt”); //Source, Destination Delete File try { if (File::Exists(“c:\\temp.txt”)) { //If file has read only attribute set clear it so that delete can occur if ((File::GetAttributes(“c:\\temp1.txt”) & FileAttributes::ReadOnly) == FileAttributes::ReadOnly) File::SetAttributes(“c:\\temp1.txt”, FileAttributes::Normal); File::Delete(“c:\\temp1.txt”); } } catch (IOException ^) { MessageBox::Show(L”This […]
User select directory example
String ^SelectedDirectory; FolderBrowserDialog ^SelectFolderDialog = gcnew FolderBrowserDialog(); //Setup dialog box SelectFolderDialog->Description = “Select directory to store files to”; SelectFolderDialog->ShowNewFolderButton = true; SelectFolderDialog->RootFolder = System::Environment::SpecialFolder::Desktop; try { SelectFolderDialog->SelectedPath = SelectedDirectory; //Try and use last selection } catch (Exception ^) { } //Display dialog box if (SelectFolderDialog->ShowDialog() == System::Windows::Forms::DialogResult::OK) { SelectedDirectory = SelectFolderDialog->SelectedPath; //…………. }
