/Home /Archive /Syndicate /Blog /Support /About /Contact  
All Visual Basic Feeds in one place!





Channel: XTab (Ged Mead)

When you need to use XML data as a data source in a WPF application, most times you’ll probably pull the XML document down from the web, a server, a separate file, or other external source.  Occasionally though, you might have a situation where you can usefully embed the XML data right inside the project.  Obviously, you lose one of the (if not the most) important aspects of data handling -  the ability to chop and change the data at runtime.  But for the sake of example, if ... [ read more ]


We all pretty much take cursors for granted, don’t we?  You wave your mouse about and the cursor obligingly follows.  Easy.   But what happens if you want to take control of the cursor?  Sometimes it’s not quite so easy.  Based on problems I’ve seen raised in the past few years, here are a few techniques you might find useful when it comes to dealing with the cursor.   Cursor on a Windows Form This is fairly straightforward.  Let’s start with th ... [ read more ]


I’m not going to pretend that I’m much of an expert on web apps, because you’d soon see through that bluff.  But I’ve been experimenting with XML recently and wanted to try using an XML file as a data source for a data bound control in a web form. It’s quite interesting that although XML is just about everywhere now, an awful lot of it is hidden under the covers.  That tends to hide the fact that if you want to do some hands-on meddling with XML, you&rsqu ... [ read more ]


In WPF, as with many other technologies, there is often more than one way of achieving a particular result. Specific to WPF, there’s one mindset that says that it’s better to use the declarative approach of XAML rather than the imperative approach of code behind.  I’m not going to get into that argument today but with that in mind, I thought I’d look at how you can use an EventTrigger in markup, rather than an event handler in code. It will be a simple example, really designed only to s ... [ read more ]


You hear technical terms being thrown around all the time, and it seems to me that sometimes they can make a relatively easy concept sound difficult.   Take “Impedance Mismatch”, for example.  You’ll probably have come across this term if you’ve been looking at LINQ or the Entity Framework. If you look at the two words in their everyday sense, you have: Impedance  - an obstacle or something that gets in the way or blocks progress.   mismatch  - two o ... [ read more ]


Introduction If you use the ReportViewer control to display a report, you’ll typically select a report at design time, ready for display at run time.   Sometimes though you might want to give your users a choice of reports to view.  There are several  ways you can do this and one of them is to add a combo box to the Windows Form or web page and allow the user to select alternative reports from a list of choices.  This isn’t technically complex, but it can be a l ... [ read more ]


If you create a local report that uses a chart data region, it’s pretty smart in the way that it uses the categories to create the legend.  ‘Categories’, you'll know, are the field(s) you drop in the category fields pane, as shown below: If you include a legend in the report, each distinct category will be listed: You can see that I added data labels that display currency values to the chart.  If you want to know how to do this, you can check out my recent bl ... [ read more ]


I was working on a local report chart recently and decided to use a pie chart as the data region.  One thing pie charts often need is to have the values of the various segments displayed as data labels.  You can add these at design time quite easily by right-clicking on the chart series (which in this case is the pie shape) and selecting Show Data Labels:     When you run this chart using a ReportViewer, you’ll get the data displayed in a pie chart format ... [ read more ]


You can’t always be sure that every image that the user opens in a PictureBox is going to have the correct orientation. To save them having to twist their necks sideways to see an image that’s the wrong way round, you can easily implement rotation options. The Image class has an aptly named RotateFlip method that does what you’d expect. This method takes a RotateFlipType as its single parameter. The RotateFlipType is an enumeration that’s provided by the System.Drawing class and it offers no ... [ read more ]


Here’s another of those old tips I’ve re-found.  If you want to create the effect of text having a shadow behind it as shown here:   You can achieve this quite easily by using the GDI+ DrawString method and drawing the same text twice.  You first draw the text in a dark colour, such as Dark Gray as used here, or Black.  Then you draw it again in the main colour, but offset the start position of the drawn text by a couple of points.  The code I’ve used ... [ read more ]


I’ve just changed my PC and while I was copying over some of the old stuff I found several projects I’d created to answer questions people had asked on VB City. So, before those projects get lost in the mist of time again, I thought I’d use some of them as blog topics, because these questions seem to come up time after time.  Here’s the first of them. Display a random PictureBox Someone had a group of PictureBoxes and wanted to display one at a time in a random sequence.  Let’ ... [ read more ]


Just like Windows Forms, WPF RadioButtons are mutually exclusive inside a single container.  That is, if you put several RadioButtons inside a container of some kind then only one of them can be selected.  Take the following example: Four RadioButtons inside a WPF StackPanel.  Only one of them can be selected.  No change from Windows Forms. Where they do change is that WPF RadioButtons can be assigned to a group. This group is (or groups are) named.  What ... [ read more ]


Introduction I wrote a blog about hiding and showing tab pages back in the VB 2005 days. This is an updated version for VS2010 that approaches the task in a slightly different way. Here’s a TabControl that has a number of TabPages in its TabPages collection.     There are more TabPages than can be shown in one row, so the left and right arrow buttons automatically appear to allow for navigation. But what if you felt it would be better if the user could see the ... [ read more ]


Introduction There are lots of data binding options in WPF.  Which one you use will depend, among other things, on the source of your data.  if the source happens to be a collection of .NET objects then you may be interested in the ObjectDataProvider that is available in WPF. Using the ObjectDataProvider allows you to reference the data source directly in the XAML markup.  (The more common alternative is to create a DataContext in the code behind).  One advantage offer ... [ read more ]


This example shows how to take two images, merge them side by side, then print them.  I’ve chosen to put them side by side, but you can easily change the logic so that they’re placed one on top of the other. To shows the steps, I’ve used three PictureBoxes.  Two of them have images assigned. The third PictureBox will be used to display the merged image. It’s important to realize that there’s no need to have any of the images on display for t ... [ read more ]


Introduction In an earlier blog on this subject, I created a form that had a PictureBox, a TextBox and a couple of Buttons:     The user enters text in the textbox, then clicks the Go button to add the text to the picture.  The Save Picture button does what you’d expect. You can see the code for the above in the earlier blog . To be really useful, though, it would be much better if the user had more control over the look of the text. For instance, the ... [ read more ]


WPF doesn’t have a NumericUpDown control and, to be honest, sometimes in Windows Forms the NUD is a bit clumsy for what you want to use it for.  WPF has a handy control, the RepeatButton, that you can use to help the user increment a counter.  Basically, all they have to do is hold the button down and you can use code-behind to monitor how many repeat clicks they want. This differs from the standard button, where you have to keep releasing and re-clicking the button if you wan ... [ read more ]


  A problem that often crops up is how to delete one or more items from a collection.  In the case of this example the collection is a collection of strings displayed as a list in a CheckedListBox.     Deleting a single item at a time This code will delete a selected item:     Private Sub Button1_Click( ByVal sender As System. Object , ByVal e As System. EventArgs ) Handles Button1.Click      &nbs ... [ read more ]


I’ve already blogged about some useful features of the WPF TextBox, here and here .  In this this blog item I’ll cover a few more of them.  Specifically, they are: IsEnabled IsReadOnly IsReadOnlyCaretVisible IsUndoEnabled AcceptsReturn AcceptsTab ScrollToEnd Content navigation methods Object Browser First, just to cover a few things where standard features have changed.   As with many WPF controls, the common ‘a ... [ read more ]


If you’re used to using either the AcceptButton or CancelButton properties of a Windows Form, you might wonder where they disappeared to when WPF came along. Let’s say you have an input window like this one: And you want to set the button marked Continue as the Accept button and the button marked Cancel as the Cancel button.  If you check out the Properties pane for the WPF Window, you won’t find the AcceptButton or DefaultButton properties: Windows Forms: ... [ read more ]


If you want to add text to an existing image, you can use GDI+ to do this.  (You can also use WPF, of course, something that I’ll look at later.) Adding text to the image Here’s a form that has an image displayed in a PictureBox, together with some controls to add text to the image:     The steps involved in getting the text on to the image are: Create a bitmap that will mirror the content of the PictureBox. Use a Graphics object to hold that ... [ read more ]


Introduction Earlier blogs, here and here , introduced the basics of the DateTime class. In this article, I’ll look at the TimeSpan object.  As I explained there, the DateTime object is a particular moment in time and sometimes that’s what you’ll need.  Other times though you will need to know how much time exists between two DateTimes.  The TimeSpan object is designed to calculate and hold that value for you. A TimeSpan will hold details of a duration or a period ... [ read more ]


One of the potentially very useful features of the WPF TextBox is that it has a spell checking function built-in.  I say ‘built in’, but actually it’s not very obvious how to access it.  if you select a TextBox and view the Properties pane, you wont find it listed in there, nor will you bring it into view if you use the search window of the Properties pane.  As far as I know, the only way to include spell checking is to manually code it, either in XAML or in code-behind.  ... [ read more ]


Introduction I’m not sure that’s the clearest title I’ve ever written, but the scenario I have in mind is this:  You have various UI elements of a WPF Window bound to data, most of them with a path to a specific field.  But you want one TextBlock to display the result of a calculation that’s applied to a field. To be specific, in this example the data includes an Annual Sales figure.  You want to divide this by 12 in order to display the average mon ... [ read more ]


Introduction In these days where we have WPF to help us with those tricky bits of eye candy that we sometimes need, it’s easy to forget that with a minimum of effort you can create a lot of them still in good old Windows Forms.  The solutions usually involve GDI+ and this example is no exception.  What I want to do is to create a single label that has two lines of text, each line using a different font, font size, font color and font size.    Sounds tr ... [ read more ]


In a recent blog , I looked at how easy it is to add additional content to a WPF Button. Here’s the button I created for the demo: And this was created using the following markup:       < Button   HorizontalAlignment ="Left" Margin ="28,27,0,0" Name ="Button2" VerticalAlignment ="Top" >       < Button.Resources >      ... [ read more ]


Introduction This blog builds on the previous one.  That earlier blog uses an ObjectDataProvider to access a collection of DrinkProduct objects and displays the ProductName property. It’ll be a rare day when you only need to access a single property of a collection like this.   Very often you’ll want to display some kind of key list, like the ProductName, first and then show users further details as they select individual items from the ListBox.  So ... [ read more ]


Multiline TextBox One of the downsides of dragging and dropping elements from the Toolbox onto the Window is that very often you don’t want the default values that will be set.  In fact, you often don’t even want some of the properties.  I’ve always thought it a bit of an interesting conundrum that although it’s almost universally recommended that you don’t hard code the height and width of elements, one of the things that the Designer will do if you ... [ read more ]


