|
A cheap way to display files and hex data
|
Total Hit (4360) |
The .NET framework includes a ByteViewer control, that you can use on your own forms to display data stored in a Byte array or in a file. The ByteViewer control can't be added to the control Toolbox, though, so you must instantiate it through code only.
«Code LangId=2»
' IMPORTANT: this code re
....Read More |
Rating
|
|
|
Adding an image as an embedded resource, and loading it from code
|
Total Hit (3633) |
To add an image as an embedded resource in a Windows Forms application, add the image file to the project with Project | Add Existing Item. Then select the file in the Solution Explorer, go to the Properties Window, and set its Build Action property to Embedded Resource. At this point the file will
....Read More |
Rating
|
|
|
Adding events dynamically in a Windows Form
|
Total Hit (2875) |
The new AddHandler statement makes it possible to attach event dynamically, that is without having to bind them via static code based on the Handles keyword. This keyword is also useful to have all the controls on a form share the same event procedure.
For example, say that you want to change th
....Read More |
Rating
|
|
|
Bind a DataGrid to a DataSet at design-time
|
Total Hit (3282) |
Binding a DataGrid - or any other data-aware control - to a DataSet or a DataTable at runtime isn't difficult: you just have to assign the DataTable to the DataGrid's DataSource property, as in:
«Code LangId=2»
' DS is the DataSet variable
DataGrid1.DataSource = ds.Tables("Titles")
«/Code»
....Read More |
Rating
|
|
|
Adding an image as an embedded resource, and loading it from code
|
Total Hit (2614) |
To add an image as an embedded resource in a Windows Forms application, add the image file to the project with Project | Add Existing Item. Then select the file in the Solution Explorer, go to the Properties Window, and set its Build Action property to Embedded Resource. At this point the file will
....Read More |
Rating
|
|
|
Copying data into the Clipboard
|
Total Hit (4564) |
Copying a piece of information into the clipboard is as easy as calling the Clipboard.SetDataObject: you can pass this method a string, an image, and so on. If you pass it a string that contains text in Rich Text Format (RTF), the Clipboard object detects this format automatically. For example, the
....Read More |
Rating
|
|
|
A macro to protect a code section with a Try...Catch block
|
Total Hit (2992) |
When you're working with the Visual Studio .NET code editor, typing a Try keyword plus the Enter key automatically creates the End Try statement. The following simple macro does something more interesting: it lets you select a portion of code and protect it with a Try...Catch...Finally...End Try blo
....Read More |
Rating
|
|
|
Adding external commands to VS.NET's Tools menu
|
Total Hit (2692) |
The VS.NET's Tools menu can be customized with your own commands, to launch external programs. For example, you may want to have a command that opens the current project's folder in a Windows Explorer window, to easily manage the project's files. To add such a new command, click Tools | External Too
....Read More |
Rating
|
|
|
Changing the project's output type
|
Total Hit (3155) |
When you start developing an application, the first thing you do in VS.NET is creating a new project and selecting its type: Windows Forms application, Class Library etc. However, it may happen that later in the development you want to change the project's output type. For example, you could have de
....Read More |
Rating
|
|
|
Creating a project into an existing folder
|
Total Hit (2536) |
When you create a new project, VS.NET automatically creates a folder with the project's name under the selected directory. If you name your project MyTestProject, and select an existing folder named c:\My Project\MyTestProject as destination directory, in reality the final project's folder will be c
....Read More |
Rating
|
|
|
|
Creating applications that target .NET Framework v. 1.0 and/or 1.1
|
Total Hit (2654) |
As explained in this article, the applications you create with one version of the framework, can target only that version or both, according to the settings you put in the appname.config file. (Where appname is the full name of your executable file including the extension, such as myapp.exe, so the
....Read More |
Rating
|
|
|
Creating custom help filters
|
Total Hit (2722) |
If you open the VS.NET documentation (either from within the IDE or by clicking the respective icon under the Start | Programs| Microsoft Visual Studio 2003 folder) you can use the Filtered by dropdown box to select a filter, and load in the list/tree control below only the subset of topics you're i
....Read More |
Rating
|
|
|
Exception debugging in Visual Studio .NET
|
Total Hit (2549) |
The Visual Studio debugger offers complete control on what happens when an application throws an exception, or calls a .NET method that throws an exception. You set all the relevant options from inside the Exceptions dialog box, which you bring up with the Debug | Exceptions menu command. This dialo
....Read More |
Rating
|
|
|
Exception debugging in Visual Studio .NET
|
Total Hit (3077) |
The Visual Studio debugger offers complete control on what happens when an application throws an exception, or calls a .NET method that throws an exception. You set all the relevant options from inside the Exceptions dialog box, which you bring up with the Debug | Exceptions menu command. This dialo
....Read More |
Rating
|
|
|
Including/excluding files in Visual Studio .NET
|
Total Hit (2523) |
Say that that you have an existing Visual Studio .NET project, and that you copy a lot of new source code files, images and other stuff from another project (maybe you're merging two projects, or a colleague wrote and passed those files to you). One approach to include the new files is to use the Pr
....Read More |
Rating
|
|
|
Linking a file in Visual Studio .NET
|
Total Hit (2644) |
If in VS.NET you add to the current project an existing file that's located outside the current project's directory, the file is first copied in the project's directory, and then it's added to the project. However, you may want to share the same source file among multiple projects, so that if you mo
....Read More |
Rating
|
|
|
Marking strings with a different color in source code documents
|
Total Hit (2530) |
When you build strings by concatenating hardcoded constant strings and variable strings, it's easy to forget a closing double quote, and thus receive a compile time error when you launch or compile the program (actually, you see that there is a syntax error even before, because the statement gets un
....Read More |
Rating
|
|
|
Quickly swap assignment operands
|
Total Hit (2680) |
It often happens that you need to swap the operands of an assignment. For example, say that you have this set of assignments:
«Code LangId=2»
p1.FirstName = m_FirstName
p1.LastName = m_LastName
«/Code»
and later in your source code you want to add a similar set of assignments, but with rever
....Read More |
Rating
|
|
|
Running ILDASM from inside Visual Studio .NET
|
Total Hit (3020) |
Nothing beats ILDASM when it's time to understand what your VB.NET or C# compiler actually emits. In this case you should prepare a desktop shortcut to ILDASM so that you can run it quickly, and then open a Windows Explorer window on the Bin directory of your project, so that you can easily drag you
....Read More |
Rating
|
|
|
Setting up multiple start-up projects
|
Total Hit (2413) |
By default, a solution has a single start-up project, namely the project that is automatically launched when you click Debug | Start or press F5. However, you have the option to start multiple projects of the solution when you call Start, something that is very useful to automatically start, in debu
....Read More |
Rating
|
|
|
Settings pre and post-build actions in VS.NET 2003
|
Total Hit (2543) |
VS.NET 2003 comes with a nice feature that allows you to automatically run an external executable file before or after a build. For example, you may want that after a build a Windows Explorer window is automatically opened on the output folder, so that you can easily run the compiled program. Or you
....Read More |
Rating
|
|
|
Shortcuts to useful VS.NET's commands
|
Total Hit (2627) |
Visual Studio .NET has a number of useful features that are often underused by developers, because they are hidden under several menus and not easily accessible. Here is a list of keyboard shortcuts to some of these commands:
Ctrl + - : moves the caret to its previous position.
Ctrl + Shift +
....Read More |
Rating
|
|
|
|
Transform a variable into a Property
|
Total Hit (2596) |
Thanks to Visual Studio.NET macros, it is quite simple to automate the task of transforming a Public field into a Property with the same name that accesses a private field of the same type.
Press Alt-F11 (or invoke the Macro IDE from the Tools|Macros submenu, select one macro module in the left-m
....Read More |
Rating
|
|
|
Understanding VS.NET public and private assemblies
|
Total Hit (2841) |
As you might have noticed, the Add Reference dialog in Visual Studio displays all the assemblies in the GAC, which brings up the following question: is there a way to have this list display assemblies that aren't in the GAC? The answer is yes, and the technique couldn't be easier.
Use the REGEDIT
....Read More |
Rating
|
|
|
Visually browsing hierarchical files
|
Total Hit (2662) |
VS.NET has a nice feature that allows you to visually navigate through the content of hierarchical files, and quickly jump to a particular section. Hierarchical files are all those files written in XML-like syntax, such as .HTML, .ASPX and .Config files. To use this feature, click the View | Other W
....Read More |
Rating
|
|
|
Reading text files
|
Total Hit (3880) |
In Visual Basic .NET you read a text file by first opening a StreamReader on it, and then iterating over all its lines until its Peek method returns -1:
«Code LangId=2»
Dim sr As New StreamReader("c:\autoexec.bat")
' Display all the text lines in the file.
Do Until sr.Peek = -1
' The Re
....Read More |
Rating
|
|
|
Retrieve file version information
|
Total Hit (3628) |
The System.Diagnostics.FileVersionInfo class lets you easily read file version information without having to call Windows API functions (as you have to do under previous VB versions). This class has a static GetVersionInfo method that returns a FileVersionInfo object related to a given file. Once yo
....Read More |
Rating
|
|
|
A macro to protect a code section with a Try...Catch block
|
Total Hit (2984) |
When you're working with the Visual Studio .NET code editor, typing a Try keyword plus the Enter key automatically creates the End Try statement. The following simple macro does something more interesting: it lets you select a portion of code and protect it with a Try...Catch...Finally...End Try blo
....Read More |
Rating
|
|