Sonntag, 3. Februar 2008

Zooming in the old COM Webbrowser Control

You may use the traditional COM Webbrowser Control for cetain reasons. How is the zoom changed in this Control?

It is NOT like in the managed Version of the HTMLDocument.

Dim Zoomlevel As Integer = 100



Private Sub WebBrowser_PreviewKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles WebBrowser.PreviewKeyDown
If e.Control = True AndAlso e.KeyCode = Keys.Subtract Then
Zoomlevel *= 0.95
Me.Browserinfoobj.HTMLDocument.body.style.setAttribute("zoom", Zoomlevel & "%")
ElseIf e.Control = True AndAlso e.KeyCode = Keys.Add Then
Zoomlevel /= 0.95
Me.Browserinfoobj.HTMLDocument.body.style.setAttribute("zoom", Zoomlevel & "%")
ElseIf e.Control = True AndAlso e.KeyCode = Keys.NumPad0 Then
Zoomlevel = 100
Me.Browserinfoobj.HTMLDocument.body.style.setAttribute("zoom", Zoomlevel & "%")
End If
End Sub


 



 



 

How to zoom inside an System.Windows.Forms.Webbrowser Control?

If I talk about zooming webseite I think of the way IE 7 zoomes them. So we are talking about a real zoom NOT about chaning the fontzises. This optical webseite zoom is unique to IE 7. The question is: How does it work?

The answer is quite simple. You have to manipulate the DOM of the Website. So everything is made by the use of a System.Windows.Forms.HTMLDocument.

In this example it is required to have 3 keydowns registered. One for "+", another for "-" and the 3rd for "0". All 3 should onlny fired if the control key is also pressed. Thing about that: Writing inside a webform and then the zoom of the site changes all the time. That would not be the effect you want to have. ;)

First we need a Variable where we save the zoom size.

Dim Zoomlevel As Integer = 100


   Private Sub Webbrowser_PreviewKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles Webbrowser.PreviewKeyDown
If e.Control = True AndAlso e.KeyCode = Keys.Subtract Then
Zoomlevel *= 0.95
Me.Webbrowser.Document.Body.Style = "zoom: " + Zoomlevel.ToString + "%"
ElseIf e.Control = True AndAlso e.KeyCode = Keys.Add Then
Zoomlevel /= 0.95
Me.Webbrowser.Document.Body.Style = "zoom: " + Zoomlevel.ToString + "%"
ElseIf e.Control = True AndAlso e.KeyCode = Keys.NumPad0 Then
Zoomlevel = 100
Me.Webbrowser.Document.Body.Style = "zoom: " + Zoomlevel.ToString + "%"
End If
End Sub


So what is this Code doing?



First the keys are detected. That is nothing special to an KeyDown Event. The Sizing is a bit special in this Vesion since it does not just add a Value. We use a multiplication *.95 for reducing the dize and a division for making things bigger. The Combination of Control an NumPad0 just setzt the size to the normal value.



So why is there a muliplication or a division? It is just my idea. You can do it with a fixed value. But thing of this: By zooming out with every zoom the difference between the last size and the new size will be smaller. By zooming in the difference will be bigger with each zoom. As I think here the user gets faster the size he wants. And you do not use high steps for changing since the factor is just .95. 

Montag, 28. Januar 2008

.net Sources are available

Since a few days Microsoft allows access on the .net Framework sources. Visual Studio 2008 was announced with the feature of stepping into the .net source. This is not possible by default so you have to configure your version first. Here you find how to do this. The bad news is: No Express Edition supports stepping into the .net sources - poor for all hobbyists out there.

Donnerstag, 3. Januar 2008

Visual C# 2008 Express Edition

Since last review was on VB 2008 Express we will now look a bit closer on Visual C# 2008 Express Edition.

The part called "Evolution of GUI" of our last review fits exactly also to the C# Express Edition - and also to the professional Editions (but there are more changes).

Also the project types are similar to VB Express.

The new WPF Designer Features fit to VB and C#.

So looking what's new in the Application Properties Tab.

Application Properties

Tab Application

There is a little surprise. The VB Version does not support changing the target Framework. If you expect that also for the C# Version you are wrong. Visual C# Express can do it!

But there is another surprise: No View 'UAC Settings button'. Since the UAC Settings are stored inside the application.manifest file I think you can easily get this functionality by using a text editor.

image

Except this there are no major changes in the application projects which are not in the VB Version. As the VB Version C# support now modifiers for resources and settings.

 

 

So you might ask: What is with .net's, c#'s and VB's new cool functionalities? You have not mentioned them in one word?

The answer is: This was a review of the IDE. .net Features are features of .net - nor of visual Studio. And also the language features are not depending on Visual Studio.

All three cases are worth for getting special reviews.

Dienstag, 1. Januar 2008

Opening Visual Studio 2008 Express Projects in Visual Studio 2008

1) Single projects (vbproj)

Here are no problems - open it in Visual Basic 2008 Express and then in Visual Studio 2005 (e. g. Standard Edition ) . Everything works.

2) Complete Visual Studio Solutions

If you open a Visual Studio 2005 Solution in Visual Basic 2008 Express Edition a conversion wizard is shown.

Im most cases only the solution file will be changed.

Here is an example of a converted file:

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Basic Express 2008
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Souvergin - RSS Reader", "Souvergin - RSS Reader\Souvergin - RSS Reader.vbproj", "{9EF163F6-8BFB-40A8-90ED-99DE4EA6A17C}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Release|Any CPU = Release|Any CPU
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {9EF163F6-8BFB-40A8-90ED-99DE4EA6A17C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {9EF163F6-8BFB-40A8-90ED-99DE4EA6A17C}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {9EF163F6-8BFB-40A8-90ED-99DE4EA6A17C}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {9EF163F6-8BFB-40A8-90ED-99DE4EA6A17C}.Release|Any CPU.Build.0 = Release|Any CPU
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
EndGlobal

This file can not be opened by Visual Studio 2005. But if you have also one of the full versions of Visual Studio like standard or professional you might want to work with them instead of an express edition.

So what is to change?

Only the first two lines:

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005

Save your edited file and then you can work with Visual Studio 2005. Maybe in some cases it would be useful to save your backported Version as a separate file e. g. if you often switch between both IDE's.