Button Content One of the great advantages of WPF is that you can place a wide variety of different content in or on its controls. Buttons are no exception, and you can create more interesting looking buttons by combining some of WPF’s graphics features. Here’s a button that you could offer a user who wants more information on footballer George Best – it’s functional, but very unimpressive:   Even if I was satisfied with plain text (and I’m not ... [ read more ]


What’s today’s date? In the previous blog on this topic , I looked at the basics of the DateTime object. You saw some of the output formats and learnt about the Now and Today properties. I’m going to dig a bit deeper into those subjects this time. Here’s a code snippet that creates a DateTime that has today’s date as its date value. It then pulls out just the value of the Day part      Dim dt As New DateTime   &nbs ... [ read more ]


Introduction When you think about how many times we have to deal with dates and times in our everyday lives, you wouldn't expect that dealing with them in code would be much of a problem. But it seems that this really is a difficult area for many people trying to handle dates and times in their VB.NET code. Of course it doesn't help that there are various names for what is effectively the same thing - Date and DateTime, for instance; how do you know when to use one or the o ... [ read more ]


Here’s the scenario:  You’re setting up some kind of data binding in WPF and you want to list a property of a class in a ListBox.  You bind the ItemsSource property of the ListBox to a valid collection, but the display isn’t the list you expect.  Instead you get a repeating list that only shows the name of the object type.       For instance, in this example, the binding is to a collection of objects of the DrinkProduct class.  That class r ... [ read more ]


I’ve written several blogs about WPF ListViews, and somebody who’s been trying to use them contacted me recently and asked if I’d post up an example project to help them spot where they were going wrong. So this is it. The remainder of this blog is an overview of the sample project.  If you want more detailed explanations of the various parts, these are covered in my earlier WPF/ListView/ValueConverter blogs.  You can download and try the WPF Application project (VS/VB 2010 version) - ... [ read more ]


When you create table reports and you want to repeat the column headers on each page of the report, you might sometimes run into a problem. And by ‘problem’ I mean that basically it just doesn’t work.  So, after you’ve had a play around with it and a little chunter about how it always used to work in the old days, you’ll probably start a search for the answer. And that’s probably why you’re sat there now, patiently listening to me waffling on. One of the key words in the last paragraph ... [ read more ]


In this earlier blog , I mentioned that a Figure is a type of Anchored Block that has slightly more fine-grained control of layout. To take advantage of these additional features, you really need to place the FlowDocument in one of the FlowDocument readers that WPF provides. The best options are: FlowDocument Reader FlowDocument Page Viewer The following sample uses several of the layout properties of the Figure element. The screenshot shows a FlowDocument that is contained in a Fl ... [ read more ]


Introduction When you’re creating documents, you’ll often want to have a mixture of text and images.  You’ll also need control over where the images are placed in relation to the text and will also want the display to continue to flow nicely as the user changes the size of the document container.  Figures and Floaters (collectively known as Anchored Blocks) will help you to do this.  These are essentially two versions of the same element, the difference being that Figur ... [ read more ]


I often write blogs about problems that I’ve had and which, eventually, I’ve managed to solve.  This is one of them.    If you’ve landed on this blog because you’ve seen this error message, you’re probably trying to create a report with the ReportViewer control. (There are other scenarios where this message might appear, but this is the one I’m working on.) In my case, the message came up when I tried to run a fairly simple report in a Windows Form using the ReportVie ... [ read more ]


  I saw that the LearnDevNow site is offering a big discount on their standard price, so thought it worth checking out their offerings.   You can either subscribe to one or more of six technology areas: SharePoint SQL Server and BI Visual Basic Web Visual Basic Windows C# Web C# Windows   or for much better value, subscribe to the whole range of more than 2,500 videos.  It’s an annual subscription basis – currently $49.99 ... [ read more ]


A friend asked me recently if it was possible to access resources that were created and stored in a separate assembly. Although I was sure it could be done, I’d never tried it, so I was interested in experimenting with this idea.  It turns out that the Pack URL holds the key.  Here’s an example. Access a single ResourceDictionary In a ResourceDictionary file named Dictionary1.xaml inside a standard WPF Application project named ‘Resources’, I have the fol ... [ read more ]


I’ve written lots of blog posts about WPF and in most cases the selection of topics has been a bit random.   Essentially, if it interests me at the time I’d write about it.  The problem with that approach is that it might assume a more basic grasp of WPF than many readers have. In a recent post on VB City, someone said (in a discussion about WPF): “I don't know where to start and a WPF primer would be good”.  Not knowing where to start ... [ read more ]


WPF FlowDocuments can be very rich in content.   Mostly you’ll appreciate the ability to lay out text and images in just about any configuration you can imagine.  But in some  circumstances you might need to include other elements, such as shapes, controls or other media elements to a FlowDocument.   We’ll look at each of these in turn over the course of a number blog items.   Images Including an Image in a FlowDocument is relatively simpl ... [ read more ]


In previous WPF RichTextBox blogs, I’ve looked at ways you can display plain text and RTF content.  Plain text and Rich Text Format both pre-date WPF and there are lots of scenarios where this might be your type of text source.  But if you begin to move into WPF in a serious way, you’ll probably find sooner or later that you need to display FlowDocuments. Although there’s quite a learning curve needed to get to grips with WPF’s verbose markup for FlowDocuments, th ... [ read more ]


In previous blogs, I looked at how to access a plain text file through a RichTextBox and then how to open and save content in RTF format .   In the second blog, I also looked at some core editing features which are available as keyboard shortcuts. This time I want to look at how to create a simple text editor based around the RichTextBox.  I also want to cover the scenario where you load a file of one type, such as a plain  text file, make changes and then save it as an ... [ read more ]


In an earlier blog , I looked at how to load and save plain text between a RichTextBox  and a txt file.   This time I want to look at a different case where text formatting has been applied to the content.   For the purposes of this sample I’m going to take a document that has been created in MS Word.  One of the many formats that both MS Word and WordPad support is RTF.   You can view and edit the RTF document in the RichTextBox. The WPF Window ... [ read more ]


The RichTextBox can be a very useful control to take in text input from a user.   With minimal work, you can create a reasonable text editor based on this control.  But there’s not much point in having a multifunctional RichTextBox around if you can’t save the input or redisplay it when needed.  So in the next few blogs I’m going to demonstrate some of the ways you can load and save content with a WPF RichTextBox.   Loading Plain Text Files OK, so ... [ read more ]


  In   an earlier blog     that looked at how to display available fonts, I used an automatic Style (that is, one without an explicit key).   These are sometimes also referred to as Keyless Styles .     < Style TargetType ="TextBlock" >        < Setter Property ="Foreground" Value ="Red"/>     </ Style > ... [ read more ]


In this earlier blog , I introduced the basics of creating an Entity Data Model (EDM) and using LINQ to run queries against it.   In this article, I want to look at how to create queries that will pull  data from more than one table.  In other words, the LINQ to Entities way of accessing related data that would require the use of INNER JOINS if you were using SQL queries. Extending the Model To keep things simple, the original EDM contained mapping to just one table in ... [ read more ]


Somebody asked me to create a starter sample intended just to show the absolute basics of using LINQ, Entity Framework and a SQL Server database, so this is it.   I’m using VS 2008 for this demo. All I’m going to do is to connect to the Northwind database, create an Entity Data Model and then run a query against that model to fetch some data.   Setting up the Data Connection If you already have this connection set up, you can of course skip this section. &n ... [ read more ]


Introduction In this earlier blog , I showed how to create a simple transition effect of moving an Image into view from left to right.   This time I’m going to tweak that example by adding some additional Images and daisy chaining animations.   Adding a Second (Visible) Image The first change I’m going to make is to place a second Image in the StackPanel.  This Image will be overlaid by the Egg Timer image when it animates.  Here is the markup ... [ read more ]


One of my favourite lines from The Simpsons is where Homer says, “Doh, every time I learn something new I have to forget something I know to make some room in my head!”.     When I find myself making repeat mistakes that I made years ago, I know just how he feels.   Here’s one that came back to bite me, which might help you if you’re currently sat staring at the above error message in Visual Studio. While trying out the drag and drop dataset ... [ read more ]


This is the continuation of the deeper look into the MSDN EF Quickstart.  Part 1 is here.   5.   Querying Entities and Associations a.   To query the departments in the School database Step 2:   ' Create an ObjectContext instance based on SchoolEntity. Private schoolContext As SchoolEntities Although the previous section tells you that generating the EDM:  “Creates a source code file that contains the class ... [ read more ]


I was flitting through various beginner examples on Entity Framework and queries and landed on the MSDN Quickstart here .  It works fine and the step by step instructions are clear enough.   Although there are various linked follow-on articles that cover some of the background, I did wonder if some beginners might find it all to be a fairly steep learning curve and be tempted to give up almost at the start.    So I thought that maybe it might be a help to some beg ... [ read more ]


Introduction In previous blogs I’ve looked at how to create the effect of a shape or an image moving into view.  Mostly I did this by animating the Width or Height property so that the element was almost hidden at the start but expanded to full size over time.  With this approach, the element starts very small and is expanded.   It’s easy to implement and will often be what you want, but it doesn’t allow for what I think of as the ‘sliding blocks&r ... [ read more ]


Introduction In my last blog on ProgressBars I mentioned a scenario where it might be nice to have two Rectangles simultaneously moving from left and right to fill the space occupied by an Image.  This was the 'Woman At Window' ProgressBar, described here . As far as I know, you can't use the ProgressBar Track to achieve this effect, but it's very easy to do by building up either a composite element in a Window or as a User Control.   For th ... [ read more ]


I ntroduction I was looking for a way of using a ProgressBar to give a kind of a 'closing down' message to the user .  Although I played around with lots of ideas, I eventually settled on one where I use an image of a person at a window and animate the ProgressBar to give the impression of a blind coming down. The ProgressBar ControlTemplate consists of an Image as the Track (i.e. the background) and a solid color Rectangle as the Indicator (th ... [ read more ]


Introduction In this earlier blog , I looked at how to use a ComboBox to display a list of all the system fonts, displaying each font name in its own font style. I mentioned there that fonts are something of a special case, in that this collection of fonts is automatically cached for you after you first use it. The result is that when you run the application for the second and subsequent times there is minimal delay between the time the user clicks the ComboBox down arrow and th ... [ read more ]


  Introduction In this blog I want to demonstrate several things. The first is how to reveal a text message in a ProgressBar. This is easy to do and you can get reasonably close to the moving marquee effect that you can see on some digital displays. A more important topic that I'll cover is TemplateBinding in ControlTemplates. This makes it easy to use a core template, but allow individual instances of the control type that use the template to tweak selected properties. In this ... [ read more ]


    In some of my earlier blogs - here , here and here , I looked at some rather colorful, non-rectangular versions of the ProgressBar. Although you probably wouldn't want to use some of those versions outside of a game environment, I hope it did show you how you can create and tweak non-rectangular versions. In this blog, I want to examine a less bizarre variation and along the way hopefully show you some more useful WPF basics. Reversing the Default ProgressBar ... [ read more ]


Introduction In the blogs here and here , I described how to create non-rectangular ProgressBars. Essentially, what you do is create a geometric Path that describes the desired shape of the outline of the bar and this is used as the named PART_Track of the ProgressBar ControlTemplate. In this blog, I want to look at a variation of this idea, in which the actual shape of the ProgressBar is the word "Loading ..." . Using this Path together with the ProgressBarBrushConve ... [ read more ]


  Introduction In this earlier blog , I looked at how to create a non-rectangular ProgressBar. As the next step, I want to look at how you can change properties dynamically as the current Value of the ProgressBar changes. I'll start with the easy (and fairly realistic) scenario where you want to tone down the ProgressBar once it has reached its maximum value. Currently the ProgressBar coloring looks like this: If you want to apply changes to the look of the Progr ... [ read more ]


  Introduction Sometimes it can be useful to display a list of fonts and allow a user to select one and have it applied to one or more controls in a Window. This is very easy to achieve, but - as usual with WPF - there are several options and a couple of things you have to be aware of. List Fonts in a ComboBox The initial requirement here is to display all the available system fonts in a ComboBox and have the name of each font display using the actual font it represents: S ... [ read more ]


  Introduction Thanks to the availability of ControlTemplates in WPF, it is relatively easy to change the look of any control. That said, as soon as you start to become ambitious, getting the exact look and behaviour you want can become a bit complicated. In most cases, though, there is a way of achieving what you want. The first ProgressBar I want to create simply replaces the default rectangular shell with a curved shape like the one shown below. This is created by des ... [ read more ]


  Introduction In this earlier blog I used an XML file containing nested data items as the data source of a TreeView. In this version I will use a collection of objects as the data source. The details of the data are much the same as I used in the previous blog, with a couple of tiny changes to avoid any possible confusion caused by the use of Visual Basic keywords as field names: These classes are saved in a VB file named SalesData.vb. Because it is fairly lengthy, filling ... [ read more ]


  Introduction For some reason, I struggled with HierarchicalDataTemplates when I first tried to use them. Although I understood the overall theory that they walk the data tree and can create formatted, nested output, I always seemed to spend an inordinately long time trying to get things to work just as I want them (or sometimes, to be truthful, to work at all!)   So I thought I would work through a few samples over the space of a few blogs, building up the complexity as I g ... [ read more ]


 In previous blogs I was looking at ways of grouping TreeViewItems. Those blogs included other features, such as changing the visibility of individual nodes based on the data content of each field. The blog that dealt with TreeViewItem visibility is here and the one that expanded the idea to include grouping is here . Although it worked to an extent, I wasn't really happy with the final result and you know how that can niggle at you - especially if you have gone public with it! ... [ read more ]


 In this earlier blog I described how to change the visibility of a line in a TreeView which has TreeViewItems that consist of two lines each. The original requirement also included grouping the entries under the different Categories. I purposely didn't include that at the time, because I thought it would obscure the main topic - i.e. changing the visibility. So in this item I will just expand the original project to include grouping. The first step is to create a n ... [ read more ]


An interesting question came up recently, where someone wanted to have a TreeView in which: Each TreeViewItem consisted of two separate lines of content but the second line may be hidden, depending on its content.   This was actually a Windows Forms question, but I wondered if this would be a good candidate for harnessing the graphical power of WPF to solve a tough WinForms problem. My idea was to create a WPF UserControl that had the features described above and ... [ read more ]


    In this earlier blog , I explained how you can create and use a Command to carry out a task based on a variety of user actions. These actions included key presses, mouse actions and key/mouse combinations, as well as clicking on WPF controls. At the time I said that if you didn't want to have the Image move unless the right mouse button was clicked directly on the Image itself (as opposed to clicking anywhere in the Window or on its other children) then you coul ... [ read more ]


  I've got to be honest and admit up front that initially I wasn't completely sold on the idea that WPF Commands are the great leap forward that they are sometimes billed as. OK, so I get that they can reduce the repetition of event handling code, but even their most ardent supporters aren't going to be able to claim that the required code is particularly intuitive. I will agree though that the availability of CanExecute is useful sometimes when multiple controls are ... [ read more ]


As I was finishing off the previous blog item on the Windows Forms ListView, it occurred to me that there isn't much documentation around to explain how to edit the ListView items.   So I thought it might be useful to cover a couple of approaches in this blog. If you're disappointed that there isn't a built-in way to edit all the items and sub items, the thing to bear in mind is that ListView is essentially a display control, rather than an editing one. That said, ther ... [ read more ]


 XAML is brilliant for creating user interfaces at design time, but if you need to make changes dynamically at runtime, this can sometimes be a problem. To take an example, let's say that you need to allow an Image to move to a different location on screen in response to some user action. To demonstrate this, we can use an Image which is housed in a Canvas. So the first step is to create a Canvas in a WPF Window, place the Image inside the Canvas and assign a value to the Sourc ... [ read more ]


 The Windows Forms ListView is designed to display data. You can use a simple text file as the data source of a Windows Forms ListView. Let's start with a scenario where you have a txt file that contains the data. Each line of the text file represents one row of data to be displayed in the ListView. The content for each column item (or cell) is delimited by the use of a TAB character. A simple text file along these lines might contain the following entries: Ged Mead UK Serg ... [ read more ]


  Introduction In the first part , I outlined the sample application and said that it: will create a collection of Person objects and databind them to a ListBox. will use very simple DataTemplates to format two properties of the Person class - FullName and Status. will use a GroupStyle HeaderTemplate to display a third property of the Person class - Category. groups the Person objects by their Category property. sorts the Categories and displays them in alphabet ... [ read more ]
Introduction I was going to title this blog "What's in a name?" because William Shakespeare's famous question smacked me on the head recently after what seemed like several hours of frustration. The answer in this particular case is "Quite a lot!". As you'll see when I cover the syntax used to group items, you can very easily fall into a trap when it comes to names. But first, I'll need to set the scene. This small application: will create ... [ read more ]


  In the previous blogs on ValueConverters - here and here - the conversion was from Integer type to Brush. In this blog I will cover the situation where you want to include a small image or icon in the ListView. There are various alternatives here. You could hard code the image path into the collection, but the problem may be that you don't know the exact image paths at the time the collection is created. The approach I want to use is where you parse the data as it feeds ... [ read more ]


  If you have read any of my previous ListView blogs, you will know that formatting the ListView is mostly a matter of creating templates and styles for the various sub-elements. The same applies if you want to do something to differentiate one row from another. For instance, you might to have horizontal divider lines between each row. This is the look we are going for in this blog:          The column headers were described in this ... [ read more ]


  The Story So Far Each of my previous blog items on WPF ListViews has mostly used a collection of DrinkProduct objects as the data source. This collection is bound to the Window via a DataContext and the individual columns are bound to fields in the collection. (As an alternative, this blog looked at the XML data source alternative.) As the route from that first ListView blog to this one has become a bit murky, I'm going to start off by recreating the DrinkProduct class an ... [ read more ]
In the previous blog , I created a simple ValueConverter that analyzed the data bound values and set the Foreground color of a TextBlock based on whether the value was less or more than a cut off value of 200 units. In reality, these preset values (such as the 200 in that demonstration) are rarely that rigid and you often need some flexibility in the analysis. To continue the example of a collection of drink products, it might be more realistic to compute a cut off value on the fly. For i ... [ read more ]


Sometimes it's the tiniest little changes that make you happy out of all proportion to the size of the change. While testing the WPF features in VS2010 I was totally thrilled to discover that at last when you type in the opening curly brace in the XAML Pane, you get an Intellisense list of useful choices. The top one, of course, is StaticResource . If I had a penny for every time I've laboriously typed out that name, I'd be a rich man! The same feature also offers other commo ... [ read more ]


 By the end of the previous blog item  on the topic of the WPF ListView, the ListView looked like this: In this blog I want to look at ways of changing the look of the rows. You may, for example, want to assign a background color to the rows. And based on what we have done so far, you might be tempted to edit the DataTemplates used for the cells. Maybe you would think about adding a Border with a Background fill and placing this around the TextBlock for each cell:&nbs ... [ read more ]


  I've often thought that dealing with dates and times can sometimes be much more difficult than it should be. There is a bewildering range of choices, many of which seem to do pretty much the same thing and you can sometimes wonder which is the 'right' way. One good example of the multiple choices is identifying a time. I don't mean a TimeSpan - which is a period of time - but a single specific moment in time, such as 8 o'clock, that you want to isolate and may ... [ read more ]


In the first WPF ListView blog  of this set, I used XML data binding and added some basic formatting to the Column Headers of the ListView. In the previous blog , a collection of objects was used as the data source. The formatting in that second example was a bit plain. So, in this blog I will look at some ways of breaking away from the standard monochrome ListView. First, let's revisit those Column Headers. Instead of the plain block Yellow I used in the first example, we ... [ read more ]


In a previous Blog , I showed how to databind an XML file to a WPF ListView. As some people are more comfortable with collections of objects than they are with XML, in this blog item I thought we could look at binding to a collection. One difference to note is that if you use XML data and XPath, you have the benefit of seeing all the data in the Design Pane at design time. With this collection of objects approach, the data is being created on the fly, so of course it can't be seen at ... [ read more ]


 A recent question on VBCity came from a developer who was searching for a way of changing the background color, font and border of the Column Headers in a ListView. This has always been a particularly tough call in Windows Forms. (A DataGridView, on the other hand, does have this feature, so that might often be an easy workaround.) But, as usual when questions of difficult layout come up, my mind turns to WPF as a possible solution. Usually I would say 'an easy solu ... [ read more ]


One small but sometimes useful new feature that was bundled with Service Pack 1 (SP1) of Visual Studio 2008 is the Splash Screen feature of WPF. This enables you to create an image file which is then used as splash while the main application spins up and loads. Probably the main selling point of this feature is its ease of use. Here are the steps involved:  Create or select a suitable image file Add it to the project in the Solution Explorer. Left-click on the file name in S ... [ read more ]


    I'm a big fan of WPF and WinForms Interop, so have often advised people to try the ElementHost when they want to do something graphically complex on a Windows Form. This useful little container allows you to create a WPF UserControl right there inside the WinForms project and then display those WPF graphics in a Windows Form.   One of the negative things about this in VS 2008 is that you always get a kind of error message inside the ElementHost at Des ... [ read more ]
  Here's a useful little tip for if you have a numeric value and you need to convert it into your local currency.   Let's assume you take in a value as a Double and you want the output to be in the format of currency, with two decimal places (in the case of the UK to represent Pence).   Here's the Double:  Code Copy      Dim TotalCost As Double = 123.4567     To show this formatt ... [ read more ]


Sorting a single array is a simple task. You just run the Shared Sort method on the array:          Dim arCustomers() As String = { "Williams" , "Brown" , "Smith" , "Jones" , "Green" }         Array.Sort(arCustomers)         For Each Str As String In arCustomers             C ... [ read more ]


  In the previous blog item in this series, I created a simple Animation in Visual Basic Code. This used a DoubleAnimation to animate the thickness of the gradient border. That example doesn't even begin to scratch the surface of what you can achieve with WPF Animation and - as you have seen demonstrated in the previous items - how you can include these animations in Windows Forms. In this part, we will look at a slightly more complex animation. Or at least one that seems c ... [ read more ]


Starting Point In my earlier post, the HiliteTextBox , I created a simple WPF UserControl which is hosted in an ElementHost in a Windows Form. If the user tries to continue without entering text in the TextBox, a bright colored Border would appear around it and stay there until the user does enter something.    If we are going to go to the trouble of harnessing WPF's graphics power, we may as well go a step further and add some animation to the control. One simple thing ... [ read more ]


Introduction      A recent forum post on VBCity asked for a way to highlight an important TextBox in a Windows Form. Assuming that the plan is to highlight the TextBox if the user is about to leave the Form without entering any text into it, there are of course several ways this can be done using Windows Forms techniques. But I thought it might be interesting to try something different and see how easy it would be to create a WPF UserControl that incorporated a TextB ... [ read more ]


Introduction   This is a re-post of an item that I had on my old blog.   As it seems to continue to get a lot of hits (when the site is up) I thought I would transfer it over here to the new site.   It is more of a "here's how" approach than a "why it works that way" one.  Also I will be creating everything in code, not markup.  There are several more approaches and advanced techniques available via XAML that I won' ... [ read more ]
      In this article, we will look at how to alter the background color that appears when a user selects an item in a WPF ListBox .   I've been using DataTemplates to organize the layout of WPF ListBoxes for quite a while now. Not only in my WPF Applications, but also in Windows Forms sometimes by using WPF/WinForms Interop (See my article on devcity for info on how to do this).   If you have used DataTemplates, you will know that the ... [ read more ]


This will be something of a 'Work in Progress' blog item, as I plan to jot down differences between WPF and Silverlight as I find them. It can be difficult to keep up to speed on these. The SDKs, Toolkits, roll out of new editions of both platforms will all cause the sands to keep on shifting. Anyhow, I hope those that I do identify will be of help to those of you who are familiar with WPF, but maybe not so much with Silverlight. The topic headings are listed alphabetically. Bu ... [ read more ]


   As a Developer, Visual Studio is my comfort zone but I thought the time had come to see what the experience of creating a Silverlight 2 project in Expression Blend would be like. Having spent the past six months working almost exclusively on Windows Presentation Foundation, I was particularly interested to find out how different the WPF and Silverlight experience would be. The first thing I had to do was update my copy of Expression Blend 2. Out of the box, your only Silv ... [ read more ]


      This is a question that seems to come up a lot in the forums:- How can I restrict the TextBox input to numerals, or only a single occurrence of a decimal point, or some other restriction?   As ever, there are several approaches. If the restriction is something basic, such as numerals only then the easy approach is to use the KeyPress event. What you can do is stop the character from appearing in the TextBox, test to see if it is allowable and, if i ... [ read more ]


    One of the things that first caught me out in WPF was the simple topic of colors. For example, let's say you want to reset the BackColor of a Form in Windows Forms. Easy enough. This will do the job:   Code Copy Me .BackColor = Color.CadetBlue   When it comes to WPF, you'll know that we are dealing with a Window, instead of a Form and have probably already picked up that BackColor is now Background .  You can however, stil ... [ read more ]


  If you develop in Visual Basic (and if you are reading this blog, I guess you do!) then you'll be as painfully aware as the rest of us that the number of VB samples on MSDN seems to be dwindling away. There was a time when you could guarantee that all the samples would be shown in both C# and VB. Not any more. These days, too many of the new articles come with C# only samples.     And before you reach for your keyboard to tell me that it's a trivial ta ... [ read more ]


    Sometimes you don't have control over how the data is saved to a text file. For instance, some items might be saved with quotation marks around words or phrases. If you want to read the file but not show these marks then you'll need a way to remove them.   Like a lot of things, it's actually very easy when you know how. You can use the built-in Replace function of the String class, replacing the marks as you find them. The trick though (and to ... [ read more ]


    I've always found ListViews quite fascinating. Slightly confusing sometimes, but fascinating nevertheless.   As I have often been heard to say, it's the little things that'll trip you up.     Take, for instance, the subject of this blog - copying an item between ListViews. The scenario is that you let the user click on an item in ListView1 and if they want this item copied to ListView2, they hit a button. Now, you would p ... [ read more ]


    There are millions of successful VB6 applications out there in the world. There they sit, happily whirring away doing whatever it is they do - perhaps occasionally being maintained or tweaked by an army of developers.   But there is no getting away from the fact that somewhere under the surface there is gentle but insistent pressure for developers and companies to move up from classic VB to the .NET platform. There are many reasons for this pressure, some ... [ read more ]


  I've seen this kind of question lots of times in the forums: " Help! I want to show a ProgressBar while I'm [doing something], but I don't know how long the process will take." The 'doing something' varies, but is often to do with downloading uploading, accessing files, reading from databases, etc.   Although there are some - sometimes quite convoluted - ways of solving the calculation problem, in most cases all that is really nee ... [ read more ]
  I've been meaning to blog about the tools I use regularly and find useful and I've managed to get a couple written this month. I'm always a bit concerned that blogs like this might end up looking like some kind of infomercial. But I eventually came to the conclusion that I've always thought that personal recommendation was the best kind of recommendation, so if I like a tool I should tell the world. Whether the world sets any store by my opinion is a matter for th ... [ read more ]


    I now have several WPF books. I've written reviews on some of them and often mentioned them in answers to Forum questions from members who want to start out in WPF.   When I wrote those articles and answers, my opinion was mostly based on my experience as a general reader who was interested in seeing what WPF had to offer and dabbling with it at a fairly elementary level. For the past three months though, I've been involved with WPF on a daily basi ... [ read more ]
    Some weeks ago I wrote a blog item about how to get the functionality of PerformClick in WPF.   I remember thinking at the time that it was a fairly clunky workaround and wondered why PerformClick hadn't been included in WPF. Of course there may be lots of reasons, beginning with 'No-one thought of it' and ending with 'It was just too difficult'.   But while looking at an apparently unrelated problem this week, it occurr ... [ read more ]


    When it comes to text handling in WPF, you have a massive range of tools available, some of which can offer you a level of granularity that was previously unachievable. I plan to write about some of these text tools, such as Spans, Runs and Glyphs in future blogs, but for today I want to look at something a little less deep.   Recently I needed to insert a carriage return in a block of text. The text was being created in the XAML markup, and I didn't par ... [ read more ]
  When it comes to text handling in WPF, you have a massive range of tools available, some of which can offer you a level of granularity that was previously unachievable. I plan to write about some of these text tools, such as Spans, Runs and Glyphs in future blogs, but for today I want to look at something a little less deep.   Recently I needed to insert a carriage return in a block of text. The text was being created in the XAML markup, and I didn't particularly want ... [ read more ]


  For several years, whenever I've needed to include code snippets in my blogs and articles, I've used a neat little application that VBCity member HotDog wrote. This has stood me in good stead until the day that XAML arrived on the scene. Unfortunately, XAML kinda confuses HotDog's AutoFormatter tool and I end up with missing angle brackets.   A bit of searching led me to a tool called CopySourceAsHTML. Although I had seen this used with Visual Studio 2005, there w ... [ read more ]
  One of the things that often pulls me up in mid flow when I'm putting WPF UIs together in a Window is that some of the core properties seem to have disappeared. Now, some of these are so fundamental that I know they have to be there, but obviously hiding under a different name.   Just recently, this happened to me twice in a row and I ended up scrolling through the Properties in the Object Browser, getting dizzy with the whizzing list of choices until I finally ... [ read more ]


      For the past week or so I've been getting those annoying little popup "Runtime Error - Do you want to Debug?" message boxes in Internet Explorer 7.   I've had them very occasionally in the past, but they were becoming a regular occurrence - sometimes three or four times in a row on the same page.    I managed to ignore them until that point, but finally decided that I'd better do something about it.   &nbs ... [ read more ]


  VBCity will be looking very different soon, as we change to the new Community Server based model.   In advance of that change, our blogs are moving to a new area.  From now on, you can view my latest blogs both here and at the new site here .  Once the new site is fully up and running, all new blog items will be posted on the new area only.  All previous blogs from VBCity Bloggers will still be available and hopefully will continue to rank ... [ read more ]
    For several years, when I've needed to include code snippets in my blogs and articles, I've used a neat little application that VBCity member HotDog wrote. This has stood me in good stead until the day that XAML arrived on the scene. Unfortunately, XAML kinda confuses HotDog's AutoFormatter tool and I end up with missing angle brackets.   A bit of searching led me to a tool called CopySourceAsHTML. Although I had seen this used with Visual Stu ... [ read more ]
     One of the things that often pulls me up in mid flow when I'm putting WPF UIs together in a Window is that some of the core properties seem to have disappeared. Now, some of these are so fundamental that I know they have to be there, but obviously hiding under a different name.   Just recently, this happened to me twice in a row and I ended up scrolling through the Properties in the Object Browser, getting dizzy with the whizzing list of choices un ... [ read more ]


  This question comes up every so often in the forums and it's one of those things that you'd think should be easy, but actually isn't. Well, it isn't until you know how - like most things in developer land. The question is usually something along the lines of "How can I grab the icon from an MS Word file?" The application may not necessarily be MS Word, but the that's the general thrust of it.   The only approach I have successfully used in this kind of scenario is th ... [ read more ]


   PerformClick is one of the many casualties of a move from Windows Forms to WPF. Of course, it's probably not something you would need to use often, but just in case you do then there is a way.   It's not a very intuitive way and - had it not been that I spotted the C# version of this trick in Adam Nathan's WPF book - I wouldn't be sat here writing this now. I'd still be searching endlessly to try and find the answer.    In order to achieve this in VB, ... [ read more ]


 Continuing my look at features that seem to be Missing in Action (MIA) from Windows Forms, vbCity colleague Matt pointed out to me that the Anchor property seems to have disappeared.   I'm really pleased that this came up, because it gives me an opportunity to highlight just some of the massive flexibility you have in WPF Windows when it comes to layout.  So what does WPF have to offer that will work as well as Anchors do? Umm, that should probably read 'better than Anch ... [ read more ]


  One of the things that first caught me out in WPF was the simple topic of colors. For example, let's say you want to reset the BackColor of a Form in Windows Forms. Easy enough. This will do the job: Code Copy Me .BackColor = Color.CadetBlue  When it comes to WPF, you'll know that we are dealing with a Window, instead of a Form and have probably already picked up that BackColor is now Background .  You can however, still use "Me" to reference the Wind ... [ read more ]


 For some time now, I've been promising myself that one day I will create a  list of what I like to think of as "WPF MIA" - those basic elements that I am totally familiar with in WindowsForms, but which somehow seem to have disappeared into thin air in WPF.  In many cases of course the tools are still there; it's just that the name has changed.   Here's an example:  In Windows Forms, you can hide the Minimize and Maximize buttons by se ... [ read more ]


  There's something that's always bothered me a little bit about creating classes. We go to the trouble of creating backing Private fields and Public properties in order to implement data hiding - right?   And when we want to include data validation, we usually use properties for that task, don't we?    But then what do we do? We go and create a parameterized constructor that lets client code push invalid data straight into a field. At least that's what I see ... [ read more ]


  I get a reassuringly high number of hits on my WPF  blog items, so I guess they're proving useful to a few people out there.  So it just occurred to me that I should maybe include a link here in my blog to a couple of WPF articles that I've written recently that are published over on our devCity site that might be of interest to newcomers to WPF.   The first one is an introduction to using FlowDocuments in WPF .    When WPF first came on the s ... [ read more ]


  One of the things that I've always found a bit frustrating as a project grows larger and larger is that it gets more difficult to navigate backwards and forwards between chunks of code that you've recently accessed.    Now I know that Visual Studio has some built in navigation hot keys: Ctrl and Minus to go back to the last point, Ctrl-Shift-Minus to go forward again are the most useful, but it can still be a bit laborious when you're trying to flit between ... [ read more ]


  I never cease to be amazed at how many ways you can fool yourself into thinking that your code will do one thing, but in fact it does something completely different. Sometimes the subtlety of the error is so fine that you can spend ages trying to work out the source of the problem and, to make life harder, there's no Exception message to give you a pointer and sometimes even using the debugging tools doesn't lead you straight to it.   I was working on something that ke ... [ read more ]


Introduction     You'll know by now that I'm quite a fan of WPF, but I have to say that my first excursion into using sound in a WPF application was a bit of a disappointment.  Rather frustrating too.   Maybe I expected too much, but I had this idea that the audio features would have been ramped up by the same kind of scale as the visual features have.  Sadly that's not quite the case and, although things have moved on a tad beyond having t ... [ read more ]


   I was looking for a task to use as the background task of my recent article on the BackgroundWorker component and decided that I'd use a recursive search through folders.   Ironically, I ended up spending about twice as much time on getting the recursive search procedures running correctly than I spent on the main BackgroundWorker code.    As I ended up with three varieties of recursive searches - and found  some things that ... [ read more ]


  One of the great things about WPF is its ability to let you use animation to enhance your user interface. (Or wreck it if you go too far!) In my opinion, subtle animations can go a long way towards improving the user experience.   One particular way is to fade colors in and out so that text seems to appear and disappear in a way that gives the impression of movement, but without any jarring visual effects.   Doing this in the XAML markup is well documented and ... [ read more ]


Introduction   Printing can often be a bit of a tricky task in .NET. Some things are more easily resolved than others though.   I saw a post recently that raised a problem that seems to occur fairly regularly: You want to print a large chunk of text to the printer, but VB seems to want to print everything all on one long line - even when this means that a lot of the text will be truncated or "printed" invisibly into thin air!   Fortunately, this is one of t ... [ read more ]


  Friday was something of a Red Letter Day in the Mead household, because that was the day that the book I've been looking forward to getting for months finally arrived on my doorstep. At last - a WPF book aimed at those of us who prefer to use Visual Basic for the code behind. The book is Matthew MacDonald's "Pro WPF with VB 2008", published by Apress.   In the couple of days since it arrived I obviously haven't been able to get too deeply into reading it - although my ... [ read more ]


  The latest .NET book from the Murach publishing house is "Murach's Visual Basic 2008". This book is essentially an update of their earlier book for VB 2005 which now includes additional coverage of new features such as Anonymous Types, Object Initializers and LINQ.   I've just been re-reading my original review of the 2005 book and much of what I said then applies equally to this latest version. Here's what I said then:   We all find that some particular a ... [ read more ]
  I've been working in conjunction with Evan Lim and Young Joo to convert the source code examples from Charles Petzold into VB.NET. As at today there still doesn't seem to be a WPF book on the market that has  VB.NET as the code-behind (although I know there are a couple on the way). Add to this the fact that many C# to VB converters at the moment still get it wrong with several areas of the new Framework, this is a real stumbling block for many VB developers who would oth ... [ read more ]


  This is something that seems to come up fairly often in the Forums. Someone wants to test for a particular value in a ListBox and if the list does (or doesn't) contain the value then that item is to be deleted.   One common way of doing this would be to use the Contains function to test if the target character or substring exists in the ListBox.    This isn't a particular difficult task, but the thing that usually catches most beginners out here is that you ... [ read more ]


  I've had a copy of the excellent Camtasia Studio from TechSmith on my system for a while now and I've been itching to find time to create a video demo or two.     Just as everyone warned me it would be, it's a lot harder and takes wa-ay longer than you think it will, but my first effort is finally finished.   As you can see from the blog heading, the video is a mini-tutorial on the subject of how to create a simple ControlTemplate in WPF.   The example I've used is a round button, jus ... [ read more ]


  Quite often as I browse through the VB.NET Forums on vbCity I see questions about tasks that can be quite difficult in WinForms, but would be much easier to deal with using WPF. One recent question that fits this description is the following one: "I am wondering how I can change a specific line of text in a listbox based on a condition. For example, if I subract listbox.items.item(1) from listbox.items.item(0) and the posted result in position (2) is a negative decimal then ma ... [ read more ]
First Chance Exceptions   I suspect that most of us have become so used to seeing the message that reads:- " A first chance exception of type 'System.ApplicationException' occurred in WindowsApplication1.exe "  that it hardly hits our conscious thoughts any more.   But did you ever check out just what this message really means or wonder whether you should or could do anything about it ?   I suppose the first thing you need to know in order to a ... [ read more ]


   I've been experimenting with the interaction between Visual Studio 2008 and Expression Blend (Version 1 with SP1). One thing I realised early on (right from the Orcas Beta days) is that Blend is a great help when you want to fine tune color gradients, create lines, shapes and paths or create animations. Having carried out both of these tasks by typing in the Xaml code in Visual Studio and checking the result, it's not something I'd want to do the hard way long term.    ... [ read more ]


   Adding controls at run time using VB.NET in Windows Forms is fairly well-documented. Finding C# code-behind samples for doing this with WPF controls under Framework 3.0 is also an easy task. But I recently wanted to see how to do this with a WPF application in Visual Basic 2008 and I found that at the time of writing my searches produced no useful clear "How To" results.    Direct conversion from C# to VB using the current conversion tools didn't always identify some essential code elem ... [ read more ]
  I've bought several books on Windows Presentation Foundation over the past few months and I've reviewed a couple of them already. As is usually the case, each of the books has something to offer and it's a rare day when you can find all the information you need on a complex, wide ranging topic like WPF in one book.   Without detracting from the other books that I admire, I think if one book does come closest to being a one-stop source then possibly it is the Pro WPF ... [ read more ]


  I've noticed a couple of questions in the VB.NET forums recently where someone wants to change the BackColor of the Tab Header on TabPages. As far as I know, in VB2005 and earlier you have to either use OwnerDraw techniques or subclass your own version of a TabControl.    In VB2008, WPF offers a much easier route. The equivalent element to a TabPage in Windows Forms is the TabItem in WPF. The WPF TabItem actually has its own Background and Foreground properties, each ... [ read more ]


  If you regularly read my blog you'll know that I like to flag up those silly little Gotchas that are minor in themselves, but massively frustrating when you come upon them and can't see the cause or the way through.  I was working on a project last night and got stuck on something that had me bamboozled for a while.   What made it harder to figure out was that I knew I had successfully achieved the result I wanted many times in the past without any problem.   Was it ... [ read more ]


  I see that the official fix has now been issued as a KB.  You can check it out here.


  So Visual Studio 2008 is finally here! After what seems like a long time using Betas, VS 2005 extensions and various other weirdly named WIPs, it's great that the full, final version has arrived.  If you haven't tried it yet and aren't ready to commit from your wallet then you'll probably be pleased to hear that VS 2008 also has a free, downloadable Express Edition. Well, "Editions" - as there are VB, C#, C++ and Web versions. The download site for the VB Express Edition is here ... [ read more ]


Introduction  Charles Petzold is usually a very popular technical author, so it was unusual to see that this book has had some quite harsh and critical reviews on the various book sites such as Amazon.     The gist of most people's complaints seem to be:  (a) "There's no XAML until Chapter 19" and/or (b) "There aren't any pictures".     OK, so I'm summarising and slightly trivialising the complaints, but that's essentially it. The Complaints - are they justifie ... [ read more ]


  I saw a couple of unrelated questions on vbCity recently - one was about PropertyInfo  and  the other was in regard to Colors - and seeing them reminded me about how easy it is to use PropertyInfo to get access to and list all the 141 named Colors.  There are of course other ways of doing this, but I just thought it would be a fun approach to use.   The following example is based on a Windows Form that contains a Button and a ListBox for ... [ read more ]


  I've spent much of the past few months getting to grips with WPF.  I'm still nowhere near the point where I can claim to be expert in this great new technology, but I thought it might help others if I blogged links to resources that I have found to be particularly helpful.   I'm sure I will add to this list as time goes on, but (in no particular order) here are some links that I'm sure you will find useful if you are just starting out with WPF. Jessica Fossler wrote a handy transiti ... [ read more ]


  I had to revisit this problem recently and so had to recall how I did it.  Here's the scenario:  You have a ListBox and a Button.  User selects an item in the ListBox.  If they want to move that item up the list they click the button.  They can keep clicking the button until the item reaches the top of the list if they want to, or just stop when they've reached the desired position anywhere up the list.   I don't know of any inbuilt way of doing this, so this was my fix: 1.  First se ... [ read more ]


   This book sets out to introduce WPF to professional developers.   Co-written by four authors, it covers a range of topics at varying levels .  Inevitably this kind of multi-author book has the feel of being a collection of specialist essays by experts in the various areas rather than a coherent, empirical textbook.   This may or may not be a bad thing, as the resulting book will have something for readers at all levels. (A good example of pleasing some of the people some of the tim ... [ read more ]


Introduction   Control Templates are a particularly powerful feature of WPF. They allow you to change almost any aspect of the look of a control, but - and here's the key benefit - you still retain every bit of the functionality pre-built into that control. So you can create, for example, a button that doesn't look anything like the rectangular one we are all used to, but when the user clicks on your version of the button you will have access to the button's events, such as the ... [ read more ]


   The Murach publishing house are unusual in that they only use a small group of in-house authors and all their books use the same structure and layout style.   This style is their individual “facing pages” approach.        How it works is that each pair of pages throughout the book deal with the same topic or sub-topic.   On the left hand page you get an explanation of the subject in hand.   Many times this explana ... [ read more ]


   Moving Beyond Simple Strings Introduction   In the previous item on Listboxes I looked at some ways of tweaking a WPF ListBox which contained only strings. As the range of what can be included in a ListBox is far greater than simple strings, I want now to move on to more complex displays.  In WPF it is very easy to create listboxes that contain a variety of content types. For example you can list a collection of images one below the other: &n ... [ read more ]


      WPF Layout - The StackPanel Introduction  One of the more basic panels provided in WPF is the StackPanel. As you would expect, it stacks its child elements one after the other - by default stacking them vertically. You can however override this setting and change the Orientation to Horizontal. As with the WrapPanel, I think that in the majority of cases you will use this panel as part of a larger, more complex display.  To begin with ... [ read more ]
Styles in WPF (2)- Styles, Resources and ResourceDictionaries   Introduction  In the first part of this article, we looked at a simple style that was created and applied to a set of Buttons. Each button has the same Background, Foreground, MinWidth, MinHeight, Margin and Padding. The resulting display looked like this:    In point of fact, the amount of code reduction in that example was small. That's because the example uses only five buttons. Bu ... [ read more ]


 In an earlier blog item we looked at a DockPanel in which the Button and the TextBlock were muscled out of the view by an Image that grabbed all the available Window space. The code in that example was: Code Copy < DockPanel   >       <!--  First Item :  A large Image -->        < Image Source ="Images/Pictures 106.jpg" DockPanel . Dock ="Top ... [ read more ]


No More OwnerDraw! Introduction   In Visual Studio 2008, thanks to the introduction of Windows Presentation Foundation, the humble ListBox finally comes of age. In previous incarnations, if you wanted to do anything but the most basic tweak of the user interface of a ListBox you usually had to resort to using OwnerDraw techniques and your options were quite limited. WPF really lifts the lid off the ListBox. (Sorry - I just couldn't resist that one!).  Now you can create very c ... [ read more ]


This is the second edition of David Sceppa's excellent and comprehensive guide to all things ADO.NET for both VB.NET and C# developers. This book covers the whole topic in great detail and is packed with explanations and usable sample snippets. It will be useful for developers across a wide range of experience of database access, from relative beginner to experienced VB.NET practitioner. Although it is possible to pick and mix from the various chapters, I found that I got by far the best ... [ read more ]


   Introduction  If you looked at my earlier blog item on WrapPanels you may remember that I raised the question as to whether it was really necessary to have so much laboriously repeated detail for the five buttons, i.e.:- Code Copy        Button Background ="Black" Foreground ="White"   Margin ="12,3,12,3" Padding ="3"        MinWidth ="75" MinHeight ="34" > Open Button >       Button Background ="Black" Foreground ="White" ... [ read more ]


      WPF Layout - The WrapPanel Introduction  As its name implies, this kind of panel is designed to dynamically change the layout of its children by wrapping them horizontally or vertically as necessary in order to try to keep displaying them for as long as possible. Obviously, if you don't set minimum size values it will eventually become possible for the children to be cropped or finally disappear, but the WrapPanel does its best to display as much as it can.  This can b ... [ read more ]


      WPF Layout - The DockPanel Introduction  The DockPanel probably offers you a better option than the UniformGrid in many cases. However, this layout panel too is not without its eccentricities and you can spend a lot of time tweaking and fiddling with settings in order to get the exact display you want.  However, if your needs are simple then the DockPanel works well.   You do have to be aware of the effect of its "Pecking Order" approach to layout and distribution ... [ read more ]
 As I had some feedback on how the images are accessed in my blog item on UniformGrids , I thought I would just very quickly explain what I did.  There are a whole host of approaches you can use to create, store and access resources in WPF. Many of them are very similar to what you would do with Windows Forms. Some are quite new. I will be writing in more detail about the new ways later, but for now I only want to cover the very basics; just enough to get you started.  The XAML code I ... [ read more ]


  This tip barely qualifies as a Gotcha! but I have seen some people get stuck with it, so thought it worth a mention.    If you want to control exactly where a second form is placed in relation to another form, you can use code that shifts the second form to either side or above or below the first one.     The key is to ensure that you set the StartPosition of the forms to "Manual".   If you do this, each form in the project that i set to Manua ... [ read more ]


 This layout panel is quite limited in what you can do with it, but it does have one rather rare advantage when it comes to WPF - it is simple to use! So for that reason it's a good layout panel to start off with.   The UniformGrid contains cells, just as you would expect with any grid. However, you have little control over those cells. What happens is that the UniformGrid assigns individual cells for each element you place within it. But - and here's one of the major limitations ... [ read more ]


  The latest (and final) Beta for what we used to know as Visual Studio CodeName Orcas has now been made available.   Visual Studio 2008 Beta 2 can be downloaded from here .   According to the team at Microsoft, this version is now feature complete.  The next version -  RTM version - will ship before the end of the year and the final product release is scheduled for February 2008.    Although still a hefty download, it's less bulky ... [ read more ]
    I was discussing Windows Presentation Foundation (WPF) recently with someone on VBCity.   Although many people don't have the time or available capacity to download the huge Visual Studio 2008 (previously known as Orcas) Beta on a development machine, it is still possible to get a foretaste of what's to come.   If you go to this link you can download the Framework 3.0 Extensions for Visual Studio 2005.  Now, it's getting a bit dated and the VS 2008 Betas ... [ read more ]


WPF Articles Running Index The WPF Articles I'm writing seem to be taking the form of a fairly meandering journey of discovery. Probably not quite as exciting as white water rafting down the Amazon, but along tbe way there are definitely some interesting things to see in between the parts where you just have to keep paddling to keep moving upstream.  It occurred to me that as it isn't very compartmentalised that it might be useful for you (and probably for me too) to have ... [ read more ]


  Introduction In the previous parts we looked at ways of hiding and showing a single Tab Page in a TabControl. In some situations you may need to hide and show multiple pages.  This is still fairly easy to do, but now you need a collection in which to hold the TabPages you have removed. (Remember from the previous descriptions that you are not really hiding the TabPages, you are in fact completely removing them, but storing a copy in memory that you can later call on to reinst ... [ read more ]


(a.k.a. WPF for Windows Forms Developers)   I'm really enthused about WPF. Not just the Wow! factor things like 3D and animation, but even the more basic features - like for instance the way that you can take control of layout and achieve intelligent resizing without fiddling around with Anchor and Dock settings.  But of course progress usually comes with a price tag - and I'm not thinking of the cost of software here. There's a price to be paid in the sense that you ... [ read more ]


In the previous part I looked at a very simple scenario where the developer knew in advance which TabPage should be hidden and re-shown. Next we'll look at doing the same thing, except that this time the user gets to choose which TabPage is hidden. As in the previous example, you're going to need some kind of trigger to kickstart the Hide or Show activity. I've used a button placed outside the TabControl on the form itself, but you could use any other trigger that suits your purpose - e.g. ... [ read more ]


AfterNote:   There are now three blog items on this topic, each showing a different aspect  If you want to view them all as one article, follow this link )   Sometimes you may want to hide a TabPage from the user's view, but you don't want to permanently remove it.   Now, if you've checked out the TabPage's methods you will see that it does have a "Hide" method in VB 2005. That's great, but the trouble is if you try using it, it doesn't work!   You won' ... [ read more ]


As I've said on many occasions in the past, it's those sometimes tiny little Gotchas that will cause you the greatest amount of aggravation. Here's one that I've been meaning to blog for a while now. It's a question/problem that comes up fairly often and it usually goes something like this:- "In a Windows Forms project, I add a module that has a Sub Main procedure in it. I want to use this Sub Main as the StartUp Object in the application. But when I look in the project properties, I don' ... [ read more ]
a.k.a.  The Power of the PrintForm Power Pack! Introduction Let's face it, ease of printing in VB.NET has never been its main selling point. In fact, because you literally have to draw most of what you want transferred to paper (or save some kind of screen capture to an image file and then print that), it really can be a bit of a pain. I knew that the Microsoft VB Team had created an additional Power Pack which prints Windows Forms directly to the printed page but hadn't got roun ... [ read more ]


I've spent most of my free Orcas experimentation time on Linq so far, and the occasional foray into the wild world of WPF. I really want to get to grips with WPF in the next few months. It's not going to be easy stuff, that's for sure, but hopefully the results - graphically at least - will be worth the effort. Saving Project Files I've noticed a few changes in the Orcas/2008 IDE. It seems that we've gone full circle again on project file saving. In Orcas, your new project is automatica ... [ read more ]


  As mentioned earlier, there is a Hands On Lab available from Microsoft which walks you through some basic (and not so basic!) steps in using Linq To SQL.  The download page is here.   Here are a few observations on the Linq To SQL Hands on Labs that I jotted down while I was working through it : So Much Reassurance is, umm, Reassuring!   One aspect of the Labs that I particularly liked was that the narrative was full of helpful notes to reassure me as I w ... [ read more ]


   I'm still very much just feeling my way tentatively forward with LINQ to SQL, but my first reaction is one of relief that it really is very similar to the LINQ to Objects approach and so the learning curve is minimal. Of course, there is the small matter of connecting to database that isn't a factor in LINQ to Objects, but so far the use of DataContext has been painless. (Hope I'm not celebrating too soon!)    A new Hands On Labs that is now available from the Visual ... [ read more ]


  I'm not usually a fan of blogs that link to blogs, but I thought that  this item by Scott Wisniewski of the Visual Basic Team is so useful in clarifying the situation that I would flag it up.    We're all used to mentally switching from Codenames like Orcas to the final version names (which now is VB 2008, apparently), but this year the ongoing stream of new products and additions to current ones is more  mind-boggling than at any previous time that I can re ... [ read more ]


We covered how to check and uncheck individual items in code in a CheckedListBox in Part 1. In this part I want to quickly run through some ways you can save and retrieve user's choices. Original List Let's start with a list of items, such as: Red Blue Green Large White Small House Pink Puce Orange Black In our example project they are saved to a plain text file named "Colors.txt". So the first task is to load this list into the CheckedListBox when the form first loads: ... [ read more ]


   Although some of the queries we saw at the end of Part 2 are quite impressive - and light years easier than doing it with Loops and If/Then tests - there are still more improvements to come.   Let's take the situation where you want to run Join queries across two separate data sources.  This is something you'll commonly do with Access or SQL Server, etc, data sources but not something you'd automatically think of doing with, for example, a couple of ... [ read more ]


   Thanks to my VBCity colleague, Scott Waletzko a.k.a. Sp!ke, I'm now happily sat here with the Orcas Beta 1 fully installed and running smoothly.   I'd suffered more than my fair share of pain when installing the March 2007 CTP so I was a bit concerned that the Beta would be a re-run of that.     The VPC version had been a particular nightmare but I did get a more or less working version up and running eventually.  &n ... [ read more ]


   This blog item was originally going to be about ten lines long and all I intended to show was how to programatically uncheck all items in a CheckedListBox in VB 2005.  But, you know how it is, you think "Hmm, what about if ...?"  or "What if I ... ?" and before you know it, you've got a mini-article.   So, before I forget why I started writing this item, here is the code needed to uncheck all items in a CheckedListBox: Programatically Uncheck All Item ... [ read more ]


Let's Run Some Queries!    By the end of Part 1 we set the stage and looked at a couple of new features coming up in Orcas, but hadn't done anything particularly exciting and new with LINQ To Objects.   In this Part I'll hopefully whet your appetite for LINQ a little bit more as we run some queries that are (a) very easy with LINQ and (b) nowhere near as easy with VB 2005 and earlier edition tools.  (And later in Part 3 you'll really ... [ read more ]


   Beth Massi, who joined Microsoft recently to take up a post on the  VS Core Community Team working with the Visual Basic Team producing developer content for MSDN has just produced and released a very informative set of 8 How-To videos for VB.NET developers.   These take you through the key steps involved in creating a SQL Server database in Visual Studio, accessing the data, displaying and using it in a Windows Forms environment.   Some of the topic ... [ read more ]


  Another of the new features that came with VB 2005 is the way you can now set ComboBoxes and TextBoxes to autocomplete based on user input.   You know the kind of thing: the user begins to type a string and the system suggests variations on the completed string.  The user then accepts the suggestion or continues typing until they find an acceptable suggestion or until they have entered the whole thing manually.   It's remarkably easy to implement.  Here's a ... [ read more ]


   There's no doubt that LINQ is one of the headline features of Visual Studio Orcas.   I've been trying out some LINQ queries; it's a very interesting new area with massive potential.   It seems though that most books and articles available at the moment are C# based, so I thought I'd blog my journey through the Land of LINQ in case any other VB DotNetters might find it useful now or in the future.    I'm currently using The Marc ... [ read more ]


  I mentioned some of my favourite VS 2005 keyboard shortcuts in my blog a few days ago.   I see that Microsoft are now offering posters that list the default key bindings for VB.NET and C#.   You can visit this page for the VB ones, download them, print them out and put them on your wall to replace that picture of Cameron Diaz.   OK, well, maybe that last step is taking productivity far too seriously,  but i ... [ read more ]


  Its obviously b een a busy day or two in Redmond.   Fast on the heels of the March CTP, the Beta 1 version of Orcas is now available for download.   It looks like only the VPC version is availabe as at today but hopefully the bits version will follow(?).   Also just out on the stall  are the VB versions of the LINQ samples    which were incomplete in the March CTP.  


   Having spent way too much non-stop time on the computer recently, I've had a spot of bother with RSI.  So given the choice between not using the computer at all and finding a way round the problem, finding a way was the only realistic choice!   One thing I decided to do was use shortcut keys much more than I had been doing.  I sometimes think that mouse is permanently attached to my right hand .   I came across a handy guide to the Visual Stu ... [ read more ]


  As already mentioned by Mike McIntyre the VB Team at Microsoft are webcasting a range of presentations on some of the features coming up in VB9 and Visual Studio 9 (Codename Orcas).        The first one, Orcas Overview, goes out on Wednesday April  18th and is presented by VB Team Program Manager John Stallo.   If, like me, you expect to be sleeping peacefully (or at least coding in your sleep) at 9AM PST, you'll be pleas ... [ read more ]


So I finally got the March CTP installed and ready to take a look at what's new in Orcas, the next level of Visual Studio.   The installation was a bit of a struggle and did nothing to improve my opinion of the intuitiveness of Virtual PC (2004 or 2007 versions) - and when I tell you that I started from a Satisfaction Score of around Minus 20 you'll get the idea.  But that's by the by.    Firing up the Orcas VS (which is the full Team Suite version), and selecting ... [ read more ]


  Beginning SQL Server 2005 for Developers - From Novice to Professional    Author:   Robin Dewson   Published By:   Apress     I have always found SQL Server, with its many Studios, Tools, Add-Ins, etc to be  a vastly complex piece of software.    And while I haven't been called on to create any serious applications with it (having always managed to duck under the wire and take the much eas ... [ read more ]


     I set myself the task of deleting a lot of old projects and solutions from my hard drive this holiday weekend to make room for all the new stuff that's coming down the pipeline.     Just as I was about to hit the OK button to confirm the Delete All, I remembered that in the past fortnight I've had thank-you emails from several readers who had found some of my early answers useful.   Those items had been written two and three years ... [ read more ]


          It may be entirely a matter of my own stupidity - let's face it, it often is  -  but I found myself getting very, very  frustrated when I installed SQL Server 2005 Developer Edition and then couldn't find the AdventureWorks Database.       "Aha!",  I hear you say, "You need to select the right choices when you first install SQL Server 2005, young Mead.".     (OK, so I made ... [ read more ]


   So you want print something out to the printer, but because of the layout you need it to be printed Landscape?   You would think - as I did - that all you need do is add something like this to the Print code: e.PageSettings.Landscape = True   Do that and you won't get an Exception thrown.  Unfortunately you won't get Landscape printing either!     The fix for this is to use instead the following line in the code that you pass t ... [ read more ]


  A recent post in the VBCityForums has just reminded me of a technique that I meant to blog, but don't think I ever got round to doing. This is to show how you can customise a label so that you can have text that uses different fonts on the same label.   Normally of course, you set the font and forecolor in the Properties Window at design time, although you can also set or change them at run time too via the Font and ForeColor properties. But the key thing is that you can only have one fon ... [ read more ]
  I've noticed that a lot of VBCity posters seem to be having problems with the DateTime class in VB.NET.   So that got me thinking that maybe the VBCity Academy should include a course on this topic.  If you would be interested in a free course courtesy of VBCity that covered various ways of handling dates and times then all you need do is follow this link and put your name down.   If there are particular areas/questions that you want to see covered, please ... [ read more ]


   In these blogs I mostly try to point up new (and hopefully improved) features that you can get in Visual Studio 2005 or VB 2005 that weren't available in earlier versions.    In many cases, of course, it was quite possible to do something in say VB.NET 2003 -  it just wasn't always the easiest job in the world to get there.    And keeping track of the forms that are open in a WinForms project is a good example.  I'll run through the pre-2005 version first, but if you've landed on this b ... [ read more ]


   Although I'm now quite familiar with using them, I've always thought that IndexOf and LastIndexOf to be rather arcane methods of finding out if a particular character or string existed inside another one.   You know the kind of thing - you have a text source that you've read into memory, maybe from a text file:           Dim sr As New IO.StreamReader(" C:\StoredText.txt ")         Dim str As String = sr.ReadToEnd         Dim SearchString As String = " the "         If str.I ... [ read more ]


a.k.a. Staying Single   In previous versions of VB.NET when trying to stop users from  having more than one instance of an application running I seem to remember having to create some fairly obscure code using Mutex.     VB 2005 has a feature that saves you any of this effort. Simply go to  My Project in Solution Explorer Double click or Right click on the My Project line Select the Application Tab In the Windows Application Framework Properties panel, click on the "Make Single Ins ... [ read more ]


   Mike McIntyre's recent blog item about breaking large images into chunks in order to print them prompts me to post up an approach to the (kind of) opposite scenario which by coincidence I was working on yesterday.   I had two images on a Windows Form, each in its own PictureBox control and I wanted to merge the two images, placing them side by side and printing them out on the printer.   It turned out to be pretty easy.   This function takes the two images as parameters, merges them ... [ read more ]
  I see that a couple of free Power Packs have just been released into the community which will be of particular interest to VB6 Upgraders who haven't yet managed to totally cut the Classic VB umbilical chord .   Details from the download page are: Microsoft Interop Forms Toolkit 1.0 This toolkit helps you bring the power of .NET to your existing Visual Basic 6 applications, by allowing them to display .NET WinForms from within the same application. Instead of upgrading t ... [ read more ]


   Sometimes you might want to change all occurrences of a specific name in a project.   In earlier versions of VS.NET this would involve you in spending some time manually combing through code with the Find and Replace tool.   And handy though Find and Replace is, if you choose to Replace All it's easily fooled into replacing names and partial names that you didn't actually want changing.    The 2005 Edition makes life much easier in this area, thanks to Symbolic Rename. When you want ... [ read more ]


  Here's another in the "Almost too obvious to mention" category, although not new to VB2005.   One of the new things we learned when the first version of VB.NET came along was that we could use the ToUpper and ToLower methods to convert a string into all upper or all lower case characters.   Don't know about you, but ever since 2002 if I wanted to take user input in a TextBox and then convert it to lower case I've always done something like:  Dim s as String = ... [ read more ]


  Sometimes these things are so obvious that it's almost embarrassing to even mention them.   But one thing I've learned since the beginning of the .NET era is that there is just so much to take in that even the really obvious things sometimes just aren't, well, obvious (at least not to me, anyway).   Here's one that you probably sussed out ages ago but  I only found by chance while doing something else.   You are in Design view and have a Windows Form on display.  You select a c ... [ read more ]
 In earlier versions of Visual Studio .NET  if you created a User Control in a Class Library project and wanted to have a quick preview of the work so far, you might have been tempted to hit that F5 key to run the project.     Unfortunately if you did that you were then stopped short with a message … “A Project with an output type of Class Library cannot be started directly”   The usual fix is to add a second project to the solution, ... [ read more ]


   OK, so we all know that we should include Exception Handling in our code and maybe most of the time we do.  If you don't do this as regularly as you should maybe it's because you've come up against the  'information overload' problem of .NET - i.e.  it's great, but there's just so darn much of it that you can't always see the wood for the trees.          With Exception Handling, one of the problems when you first get into this area is that there are just so many possible Exceptions you cou ... [ read more ]


  OK, I admit it;   I'm IIS-ly challenged.         I know that some people freeze on the spot at the sight of slithery snakes.    Some people are terrified of the dentist's drill.     But the pits for me is when I turn a coding corner and see the dreaded IIS looming in my path.    I get worse collywobbles than a Treasure Island pirate who's just been handed the Black Spot.     When I finally go to that great software house in the sky and St ... [ read more ]


    As Bilbo Baggins desperately tried to guess while on his adventures in The Hobbit,  the answer to  “What’s it got in his pocketses”    -    “String ...… or Nothing    “  (which was really two guesses).        I came across another example of one of those relatively small improvements in VB2005 this week.     It won’t send your productivity zooming but it’s still nice to see these little tweaks that all add up to an overall ... [ read more ]


  Neil Sedaka was wrong apparently  -  Breaking up isn’t hard to do  :-)   Intro   There are a couple of useful little enhancements to the Split method in VB2005.      I can’t begin to count how many times I’ve suggested the use of this very handy method in VB.NET answers over the years.    You know the kind of thing – you have a string containing words or phrases which are separated by commas, for example, and you want to bre ... [ read more ]


   If you've used IsNumeric in the past and thought it was pretty handy, then you may be interested in TryParse, another nifty little method that's been slipped into VB2005 without much of a fanfare.     TryParse takes a string and tries to parse it to a particular type.     It will return True or False to signify whether the attempt to parse has succeeded.     If it does succeed, then the method will pass back the ... [ read more ]


    Explicit content warning!    Wow!    That got your attention, I bet!      Actually I just wanted to warn you explicitly that this blog item contains nothing that is the slightest bit VB.NET related.    So if you were hoping  for some meaningful insight into a nagging technical VB problem, you’ll probably be disappointed.   Then again, if you’ve read my other blog items that are VB ... [ read more ]


   Had some interesting feedback from readers who used other ways of disabling code blocks.  It made me think that I should probably have said something like "Of course, this - as usual with Visual Studio - isn't the only way.  It just happens to be the way I find easiest, so I thought I'd pass it along to you.  "    You can of course use your mouse and navigate to the Edit menu and: Select Edit Advanced Comment Selection  & ... [ read more ]


   Here's a little tip.   Actually, it's so small that it's probably no more than a Tipette, A Tipchen (for German readers) or a Tipling ....  oh wait!  Isn't that what I do every night after work?     Anyway, enough preamble.   If you are in one of those not uncommon situations where you temporarily want your project to ignore a block of code, how do you do this?      Maybe your preferred way is to  ... [ read more ]


a.k.a.   YOU decide when the application closes!   VB.NET 2002 and 2003     In the original versions of VB.NET if the Form used to start the application is closed then the application automatically exits.    You know this, of course.    You probably also know that if you want to include Splash screens. Log in forms or in fact any temporary form at the start of the application’s life, you have to jump throug ... [ read more ]


Maybe it’s just me.    Maybe I’m just having a bad day.   Or maybe the Help isn’t as intuitive in VS2005 as it was in VS 2003.   Or maybe it’s just that there’s so darn much new stuff in VB/VS2005 that I just can’t track it all down in the Help files.        Whatever the reason, I really do feel as though I’m spending far longer trying to pinpoint   the answers to & ... [ read more ]


    I remember that when I first started moving from VB6 to VB.NET,   I really missed the comfort zone of the relatively easy to use control array in Classic VB.    But I soldiered on and got to grips with all that business of creating a new control, setting properties,   adding   it to the Form’s Controls array and creating an event handler.        I think that learning to use AddHandler   was probably ... [ read more ]


 Microsoft UK are running a competition with the aim of  showcasing the vision, creativity and dedication of the IT community in the UK .   This competition is split into two distinct categories:   Category 1:  IT professionals are invited to submit a deployed or aspirational system design, appropriate for any size of organisation, either in the commercial or not for profit sectors. The system design submitted should no ... [ read more ]


   I discovered a small change from Visual Studio 2003 to VS 2005  today that I hadn’t noticed previously.      As you know, when using the Format menu in Visual Studio, you select a number of controls and you can then choose to change various formatting elements such as:   Align Lefts Align Top Make Same Size   and so on.      In the earlier versions of Visual Studio, all of the c ... [ read more ]


(a.k.a.  When Simple Mail Transfer Protocol isn’t quite as simple as it sounds)      I wanted to build in a feature that sent an email from a button click in a Windows Form in VB.NET 2005.    This is something I have seen asked about many times in VB and VB.NET Forums over the years.       It turned out to be less easy than I thought it would be (nothing new there, then!)      The difficulty I fo ... [ read more ]


      I’ve always admired utility apps that do just one thing, but do it particularly well.    Going back into the mists of time, I remember that the first app in this category was XTree, way back in my computing youth.    Remember   XTree?    (Best not admit it, you’ll be giving your age away!).      I also have a spiffy little image optimizer utility which as they say in the advert in the ... [ read more ]


   Playing audio has certainly got a lot easier now that the 2005 version includes the very useful My.Computer.Audio.Play method.         If you know where the audio file is going to be saved then you can use something like:       My .Computer.Audio.Play(Application.StartupPath & "\DingDong.wav" ) Or    My .Computer.Audio.Play( "C:\Start.Wav" )      Of course ... [ read more ]


   I discovered a very interesting little twist on the differences between the Today property and the Now property in the DateTime Class.     I was working on something recently and using the built-in Compare method of the DateTime Type.   Essentially the user selected a date and I had a validation snippet that was supposed to check that they had not picked a future date.   One of the ways they could choose their date was via a DateTimePicker co ... [ read more ]


   It looks like the beginning of the end for one of   my   most popular articles on devCity (at least, most popular, according to the number of hits and the general positive feedback, that is ).     It’s the one that deals with Multiple Forms in VB.NET.   http://www.devcity.net/net/article.aspx?alias=multipleforms     This particular   article helps to solve that first day problem that many of us ... [ read more ]
  Here’s a nifty little tip that you may possibly find useful one day .    I had to work out how to display superscript and subscript characters using the DrawString method.    Now, Drawstring itself is a fairly easy beast to tame once you’ve done it a couple of times, but the extra requirement of   the super and subscript digits needed an extra bit of thought.      Anyhow, here’s how I went about it:   I created two separate fonts, one for the standard siz ... [ read more ]


    I was answering a question in one of the Forums earlier this week and it reminded me of a little VB.NET gotcha I'd stumbled across previously and that I had almost forgotten.  So while it's still at the front of my mind, I thought I'd include it in my blog.   The question asked about how to fetch one column of data from an underlying database and populate a set of 25 labels.   Each label  had to contain one item from the column - Label1 to contai ... [ read more ]


  I've seen countless requests in the VBCity Forums for sources of free learning materials for beginners and upgraders. I heard of one recently aimed at Classic VB developers who are interested in using ASP.NET.    This free offer comes from InnerWorkings  via Microsoft's VBRun website. They have compiled a collection of ASP.NET learning challenges for Visual Basic .NET developers moving from VB 6.0. The offer is available free to VBRun users ... [ read more ]


  Reading an article the other day reminded me of a Gotcha that seems to crop up in the forums every so often.  The question usually goes along the lines of : "I've added the ampersand symbol to the text of a button to give it an Alt plus X hotkey for the button click.    I can see the underscore in the VS IDE, but  when I run the project, the underscore has disappeared."    Folk spend a lot of time trying to find the answer to this "V ... [ read more ]


Very early on in my .NET learning curve I came up against the old "How do I access data and controls on the startup form?" problem.   With a little help from a knowledgeable friend  to help me solve the puzzle, I thought I may as well put my solution in an article for devCity.  Which I did - http://www.devcity.net/Articles/117/1/multipleforms4.aspx  here.   I know that it's been helpful to many .NET Newbies - the feedback comments tell me so.&nbs ... [ read more ]


  I’m developing this theory that says “You have to fail in order to succeed”.      I’ve come to realise that a lot of modern programming requires a comprehensive grasp of such a massive range of skills and knowledge that it’s impossible to get a handle on it all at the first pass.    So many different concepts, so much detail, so many ways to get it wrong that failure the first couple of times through is just about inevitable. ... [ read more ]


© 2005 Serge Baranovsky. All rights reserved.
All feed content is property of original publisher. Designated trademarks and brands are the property of their respective owners.

This site is maintained by SubMain(), a division of vbCity.com, LLC