May 18, 2009 09:53 by
bryan
Been playing around with this hack for some time, it's fun, I can't remember where I first got the application from, but I've had some harmless fun with it in the office.
This small hack allows you to write information to most HP printers LCD screen.
HPHack.zip (6.49 kb)
adc6fc99-a3cb-4086-ad7e-051772c5cc43|1|1.0
May 15, 2009 13:43 by
bryan
I was in need to copying one concreate object to another concreate object, but I needed the flexability that when a new property is added the method would not need to be changed, also I needed the ability for the method to take in any types.
So the first take was to generate a method that uses reflections to go over the obecjts properts and set the returning object properties. That was quite simple, then to make the method more flexable I used generics to help with my method, to allow for any types to be used.
One thing to note is that you require the try catch, in case the GetValue or SetValue fails, such as if the object is null.
This is what I ended up with.
Here is the VB.NET method

Here is the C#

6ba0c448-2014-4b1f-9532-1ff4118650a0|1|1.0
May 14, 2009 13:17 by
bryan
If you are like me when you are developing you create a Debug version of your application and in turn .NET provides you with .PDB files for debugging, that is as far as I know, want to know more about it then take a look at John Robbins' Blog on PDB files: what every developer must know
d92f3a9e-794a-486f-b046-bbbb1ba4e888|1|1.0
May 12, 2009 09:58 by
bryan
I have been on the look out for the ability to display and search a customers database, but having the ability to display millions of records if that what the end users wants. But the trouble is that it can take a long time to return a million records from a data source.
I've talked about paging before in my article LINQ-to-SQL-and-Paging, which works fine for internet based paging, but what about WPF and WinForm Grids, well I came across Vitrual Mode for the Microsoft Data Grid, which can provide an answer. What this allow you to do is, load the data you can see on the screen very quickly and as you scroll through the data is fetched when required.
By setting the VirtualMode = true for a data grid, it allows you to add a handler for deail with CellValueNeeded
Here is the main body of the code

Each time the Data grid needs some values it will call the following:

And of course the NameListCache class

I have attached the source, you will also find a PopulateData project to populate the database with data.
DataGridViewVirtualModePaging.zip (19.43 kb)
PopulateData.zip (11.43 kb)
Here are a few of the database scripts that yu will need for the sample
Names.sql (581.00 bytes)
GetNames.sql (786.00 bytes)
1bb060d4-8d31-4882-9160-ccfe58a19649|2|3.0
May 3, 2009 17:41 by
bryan
Okay, I've learn't something new today, so I'd thought I would share it with you, it's the yeald keyword, the reason why I think I have not used or know about it before is that it is used for an IEnumerable collection, which has come more in to play with LINQ, here is a short example of how it can be used:

This generates the following output:

It just makes sense to do it this way, much cleaner and much more efficient.
For more details check of MSDN on yeald.
It's worth noting that Yield is not support with VB.NET
5d207fe2-9a21-4c9e-a8f6-552cc05d2cd3|1|5.0
February 6, 2009 08:30 by
bryan
Okay you are developing a WinForm application and you are looking at performance, one area is Caching of information, but wait a minute I've been using caching in my web applications for sometime, but how do you do it from a WinForm application as you don't have a host to store your cache.
Would you know it you can use the web cache too, just you have to take a few extra steps to retain your cache, either in memory or in temporary files.
You can use the HttpRequest to store the System.Web.Cache objects in your application, and this works well.
I also came across any Blog, providing another method to Caching, however I have a little concern over this method of caching in files as you are likely to get file locking.
Using System.Web.Caching From The Console Or Windows Forms
I've written my own simple VB.NET application to show it working and just holding the Cache in memory for the life of the application.
WinFormCache.zip (17.73 kb)
Of course you could run a Windows Service which holds all the Cache information, this way it will be available to all your WinForm applications should you require it.
8c3849f3-9342-4d00-a7af-8f51e8b23a2e|2|3.0
February 4, 2009 09:17 by
bryan
Found a nice post from Chris Blankenship's blog about generating a Random Password, the code is just one line of code and is quite simple
string password = Membership.GeneratePassword(12, 1);
Console.Writeline("Random Password: " + password);
08257092-e4cf-49ca-96b7-5ae44788dafb|0|.0
February 4, 2009 08:59 by
bryan
I've come across two issues with the Entity Framework, one that effects any language and one just for VB.NET
It's quite simple, the Entity Framework generates edmx files, however that Inherits Global.System.Data.Objects.DataClasses.EntityObject, which means when you create your Partial class you can not Inherit from your own base class.
The second issue is related to VB.NET, as if you are intending to use Dependence Injection or IoC you need to have an Interface defined and to implement an Interface in VB.NET you must add Implements after each Property and Method, which you can not do as the framework generates it's own code.
I've attached both C# and VB.NET examples, none of which compile
Entity Framework Issues.zip (42.58 kb)
d63eb5bd-d694-4dc7-ae78-c86fb1e12f1d|0|.0
December 22, 2008 10:17 by
bryan
The latest fad is to create Carousels to display images, and allow for easy navigation. I have not been able to find any .NET controls to enable you to create a Carousel on a web page.
So I set myself the task of generating a web page control to allow for easy, managed code, configuration of a Carousel Control in .NET
First I went on the hunt for a simple javaScript Carousel that I could use, I found a lovely Carousel by Doug Greenall, the information on his blog goes in to great detail of how the Carousel works, but this was not intention to go in to detail about the inner working of a Carousel.
So I downloaded Doug Greenall's Carousel and then went to adapt the javaScript code to create a single DLL Control that could be reused.
The end product is a small DLL that can be dragged and dropped in to your ASP.NET application or Website
Carousel.dll (21.50 kb)
The project solution was generated using Visual Studio 2008 Pro,with a Target Framework of ".NET Framework 2.0"
Carousel.zip (191.73 kb)
How to use the Carousel
Okay, so now I've built the Carousel Control, you now want to to know how to use it?
-
First create a new WebSite
-
Add the Carousel.dll or a project reference to your website
-
On the web page register the control (or add it to your web.config)

- Next in the code behind you need to add to the CarouselDetail collection, which will add the images, links to the Carousel
And that is it, the more you add to the CarouselDetail collection the more items will appear on the Carousel.
daa40290-e5c2-4a1e-bc20-ad877d92ca4d|3|3.3
December 22, 2008 10:01 by
bryan
I've always been able to create a standalone DLL control that can be reused in other web applications. I've never really found out how to embed other resources, or more to the point JavaScript files.
Until now
Here's how to embed the file:
- Create a js file such as carousel.js
- In Visual Studio, select the file in Solution Explorer and change the Build Action property to "Embedded Resource"
- Build the project and the carousel.js file is now part of the assembly (you don't need to distibute the js file now it's part of the assembly)
Now to get the resource out using code:
So if we have a resource named Control.carousel.js we can use the following to include it in our page:
System.IO.Stream script = Assembly.GetExecutingAssembly().GetManifestResourceStream("Control.carousel.js");
System.IO.StreamReader sr = new System.IO.StreamReader(script);
Page.ClientScript.RegisterClientScriptBlock(GetType(), "carousel", sr.ReadToEnd().ToString(), true);
sr.Close();
The above code injects the embedded file in to the page, how easy could it be?
d97f4ee7-7425-4fd3-b620-689d631e77c7|2|3.0