C++/CLI being a .Net language it has its basic types directly mapping to that provided by the .Net framework. The structure below shows the various basic types of C++/CLI and the types they map to in the .Net framework. C++/CLI (use to declare) .Net / CLI Type Declaration Description bool Boolean bool isValid = true; […]
All posts by
Using Text Boxes
Update Settings After A Text Box Is Edited Use the ‘Leave’ event Locking the contents of a text box ReadOnly = True BackColour = Window (if you don’t want it greyed out) Read the contents of a text box String ^buffer; buffer = txtScreenContents->Text; Write to a text box txtScreenContents->Text = “Hello World\r\nHeres another line.” […]
Cursor
Show and hide the cursor Cursor->Show(); Cursor->Hide();
Re-sizable Forms
Making Form Re-Sizable AutoScroll Set to true, to enable scroll bars when needed. You can then just add controls outside of the forms size and the scroll bars will appear to allow then to be seen. Minimum Size Set the minimum size for the form Padding Set to force a bit of space after the […]
Right Click Menus
Create a ContextMenuStrip from the toolbox
Form Controls and Objects
Indexing Controls (refer to them by index number) Use a group box Stopping Refresh Of A Control ListBox->BeginUpdate(); //Supress drawing the listbox . . . ListBox->EndUpdate(); //Resume drawing of the list box Tab Control To see which tab is active use:- if (TabName->Visible) Visible doesn’t dictate if a tab is displayed, it tells you if […]
Add a form from another project
Copy the .h, .cpp and .resx files into the project directory. Right click the project name in the solution explorer and use 'Add Existing Item' to add them to the project. Select the .h file and then in the properties change the file type from "C++ Class" to "C++ Form" Troubleshooting missingmanifestresourceexception error Wth an […]
Setting Special Socket Options
Use SetSocketOption TcpSocket->SetSocketOption(SocketOptionLevel::Socket, SocketOptionName::DontLinger, true); TcpSocket->SetSocketOption(SocketOptionLevel::Socket, SocketOptionName::ReuseAddress, true);
Global Class Objects
Creating A Global Class Often its useful in an application to be able to use an object from anywhere. On first attempts this seems impossible for managed classes, but the solution is to use a class declared at the global level and have it contain the object you want to access from everwhere. Add To […]
Read File
using namespace System::IO; Read Bytes From A File __int64 FileByteNumber; int ReadByte; FileStream ^SourceFile = gcnew FileStream(SelectFileDialog->FileName, FileMode::Open, FileAccess::Read, FileShare::None); for (FileByteNumber = 0; FileByteNumber < SourceFile->Length; FileByteNumber++) { //—– READ EACH BYTE —– if ((ReadByte = SourceFile->ReadByte()) == -1) throw gcnew Exception("File read too short"); //ReadByte has the value but is actually an integer […]
