A simple C#WinForm application which allows us to query IP addresses and returns the metadata associated with each queried IP address. This data is then displayed in a listView item. The default WinForms listView item has been replaced by the betterlistview control for a more aesthetically pleasing look.
INI files are mostly used in C++ and Delphi programming these days. Microsoft’s .Net framework focuses on XML-based config files not INI files. However it is still possible to read and write to INI files using C#. In this example I have created a very simple INI reader. It allows you to read/write to the config file ini_reader_writer_20xx-xx-xx.ini .
In this simple example I create a very simple DLL(Dynamic-link library) in C#. the library has to functions the first function is the Calculate method which allows us initiate a simple addition of the numbers in each numerical box.The second function is a logger to keep track of the addition problems we solve. The WriteLine method also shows us how we can write to and delete files in by calling methods from the dll_example_class_library.dll we compiled.
A simple method called Calculate just adds two numbers together using the dll_example_class_library.dll DLL’s help to keep code more organised and also allow us to change functionality of programs without recompiling the EXE .
After the DLL is compiled we can add it to our project by: right clicking Refrences, clicking add reference, clicking browse and selecting our DLL
In order for us to use the methods in our class it has to first be initiated. Once initiated we can start using the methods in our logic.
A simple logger to write all the occurring events to a file in the root directory \ Logs folder of the application.
The logger class LoggerClass.cs processes the data and writes it to a .log file. the Class can also delete the current log file which is being written to.
public static class Logger
{
private static string LogFile = Application.StartupPath + "\\Logs\\Event_Logger_" + DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss") + ".log";
public static void WriteLine(string txt)
{
try
{
File.AppendAllText(LogFile, "[" + DateTime.Now.ToString() + "] : " + txt + "\n");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Could Not Append Text To Log File", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
public static void DeleteLog()
{
try
{
File.Delete(LogFile);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Could Not Delete Log File", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
Dark themed control and docking library for .NET WinForms.
DarkUI is an attempt to create a simple, extensible control library which emulates the look and feel of popular tabbed document interfaces such as Visual Studio, Photoshop, WebStorm, and XCode. Originally just a collection of bug fixes and enhancements built on top of WinForms, it has now evolved in to a fully working docking and control library.
It’s an inspiring library displaying the power of Windows Forms.
The best way to learn how to use DarkUI is to check out the Example project included with the source code. It’ll show you how to use the majority of the forms, controls, and docking components.
In my previous post I created a very basic telnet only application. So in order to add some new features to the application I will be using the ExtraPutty library.
We need to leverage the ExtraPuTTY.dll in order to use it’s functions in C#. So because ExtraPuTTY.dll is not a COM .dll we can use the DllImport attribute to call the functions within the library.
Calling the methods from ExtraPuTTY.dll
You can use dependency walker to take a closer look at the methods within a .dll file. This is especially useful when you’re building a program and want to see the capabilities of the library you are using.
Dependency Walker is a free utility that scans any 32-bit or 64-bit Windows module (exe, dll, ocx, sys, etc.)
Writing a small app to communicate over telnet has never been easier. Of course you could just download Putty or use Telnet in Windows CMD but wheres the fun in that?
Writing your own app has tons of perks, automation is what comes to mind… It’s common for programmers to have small helper scripts (for instance running batch scripts in windows to automate installations etc.) but windows .bat and PowerShell scripts can be limiting at times. Especially when you want the user to be amazed by your custom GUI.
ConsoleControlallows us to embed a CMD terminal into our Windows Forms or WPF application. In this case we are using Windows Forms. TentacleSoftware.Telnet is a Telnet library making connecting to the device much easier since we don’t have to write our own sockets protocol etc.
A small system reader app written in C# WinForms. The application reads the systems ram, processor and user details and displays them on the form. On program form load the application will run DXDIAG in the background and will save the text file to the root directory of the application. Once the program has finished the DXDIAG process you can click on the send button. This will allow us to send the DXDIAG file to any FTP server we have defined in the program.
As default I have replaced all the necessary details with the # symbol.
replace the # symbol with your FTP server details.
A very simple notepad application using the windows API. The following controls are used:
menuStrip: The topbar menu with integrated drop down boxes. The DarkClass.cs class allows us to change the color of this control.
openFileDialog: Lets us search for and open a file on our windows machine.
saveFileDialog: Allows us to search for a location and save a file.
fontDialog: Shows us the font control menu allowing us to modify our typography inside the text box.
The four main controls in this app
Inside the DarkClass.cs we can change the colors of the menustrip by returning the colors we define in the RGB format Color.FromArgb(46, 204, 113). This class is then called on the application load from the MyRenderer() like so:
menuStrip1.Renderer = new DarkClass.MyRenderer();
The DarkClass.cs class allows us to change the menu strip colors.
The solution is divided into 3 different folders: Classes, Forms and Icons. The Classes folder only contains one class which allows us to drag the form.
The Classes, Forms and Icons folder contain the meat and potatoes of the application.The DRAGCLASS.cs class leverages the user32.dll to allow us to drag the form around.
The Forms folder contains all the forms for the short project. these forms are all overlaid on the Dropshadow.cs form which is the faded red outline around each of the forms.
The Icons folder holds all the custom icons used in this project. Most of the icons used are packed into an imagelist component used by visual studio, however some are just pictureboxes that were added the good old fashioned way.
This project is purely visual, there is no back end logic whatsoever, It’s based on the Umbrella corporations logo fro the resident evil series.
When the login button is clicked an event is triggered initiating a 5 second timer. This is to simulate the authentication process which would be occurring if the application was in fact communicating to a server out there in the ether.
Once the the login button is clicked this example landing form will be displayed.
Some Tips:
– Set the image list color depth to 32 bits so the best quality can be leveraged.
-Search NUGET for an easy download of the XanderUI dll.
-Restore NUGET packages and clean + rebuild the solution often.