Resize form, controls, fonts

At bottom of the form load event put ResizeFormClass.SubResize(Me, percentW, percentH) where percentW is ratio form.width/Int((Screen.PrimaryScreen.WorkingArea.Width), and percentH is ratio form.height/Int((Screen.PrimaryScreen.WorkingArea.Height). If form is maximized, below ResizeFormClass.SubResize(Me, percentW, percentH) put Me.WindowState = FormWindowState.Maximized, at runtime.
At the resolution 1 form resizes and the form width becomes: Int((Screen.PrimaryScreen.WorkingArea(1).Width) * (percentW / 100)), while the form height becomes: Int((Screen.PrimaryScreen.WorkingArea(1).Height) * (percentH / 100)).
When I run the application, at resolution 2, the form width becomes: Int((Screen.PrimaryScreen.WorkingArea(2).Width* (percentW / 100) and the form height becomes: Int((Screen.PrimaryScreen.WorkingArea(2).Height) * (percentH / 100)).
The form resizes not exactly proportionally because Int((Screen.PrimaryScreen.WorkingArea(1).Width) * (percentW / 100))/Int((Screen.PrimaryScreen.WorkingArea(2).Width* (percentW / 100))<>Int((Screen.PrimaryScreen.WorkingArea(1).Height) * (percentH / 100))/Int((Screen.PrimaryScreen.WorkingArea(2).Height) * (percentH / 100)),
but the controls and the fonts resize proportionally.
With this method we resize the form better than other methods because we can set both width and height of the form and because with percentW=100 and percentH=100 the form fills all the working area as in the maximized mode and we can set the WindowState property=Maximized without the risk to "lose" any control.
On the other hand, going from the resolution 1280x1024 to the resolution 1024x768 FormHeight1/FormHeight2= Int((Screen.PrimaryScreen.WorkingArea(1).Height) * (percentH / 100))/ Int((Screen.PrimaryScreen.WorkingArea(2).Height) * (percentH / 100))=1.347 and FormWidth1/FormWidth2= Int((Screen.PrimaryScreen.WorkingArea(1).Width) * (percentW / 100))/Int((Screen.PrimaryScreen.WorkingArea(2).Width* (percentW / 100))=1.25. If we make the ratio 1.347/1.25 we find 1.0776. That is the form stretch out about by 7.76%, that isn't so much!
Going form 1280x1024 resolution to 800x600 resolution we have similarly to make the ratio 1.74/1.6=1.0875, that is the form stretch out about by 8.75%.
If we go form 1024x768 resolution to 800x600 resolution similarly we have to make the ratio 1.29/1.28, that is the form stretch out by 0.78%!
In a module paste code below:

Module Module1

Public Class ResizeFormClass
'Original form width.
Private Shared m_FormWidth As Long
Private Shared m_FormHeight As Long



Public Shared Sub SubResize(ByVal F As Form, ByVal percentW As Double, ByVal percentH As Double)
Dim FormHeight As Long
Dim FormWidth As Long
Dim HeightChange As Double, WidthChange As Double



Call SaveInitialStates(F)




'Calculate the new height and width the form needs to be resized to, based on the current avaible screen area.
FormHeight = Int((Screen.PrimaryScreen.WorkingArea.Height) * (percentH / 100))
FormWidth = Int((Screen.PrimaryScreen.WorkingArea.Width) * (percentW / 100))



'Use the Form that is to be resized.
With F
'Change the demensions and position of the form.

.Height = FormHeight
.Width = FormWidth

HeightChange = .ClientSize.Height / m_FormHeight
WidthChange = .ClientSize.Width / m_FormWidth

End With
'Calculate ratio current avaible screen area/form size

'Notify the class that the form has been resized.
SubChangeWithRatio(F, WidthChange, HeightChange)

End Sub

Private Shared Sub SaveInitialStates(ByVal F As Form)


'Use the form that is being resized.
With F
'Check if the form is a MDI form.

'Set the FormWidth and FormHeight variables to the Form's Scale Width and Height.
m_FormWidth = .ClientSize.Width
m_FormHeight = .ClientSize.Height

End With

End Sub


Public Shared Sub SubChangeWithRatio(ByVal F As Form, ByVal RapportoW As Single, ByVal RapportoH As Single)
'uses a recursive routine
For Each ctl As Control In F.Controls
ResizeControlAndIncludedControls(ctl, RapportoW, RapportoH)
Next

End Sub

Private Shared Sub ResizeControlAndIncludedControls(ByRef ctl As Control, ByVal RapportoW As Single, ByVal RapportoH As Single)



Dim ChildCtl As Control

For Each ChildCtl In ctl.Controls

ResizeControlAndIncludedControls(ChildCtl, RapportoW, RapportoH)

Next
ResizeControl(ctl, RapportoW, RapportoH)
End Sub

Private Shared Sub ResizeControl(ByRef ctl As Control, ByVal RapportoW As Single, ByVal RapportoH As Single)
Dim lb As New ListBox, intlH As Boolean
Try
If TypeOf ctl Is ListBox Then


lb = CType(ctl, ListBox)
intlH = lb.IntegralHeight
lb.IntegralHeight = False

ctl.Left = CInt(ctl.Left * RapportoW)
ctl.Top = CInt(ctl.Top * RapportoH)
ctl.Width = CInt(ctl.Width * RapportoW)
ctl.Height = CInt(ctl.Height * RapportoH)

Else

ctl.Left = CInt(ctl.Left * RapportoW)
ctl.Top = CInt(ctl.Top * RapportoH)
ctl.Width = CInt(ctl.Width * RapportoW)
ctl.Height = CInt(ctl.Height * RapportoH)

End If

lb.IntegralHeight = intlH
If TypeOf ctl Is ListView Then
Try
ResizeColumns(ctl, RapportoW, RapportoH)
Catch ex As Exception
End Try
End If
Try
ResizeControlFont(ctl, RapportoW, RapportoH)

Catch ex As Exception
End Try
Catch ex As Exception
End Try

End Sub

Private Shared Sub ResizeControlFont(ByRef Ct As Control, ByVal RapportoW As Single, ByVal RapportoH As Single)

'Resizes the control font and, in the case of some controls, as the listview
' resizes the columns also

Try

Dim FSize As Double = Ct.Font.Size
Dim FStile As FontStyle = Ct.Font.Style
Dim FNome As String = Ct.Font.Name
Dim NuovoSize As Double = FSize



NuovoSize = FSize * Math.Sqrt(RapportoW * RapportoH)
Dim NFont As New Font(FNome, CSng(NuovoSize), FStile)
Ct.Font = NFont

Catch

End Try

End Sub

Private Shared Sub ResizeColumns(ByRef ct As Control, ByVal RapportoW As Single, ByVal RapportoH As Single)

Dim c As ColumnHeader
For Each c In CType(ct, ListView).Columns
c.Width = CInt(c.Width * RapportoW)
Next

End Sub
End Class
End Module

Found two bugs in Visual Basic express + SP1

The properties rows of datagridview and visiblerows.count of datagrid
mark 1 plus record. Done my signal to Microsoft.

Dbms Firebird and Vb.net

Warning: this article has been modified on 17 February 2007

Dbms the Firebird offers excellent performances also regarding other famous dbms. Moreover it is free, it's wheight is around 14 mega. It has a client-server structure and as far as instructions SQL they follow the international standards.
For a comparison with others dbms see here
The last setup for the classic server and superserver can be dowloaded here.
To work with .net applications Firebird needs the .net providers wich you can download here.
Now is more easy to insert indexes and primary keys in the tables.
As editors of SQL there are free applications. One is SQL Manager 2005 Lite for InterBase/Firebird from here. The other is IBEasy+ 1.5.1 from here
SQL Manager 2005 lite is more complete, but with IBEasy+ 1.5.1 you may import tables from Excel, files XML, and Access, but I council to import from files Excel (the import from Access doesn't work and that from files XML works badly).
The tables can directly be exported in
Excel format from Access (clic with the right of the mouse on the table and choose the option “exports”. In order to see how to import tables of Excel consult the guide of IBEasy+ 1.5.1.

Increasing the speed in developing a Vb. net project with Firebird

When you are developing a project with a Firebird database which contains too many rows, the displaying of the data in a datagridview control may be slow.
This appens when in the connectionstring you have setted servertype=1.
Indipendently of what will be the connectionstring in the final application you at present set servertype=0. In this way the speed of displaying of the data will be appreciably increased.
Anyhow if you directly clic on the executable you have a normal speed of the displaying.

Firebird in applications shared in LAN net

In the client applications in which more computer are connected in network

  1. In the application project use a connection string like this “server=computer name where the server resides; username=user name ; password=user password; database= explicit path of the database in the server machine\mydb.gdb"

  2. You have to install in the client machine the .net framework.

  3. You have also to copy on the in the client machine only the escecutable of the application and to install the FirebirdClient-2.0.1.

  4. You don't need install neither the Server of Firebird neither the client library in the client machine.

  5. If the server machine is firewalled let open the port n. 3050 in the firewall.

  6. There's no other you have to do.

Firebird in applications not connected in network

In order to distribute applications not connected in network but like installabile program on a whichever computer, use the following procedure:

  1. Download ADO NET Provider FirebirdClient-2.0.1 which installs the net classes of Firebird on every computer which must hold a VB.net application with Firebird.

  2. Download the package Embedded Firebird

  3. Unzip this file.

  4. In the folder of the application “\bin\debug” copy from the previously unzipped package the libraries:
    - fbembed.dll
    - icuu30.dll
    - icuin30.dll
    - icudt30.dll
    - the folder “intl” and the folder "udf"

  5. In the application project use a connection string like this: “servertype=1; username=user name; password=user password; database=” & My.Application.Info.DirectoryPath &” \mydb.gdb "

  6. In the installation package insert the executable, the database, the libraries and the folder intl, which will be placed in the same target folder of the application.

As installer I council CIS downloadable from http://66.249.93.104/translate_c?hl=en&ie=UTF-8&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;oe=UTF-8&langpair=it%7Cen&u=http://www.silvercybertech.com/italian/index.html&prev=/language_tools


Solved the issue "unable to load DLL fbembed .dll"

With the installation of new FbClient 2.0.1 is no more enough to insert in the application directory only the fbembed.dll, but you have first to download the package Firebird 2.0.0.12748-0 emb or Firebird 2.0.1.12855-0 emb. After, from unzipped package, you have to copy in the application directory the following dll:
- fbembed.dll
- icuu30.dll
- icuin30.dll
- icudt30.dll
Also you have to copy the folders "intl" and "udf".
Obviously you must do this using the proper installer software.

Older Posts