Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Test and label fields misalign on windows 2000

Test and label fields misalign on windows 2000

Scheduled Pinned Locked Moved C#
help
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I have a TabControl with 7 different tabs. One of the Tabs has numerous text boxes and labels and a few buttons. When I run the app on this particular laptop that is running windows 2000 professional the text boxes, labels and buttons are shifted down and to the right. Part of the text boxes and labels are obscured and cannot be moved. This problem does not occur on XP nor does it happen on a Windows 2000 professional Desktop. I had to laugh when I saw it because I don't have a clue as to why it is happening. If my explaination is not clear let me know and I'll try harder to make it clear. Any insight would be awesome! Parrish

    D H 2 Replies Last reply
    0
    • L Lost User

      I have a TabControl with 7 different tabs. One of the Tabs has numerous text boxes and labels and a few buttons. When I run the app on this particular laptop that is running windows 2000 professional the text boxes, labels and buttons are shifted down and to the right. Part of the text boxes and labels are obscured and cannot be moved. This problem does not occur on XP nor does it happen on a Windows 2000 professional Desktop. I had to laugh when I saw it because I don't have a clue as to why it is happening. If my explaination is not clear let me know and I'll try harder to make it clear. Any insight would be awesome! Parrish

      D Offline
      D Offline
      Dimitris Iliopoulos
      wrote on last edited by
      #2

      Format and reinstall windows 2000 on the laptop :) !!! Most users play with the settings of the windows and they end up with a windows operating system missfunctioning From Greece: Dimitris Iliopoulos dimilio@yahoo.com

      H 1 Reply Last reply
      0
      • D Dimitris Iliopoulos

        Format and reinstall windows 2000 on the laptop :) !!! Most users play with the settings of the windows and they end up with a windows operating system missfunctioning From Greece: Dimitris Iliopoulos dimilio@yahoo.com

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        :wtf: What kind of advice is that? If you can't give a reasonable answer, please don't answer at all.

        Microsoft MVP, Visual C# My Articles

        1 Reply Last reply
        0
        • L Lost User

          I have a TabControl with 7 different tabs. One of the Tabs has numerous text boxes and labels and a few buttons. When I run the app on this particular laptop that is running windows 2000 professional the text boxes, labels and buttons are shifted down and to the right. Part of the text boxes and labels are obscured and cannot be moved. This problem does not occur on XP nor does it happen on a Windows 2000 professional Desktop. I had to laugh when I saw it because I don't have a clue as to why it is happening. If my explaination is not clear let me know and I'll try harder to make it clear. Any insight would be awesome! Parrish

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          Ignore that last reply. That's not a solution but in the most extreme circumstances. On laptops - and even some desktops - it's common that the DPI (dots per inch) is set higher. Desktops are typically at 96 DPI while newer laptops (with much better displays capable of higher resolutions) are at 120 DPI. Unfortunately, the .NET Framework uses pixels, a logical unit. VB6, for example, uses twips which are a physical unit (like an inch or a point). See http://visualbasic.about.com/cs/visualbasicfaq/a/dykpixeltwip.htm[^] for more information. How do you convert this? By P/Invoking GetDeviceCaps and initializing a couple of static properties with the scale factor. You should also handle the Microsoft.Win32.SystemEvents.DisplaySettingChanged event so that you can update these when the display settings change. See How to Write High-DPI Applications[^] in the MSDN Library. Using those concepts, you could create a class like so:

          public sealed class Display
          {
          static Display()
          {
          SystemEvents.DisplaySettingsChanged += new EventHandler(Update);
          }
          private Display() {} // Prevent instantiation
           
          [DllImport("gdi32.dll")]
          private static extern IntPtr GetDeviceCaps(IntPtr hdc, IntPtr index);
           
          [DllImport("user32.dll")]
          private static extern IntPtr GetDC(IntPtr hwnd);
           
          [DllImport("user32.dll")]
          private static extern IntPtr ReleaseDC(IntPtr hwnd, IntPtr hdc);
           
          private static void Update()
          {
          Setup(true);
          }
          private static void Setup(bool force)
          {
          if (initialized && !force) return;
          logsPerPixelX = logsPerPixelY = 0; // Initial values
          IntPtr hdc = GetHDC(IntPtr.Zero);
          try
          {
          if (!hdc.Equals(IntPtr.Zero))
          {
          IntPtr value;
          value = GetDeviceCaps(hdc, 88); // LOGPIXELSX
          logsPerPixelX = 1440 / value.ToInt32();
          value = GetDeviceCaps(hdc, 90); // LOGPIXELSY
          logsPerPixelY = 1440 / value.ToInt32();
          ReleaseDC(IntPtr.Zero, hdc);
          }
          }
          catch {}
          if (logsPerPixelX == 0) logsPerPixelX = 15; // Default for 96 DPI
          if (logsPerPixelY == 0) logs

          D P 2 Replies Last reply
          0
          • H Heath Stewart

            Ignore that last reply. That's not a solution but in the most extreme circumstances. On laptops - and even some desktops - it's common that the DPI (dots per inch) is set higher. Desktops are typically at 96 DPI while newer laptops (with much better displays capable of higher resolutions) are at 120 DPI. Unfortunately, the .NET Framework uses pixels, a logical unit. VB6, for example, uses twips which are a physical unit (like an inch or a point). See http://visualbasic.about.com/cs/visualbasicfaq/a/dykpixeltwip.htm[^] for more information. How do you convert this? By P/Invoking GetDeviceCaps and initializing a couple of static properties with the scale factor. You should also handle the Microsoft.Win32.SystemEvents.DisplaySettingChanged event so that you can update these when the display settings change. See How to Write High-DPI Applications[^] in the MSDN Library. Using those concepts, you could create a class like so:

            public sealed class Display
            {
            static Display()
            {
            SystemEvents.DisplaySettingsChanged += new EventHandler(Update);
            }
            private Display() {} // Prevent instantiation
             
            [DllImport("gdi32.dll")]
            private static extern IntPtr GetDeviceCaps(IntPtr hdc, IntPtr index);
             
            [DllImport("user32.dll")]
            private static extern IntPtr GetDC(IntPtr hwnd);
             
            [DllImport("user32.dll")]
            private static extern IntPtr ReleaseDC(IntPtr hwnd, IntPtr hdc);
             
            private static void Update()
            {
            Setup(true);
            }
            private static void Setup(bool force)
            {
            if (initialized && !force) return;
            logsPerPixelX = logsPerPixelY = 0; // Initial values
            IntPtr hdc = GetHDC(IntPtr.Zero);
            try
            {
            if (!hdc.Equals(IntPtr.Zero))
            {
            IntPtr value;
            value = GetDeviceCaps(hdc, 88); // LOGPIXELSX
            logsPerPixelX = 1440 / value.ToInt32();
            value = GetDeviceCaps(hdc, 90); // LOGPIXELSY
            logsPerPixelY = 1440 / value.ToInt32();
            ReleaseDC(IntPtr.Zero, hdc);
            }
            }
            catch {}
            if (logsPerPixelX == 0) logsPerPixelX = 15; // Default for 96 DPI
            if (logsPerPixelY == 0) logs

            D Offline
            D Offline
            Dimitris Iliopoulos
            wrote on last edited by
            #5

            I am really sorry if my answer was not reasonable. I have seen your code and it is really excellent! But lot of times and i mean (lot of times) i have installed a product of mine which worked perfectly in all of the previous installations on a computer and simply on that computer didn't play, after lot of time on debuging my code for the problem i have seen, i found that the user has deleted some keys from the registry himself :(( and this was the problem!!!!!! My answer was not a programming one and i am sorry, but it is true that sometimes you need to go that way!!! From Greece: Dimitris Iliopoulos dimilio@yahoo.com

            H 1 Reply Last reply
            0
            • D Dimitris Iliopoulos

              I am really sorry if my answer was not reasonable. I have seen your code and it is really excellent! But lot of times and i mean (lot of times) i have installed a product of mine which worked perfectly in all of the previous installations on a computer and simply on that computer didn't play, after lot of time on debuging my code for the problem i have seen, i found that the user has deleted some keys from the registry himself :(( and this was the problem!!!!!! My answer was not a programming one and i am sorry, but it is true that sometimes you need to go that way!!! From Greece: Dimitris Iliopoulos dimilio@yahoo.com

              H Offline
              H Offline
              Heath Stewart
              wrote on last edited by
              #6

              Then why don't you reinstall your product? Your installation should be responsible for setting default registry keys as well as removing them during uninstall. Formatting and reinstalling the OS is a last-ditch effort. It's your application that was screwed up more than likely - thorugh no fault of your own, just the users - so it's your application that should be repaired first. There are many other things one could do before resorting to reinstalling the OS.

              Microsoft MVP, Visual C# My Articles

              1 Reply Last reply
              0
              • H Heath Stewart

                Ignore that last reply. That's not a solution but in the most extreme circumstances. On laptops - and even some desktops - it's common that the DPI (dots per inch) is set higher. Desktops are typically at 96 DPI while newer laptops (with much better displays capable of higher resolutions) are at 120 DPI. Unfortunately, the .NET Framework uses pixels, a logical unit. VB6, for example, uses twips which are a physical unit (like an inch or a point). See http://visualbasic.about.com/cs/visualbasicfaq/a/dykpixeltwip.htm[^] for more information. How do you convert this? By P/Invoking GetDeviceCaps and initializing a couple of static properties with the scale factor. You should also handle the Microsoft.Win32.SystemEvents.DisplaySettingChanged event so that you can update these when the display settings change. See How to Write High-DPI Applications[^] in the MSDN Library. Using those concepts, you could create a class like so:

                public sealed class Display
                {
                static Display()
                {
                SystemEvents.DisplaySettingsChanged += new EventHandler(Update);
                }
                private Display() {} // Prevent instantiation
                 
                [DllImport("gdi32.dll")]
                private static extern IntPtr GetDeviceCaps(IntPtr hdc, IntPtr index);
                 
                [DllImport("user32.dll")]
                private static extern IntPtr GetDC(IntPtr hwnd);
                 
                [DllImport("user32.dll")]
                private static extern IntPtr ReleaseDC(IntPtr hwnd, IntPtr hdc);
                 
                private static void Update()
                {
                Setup(true);
                }
                private static void Setup(bool force)
                {
                if (initialized && !force) return;
                logsPerPixelX = logsPerPixelY = 0; // Initial values
                IntPtr hdc = GetHDC(IntPtr.Zero);
                try
                {
                if (!hdc.Equals(IntPtr.Zero))
                {
                IntPtr value;
                value = GetDeviceCaps(hdc, 88); // LOGPIXELSX
                logsPerPixelX = 1440 / value.ToInt32();
                value = GetDeviceCaps(hdc, 90); // LOGPIXELSY
                logsPerPixelY = 1440 / value.ToInt32();
                ReleaseDC(IntPtr.Zero, hdc);
                }
                }
                catch {}
                if (logsPerPixelX == 0) logsPerPixelX = 15; // Default for 96 DPI
                if (logsPerPixelY == 0) logs

                P Offline
                P Offline
                Parrish
                wrote on last edited by
                #7

                Heath, I appreciate your insight and expertise but your talking to someone who only has a very basic understanding of this type of development environment. Please forgive my ignorance. To be honest I'm not completely sure I understand how to use it. Whenever the screen size is changed do I run all my Text boxes and labels through the scaling functions to reposition them? I did incorporated this class into my code. I instantiate a Display object when I bring up my application and the Update service is called when I change the screen dimensions. I did have to make a few changes to get it to work (as I'm sure you expected). I had to add the following at the appropriate places...are they ok? static int logsPerPixelX,logsPerPixelY; IntPtr eightyEight = new IntPtr(88); IntPtr ninety = new IntPtr(90); value = GetDeviceCaps(hdc, eightyEight); // LOGPIXELSX logsPerPixelX = 1440 / value.ToInt32(); value = GetDeviceCaps(hdc, ninety); // LOGPIXELSY logsPerPixelY = 1440 / value.ToInt32(); ReleaseDC(IntPtr.Zero, hdc); Because I'm not real sure how to use it, I don't understand why the logsPerPixelX and logsPerPixelY are setup but never used and why twipsPerPixelX and twipsPerPixelY are never setup? I also don't understand why it is only one tab page out of 7 that has this problem? I have numerous other Forms that display properly. If you could just grit your teeth and drop kick me into the right areas I would be most appreciative. If it jams, force it!! Parrish Pope

                H 1 Reply Last reply
                0
                • P Parrish

                  Heath, I appreciate your insight and expertise but your talking to someone who only has a very basic understanding of this type of development environment. Please forgive my ignorance. To be honest I'm not completely sure I understand how to use it. Whenever the screen size is changed do I run all my Text boxes and labels through the scaling functions to reposition them? I did incorporated this class into my code. I instantiate a Display object when I bring up my application and the Update service is called when I change the screen dimensions. I did have to make a few changes to get it to work (as I'm sure you expected). I had to add the following at the appropriate places...are they ok? static int logsPerPixelX,logsPerPixelY; IntPtr eightyEight = new IntPtr(88); IntPtr ninety = new IntPtr(90); value = GetDeviceCaps(hdc, eightyEight); // LOGPIXELSX logsPerPixelX = 1440 / value.ToInt32(); value = GetDeviceCaps(hdc, ninety); // LOGPIXELSY logsPerPixelY = 1440 / value.ToInt32(); ReleaseDC(IntPtr.Zero, hdc); Because I'm not real sure how to use it, I don't understand why the logsPerPixelX and logsPerPixelY are setup but never used and why twipsPerPixelX and twipsPerPixelY are never setup? I also don't understand why it is only one tab page out of 7 that has this problem? I have numerous other Forms that display properly. If you could just grit your teeth and drop kick me into the right areas I would be most appreciative. If it jams, force it!! Parrish Pope

                  H Offline
                  H Offline
                  Heath Stewart
                  wrote on last edited by
                  #8

                  You don't instantiate the Display class as I presented it - it defines static methods and properties: there is no need to instantiate it (which is why I made it sealed and the default constructor private). Yes, when your display changes you would need to run the sizes and locations of the controls through these methods. If you don't understand them, read the other links I gave you. There is more information about programming for different resolutions at http://msdn.microsoft.com[^].

                  Microsoft MVP, Visual C# My Articles

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups