dotnet thoughts 

a dotnet developer's technical blog

Image viewer in WPF

In my blog you can find few postings about Image viewer application in WPF. This is a project I am currently doing to learn WPF. I have updated the source code, with some new features

  1. Resources strings
  2. Keyboard shortcuts
  3. File Information
  4. Custom commands
  5. Addressbar using dropdownlist

etc.

If you wish you can download the source from here

Adding web user controls in runtime

Today one of my colleague (Aneesh, the one who wrote this post) asked me how can we add Web user controls dynamically in to a web page. I tried to do like Controls.Add(..) and placed a asp:placeholder and tried. But every time it is getting added without any error, but it is not getting displayed. :)

After doing some search I got some code snippet, which helps you to Add Web user controls dynamically on web pages.

Dim oWebUserControl1 as WebUserControl1 = Ctype(Page.LoadControl("~/WebUserControl1.ascx"),WebUserControl1)
Me.PlaceHolder1.Controls.Add(oWebUserControl1)

File Properties Dialog box using VB.Net

While working with my WPF project, I come to a requirement, where I need to display the File Properties dialog box, which available on right click on a File > selecting Properties. I got one solution from Google groups, but I forgot the link. :( I am posting the code.

Imports System
Imports System.Runtime.InteropServices
Namespace Win32
    <StructLayout(LayoutKind.Sequential)gt; _
 Public Class SHELLEXECUTEINFO
        Public cbSize As Integer
        Public fMask As Integer
        Public hwnd As IntPtr
        Public lpVerb As String
        Public lpFile As String
        Public lpParameters As String
        Public lpDirectory As String
        Public nShow As Integer
        Public hInstApp As Integer
        Public lpIDList As Integer
        Public lpClass As String
        Public hkeyClass As Integer
        Public dwHotKey As Integer
        Public hIcon As Integer
        Public hProcess As Integer
    End Class
    Public Class Shell
        Public Const SEE_MASK_INVOKEIDLIST As Integer = 12

        <DllImport("shell32.dll")gt; _
        Public Shared Function ShellExecuteEx(<[In](), Out()> _
      ByVal execInfo As SHELLEXECUTEINFO) As Boolean
        End Function
    End Class
End Namespace

And you can call the function like this

        Dim fileInfo As New Win32.SHELLEXECUTEINFO
        fileInfo.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(fileInfo)
        fileInfo.lpVerb = "properties"
        fileInfo.fMask = Win32.Shell.SEE_MASK_INVOKEIDLIST
        fileInfo.nShow = 1
        fileInfo.lpFile = filename		'File name to display properties.
        Win32.Shell.ShellExecuteEx(fileInfo)

There is one issue I am facing right now with the code, the Dialog is not displayed as Modal window. I have to do R&D on it, and will update later.