Wednesday, April 21, 2010

JSON.NET

Json - Release: Json.NET 3.5 Release 7

Json.NET library makes working with JSON formatted data in .NET simple. Key features include a flexible JSON serializer to for quickly converting .NET classes to JSON and back again, and LINQ to JSON for reading and writing JSON.

Features
-Flexible JSON serializer to convert .NET objects to JSON and back again
-LINQ to JSON for reading and writing JSON
-Writes indented, easy to read JSON
-Convert JSON to and from XML
-Supports Silverlight and the Compact Framework

The JSON serializer is a good choice when the JSON you are reading or writing maps closely to a .NET class. The serializer automatically reads and writes JSON for the class.

For situations where you are only interested in getting values from JSON, don't have a class to serialize or deserialize to, or the JSON is radically different from your class and you need to manually read and write from your objects then LINQ to JSON is what you should use. LINQ to JSON allows you to easily read, create and modify JSON in .NET.

Thursday, April 1, 2010

Easiest way to set ListView ItemHeight in an Owner-Drawn ListView

When creating an owner-drawn ListBox, you will receive measure-item messages that allow you to specify the height of items.  In a ListView control, that functionality is not there.  So how is the ItemHeight determined in a ListView in Details mode?  It uses the ImageList height then the Font height, so to override the item height create a dummy ImageList and set it to the desired height and assign it to the listview depending on the view.  Using the Font to set the height does not work very well because it also affects the height of the Header control, an unwanted side-effect.

Wednesday, March 17, 2010

HUDZEE


If you have extra 3.5" internal hard drives, perhaps for backups or archiving purposes, what's the best way to store them?  This is the answer – a VHS-like static-free enclosure that can be placed on a bookshelf.  I found a similar item on Amazon, but it looks flimsy and apparently has one side longer than the other so you can't stand it straight up on a bookshelf.  The Hudzee looks strong, snug, and will store nicely on a bookshelf.  They're about $65 for 10 of them, not very cheap, but if you have hard drives accumulating, it's a good investment.
http://hudzee.com/

Friday, March 12, 2010

Jazzercise!

Started a new blog, for myself really, to chronicle my exercise - specifically, following one of the year-long programs found in the book "The New Rules of Lifting", which I just finished reading.

http://christoffer-workout.blogspot.com/

Tuesday, November 24, 2009

Programmatically setting Internet Explorer print settings for Header, Footer and Margins

The following ampersand values can be used in custom headers and footers.

  • && = ampersand
  • &b = right-justify
  • &b&b = Text following the first "&b" in center alignment; text following the second "&b" in right-justified alignment
  • &d = date (user short format)
  • &D = date (user long format)
  • &t = time (user preference)
  • &T = time (military format)
  • &p = page
  • &P = number of pages
  • &u = URL (or file path)
  • &w = (window) title tag

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup

  • header
  • footer
  • margin_left
  • margin_right
  • margin_top
  • margin_bottom
  • shrink_to_fit ("yes" or "no")
  • Print_Background ("yes" or "no")
  • font ("font-family: KabaleMedium; font-size: 12pt; color: rgb(0,0,0); font-weight: bold;")
  • (unverified) printer
  • (unverified) orientation ("1" =Portrait, "2" = Landscape)
  • (unverified) duplex ("1" = Off, "2" = On)

 

   1:  Imports Microsoft.Win32
   2:   
   3:  Public Class Form1
   4:   
   5:      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   6:          AxWebBrowser1.Navigate("http://www.bing.com")
   7:      End Sub
   8:   
   9:      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  10:          Dim IERegKey As RegistryKey
  11:          Dim header, footer As String
  12:   
  13:          IERegKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\PageSetup", True)
  14:          footer = IERegKey.GetValue("footer", 0)
  15:          header = IERegKey.GetValue("header", 0)
  16:   
  17:          IERegKey.SetValue("footer", "")
  18:          IERegKey.SetValue("header", "")
  19:   
  20:          AxWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT)
  21:   
  22:          ' Reset the values after printing is completed
  23:          IERegKey.SetValue("footer", footer)
  24:          IERegKey.SetValue("header", header)
  25:      End Sub
  26:   
  27:  End Class

 

From http://support.microsoft.com/kb/283797/en-us
PRB: Programmatically Issuing Print Command May Not Print to Default Printer

When you select a printer in Internet Explorer (on the File menu, click Page Setup, click Printer, and choose a printer that is not the system default), your printer selection is stored in the following registry key:

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup\printer

After you make this selection, Internet Explorer continues to use the printer value that is stored in the registry.

 

Print Templates - http://msdn.microsoft.com/en-us/library/aa753279(VS.85).aspx

Wednesday, October 21, 2009

Calculus in 20 minutes (YouTube Video)

Part 1

Part 2

Function IsAnimatedGIF(ByVal szFilename As String)

 

My implementation:

   1:      Public Function IsAnimatedGif(ByVal szFilename As String) As Boolean
   2:   
   3:          Dim fi As New System.IO.FileInfo(szFilename)
   4:   
   5:          Dim nFrameCount As Integer = 0
   6:   
   7:          If fi.Extension.ToLowerInvariant() = ".gif" Then
   8:   
   9:              Try
  10:                  Using _img As Image = New Bitmap(szFilename)
  11:                      Dim fd As System.Drawing.Imaging.FrameDimension = New System.Drawing.Imaging.FrameDimension(_img.FrameDimensionsList(0))
  12:                      nFrameCount = _img.GetFrameCount(fd)
  13:                  End Using
  14:              Catch ex As Exception
  15:                  'Failed to load image, bad file?
  16:              End Try
  17:   
  18:          End If
  19:   
  20:          Return (nFrameCount > 1)
  21:   
  22:      End Function

See

CodeProject: Add GIF-animation to your MFC and ATL projects with the help of CPictureEx and CPictureExWnd. Free source code and programming help

and

Coding4Fun : That's Totally Disco