dotnet thoughts 

a dotnet developer's technical blog

Image viewer in WPF – Part II

As part of my WPF study, I have written a post (Image viewer in WPF – Part I). As the second part I am explaing the XAML (UI) code for the application.

In WPF Microsoft, introduced a new container control, ScrollViewer. I am using Scrollviewer as my host for displaying Images.

<ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<StackPanel>
<Image Stretch="Fill" Name="MainImage" />
</StackPanel>
</ScrollViewer>

This control will display scrollbars automatically, if the Image size is greater than the scroll viewer size. And in the codebehind I am displaying the Images using a Collection

Private Sub DisplayImages()
If m_FilesUpdated.Count <= m_FileIndex Or m_FileIndex < 0 Then
MessageBox.Show("No more images to display", Me.Title, MessageBoxButton.OK, MessageBoxImage.Warning)
If m_FilesUpdated.Count <= m_FileIndex Then
m_FileIndex -= 1
Else
m_FileIndex += 1
End If
Return
End If
If m_FilesUpdated IsNot Nothing Then
MainImage.Source = m_FilesUpdated(m_FileIndex)
End If
End Sub

And the Next and Previous menu items, to navigate to Next and Previous images, I am updating the index and calling the DisplayImages() method.


Private Sub NextImageMenu_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
m_FileIndex += 1
DisplayImages()
End Sub

You can download the full source code from Image viewer source. Change the extension from .zipx to .zip

Encryption-Decryption using stored procedure in SQL Server

For more security we may require to use Encryption-Decryption of data. Here is some code, which can be used for Encryption-Decryption in SQL Server.

CREATE PROCEDURE usp_Encryption_Decryption
@DataText VARCHAR(100)
AS
declare @encryptedstuff VARCHAR(100)
declare @decryptedstuff VARCHAR(100)

SET @encryptedstuff = EncryptByPassPhrase(‘LED_PWD-2007′, @DataText)
SELECT @encryptedstuff
SET @decryptedstuff = DecryptByPassPhrase(‘LED_PWD-2007′, @encryptedstuff)
SELECT @decryptedstuff

Select folder using OpenFileDialog control

Few days back one of my friend got a nice requirement from the client. The client want to select a Folder using the OpenFileDialog control. And after some googleing he got a solution, to select Folder using OpenFileDialog control.

Code to Select folder using OpenFileDialog control

Using _OpenFileDialog As New OpenFileDialog
With _OpenFileDialog
.CheckFileExists = False
.CheckPathExists = True
.Multiselect = False
.FileName = "(Get Folder)"
.Filter = "Folders only|*.FOLDER"
If .ShowDialog() = Windows.Forms.DialogResult.OK Then
MessageBox.Show(.FileName)
End If
End With
End Using

Note : In WPF we can’t use OpenFileDialog with using keyword. And to use OpenFileDialog in WPF you need to import a namespace(Microsoft.Win32)

Image viewer in WPF – Part I (Selecting multiple files with FileOpen Dialog)

Last few days I am working in WPF project, it is nice and good. So I started searching for sample applications to learn WPF. Here is the one, an Image viewer. According to MSDN the image control in WPF supports *.bmp;*.gif;*.ico;*.jpg;*.png;*.wdp;*.tiff file formats. And I need to check how can we open multiple files using the File Open Dialog.

here is the code to open multiple files with File Open Dialog in WPF

Dim OpenFileDlg As New OpenFileDialog()
With OpenFileDlg
.CheckFileExists = True
.CheckPathExists = True
.Filter = "Supported Images|*.bmp;*.gif;*.ico;*.jpg;*.png;*.wdp;*.tiff"
.Multiselect = True 'Allow selection of multiple files
.ReadOnlyChecked = True
.ShowReadOnly = False
If .ShowDialog(Me) = True Then
For Each file As String In .FileNames
m_FilesUpdated.Add(New BitmapImage(New Uri(file))) 'Adding each file to the collection
Next
End If
End With

And the screen shot of the Image viewer running on my machine
WPF Image viewer

How to open attachments blocked by outlook

While working with Microsoft Outlook, some times you will get an error like “Outlook blocked access to the following potentially unsafe attachments”. After googleing I found a solution from Microsoft support site, but I didn’t found any direct solution from the UI. You can get more information from Microsoft Support on “Outlook blocked access to the following potentially unsafe attachments” error.

The solution that worked for me like Adding a new string key in HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Security, with Name as “Level1Remove” and you need to give the file extensions you want to download (or disable blocking). Like in my case it is “.mdb” and also you can give multiple extensions by separating them with a semi colon.

Older Posts »