Dpi-Aware experiments in V.S. 2005 Environment
-
Hi all, I written the following code to make "DPI-Aware" the ImageSize property of an ImageList Control in my application (V.B. .Net C.F.2) in V.S. 2005 environment: Dim RK As Microsoft.Win32.RegistryKey = _ Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Drivers\Display\GPE") Dim LPX As String = CType(RK.GetValue("LogicalPixelsX"), String) Dim LPY As String = CType(RK.GetValue("LogicalPixelsY"), String) If LPX = 96 And LPY = 96 Then Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16) Else Me.ImageList1.ImageSize = New System.Drawing.Size(32, 32) End If Well, I placed it in the Form1_Load event, and it works. But with doubt if that place was the "rigth place", I tryed to place it in the "Form1.Designer.vb" code (because I think it is the "more appropriate" place). I placed the first 3 line in the begin of code: <global.microsoft.visualbasic.compilerservices.designergenerated()> _ Partial Public Class Form1 Inherits System.Windows.Forms.Form Dim RK As Microsoft.Win32.RegistryKey = _ Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Drivers\Display\GPE") Dim LPX As String = CType(RK.GetValue("LogicalPixelsX"), String) Dim LPY As String = CType(RK.GetValue("LogicalPixelsY"), String) 'Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) If disposing AndAlso components IsNot Nothing Then components.Dispose() End If MyBase.Dispose(disposing) and the "If-Else" conditions immediately above the ImageList.Add property code: If LPX = 96 And LPY = 96 Then Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16) Else Me.ImageList1.ImageSize = New System.Drawing.Size(32, 32) End If Me.ImageList1.Images.Clear() Me.ImageList1.Images.Add(CType(resources.GetObject("resource"), System.Drawing.Image)) Me.ImageList1.Images.Add(CType(resources.GetObject("resource1"), System.Drawing.Image)) Me.ImageList1.Images.Add(CType(resources.GetObject("resource2"), System.Drawing.Image)) Also if it's recomanded to not write code-lines directly in .Designer.vb code, the code works correctly in both emulator and device, BUT sometime (I not understood why and in witch circumstances), only the If-Else conditions lines above are deleted and replaced with the single line: Me.ImageList1.ImageSize = New System.Drawing.Size
-
Hi all, I written the following code to make "DPI-Aware" the ImageSize property of an ImageList Control in my application (V.B. .Net C.F.2) in V.S. 2005 environment: Dim RK As Microsoft.Win32.RegistryKey = _ Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Drivers\Display\GPE") Dim LPX As String = CType(RK.GetValue("LogicalPixelsX"), String) Dim LPY As String = CType(RK.GetValue("LogicalPixelsY"), String) If LPX = 96 And LPY = 96 Then Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16) Else Me.ImageList1.ImageSize = New System.Drawing.Size(32, 32) End If Well, I placed it in the Form1_Load event, and it works. But with doubt if that place was the "rigth place", I tryed to place it in the "Form1.Designer.vb" code (because I think it is the "more appropriate" place). I placed the first 3 line in the begin of code: <global.microsoft.visualbasic.compilerservices.designergenerated()> _ Partial Public Class Form1 Inherits System.Windows.Forms.Form Dim RK As Microsoft.Win32.RegistryKey = _ Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Drivers\Display\GPE") Dim LPX As String = CType(RK.GetValue("LogicalPixelsX"), String) Dim LPY As String = CType(RK.GetValue("LogicalPixelsY"), String) 'Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) If disposing AndAlso components IsNot Nothing Then components.Dispose() End If MyBase.Dispose(disposing) and the "If-Else" conditions immediately above the ImageList.Add property code: If LPX = 96 And LPY = 96 Then Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16) Else Me.ImageList1.ImageSize = New System.Drawing.Size(32, 32) End If Me.ImageList1.Images.Clear() Me.ImageList1.Images.Add(CType(resources.GetObject("resource"), System.Drawing.Image)) Me.ImageList1.Images.Add(CType(resources.GetObject("resource1"), System.Drawing.Image)) Me.ImageList1.Images.Add(CType(resources.GetObject("resource2"), System.Drawing.Image)) Also if it's recomanded to not write code-lines directly in .Designer.vb code, the code works correctly in both emulator and device, BUT sometime (I not understood why and in witch circumstances), only the If-Else conditions lines above are deleted and replaced with the single line: Me.ImageList1.ImageSize = New System.Drawing.Size
You had it right the first time with placing the code in
Form_Load
. The designer section of the code is "owned" by Visual Studio and as you've seen VS does not gaurantee that changes you make to it will be preserved. If you plan to have others use and modify your code then the designer area isn't idea because no one else would know to look there for your code. Other than theForm_Load
method the other place to consider would be in the constructor of the form right after theInitializeComponent
method is called.Joel Ivory Johnson
Meet my dev team: RDA Architecture Evangelist Team Blog
My site: J2i.net
Twitter: J2iNet
-
You had it right the first time with placing the code in
Form_Load
. The designer section of the code is "owned" by Visual Studio and as you've seen VS does not gaurantee that changes you make to it will be preserved. If you plan to have others use and modify your code then the designer area isn't idea because no one else would know to look there for your code. Other than theForm_Load
method the other place to consider would be in the constructor of the form right after theInitializeComponent
method is called.Joel Ivory Johnson
Meet my dev team: RDA Architecture Evangelist Team Blog
My site: J2i.net
Twitter: J2iNet
Thank you very much Joel!