none
If the y component for a control location is the same when moved, why is it showing at a different height in the scree when running RRS feed

  • Question

  • I have a control.   combobox10 that when it gets focus I am expanding its size on screen to show more information.

    However the actual on screen performance has the combobox10 getting wider as desired but the location is shifting to a lower place on the screen.  Note the 692 Y setting in location does not vary.   The move is very annoying to say the least.  Any recommendations would be appreciated.  I would think this would not be impacted by screen preferences set on the PC, but is that a possible cause?

    Thank you for your assistance on this.

    The code is the following.

    Private Sub ComboBox10_GotFocus(sender As Object, e As EventArgs) Handles ComboBox10.GotFocus

            ComboBox10.BringToFront()

            

            ComboBox10.Size = New System.Drawing.Size(1706, 33)

            ComboBox10.Location = New System.Drawing.Point(153, 692)

        End Sub

     

        Private Sub ComboBox10_LostFocus(sender As Object, e As EventArgs) Handles ComboBox10.LostFocus

            ComboBox10.SendToBack()

            ComboBox10.Location = New System.Drawing.Point(1257, 692)

            ComboBox10.Size = New System.Drawing.Size(602, 33)

        End Sub

    Wednesday, November 27, 2019 2:02 PM

All replies

  • Hi

    Trty (a variation of) this. Using the .Width property instead of .Size (the .Size is dependant on the .Font in use).

    	Private Sub ComboBox10_GotFocus(sender As Object, e As EventArgs) Handles ComboBox10.GotFocus
    		ComboBox10.Location = New Point(20, 20)
    		ComboBox10.Width = 500
    	End Sub
    	Private Sub ComboBox10_LostFocus(sender As Object, e As EventArgs) Handles ComboBox10.LostFocus
    		ComboBox10.Location = New Point(100, 20)
    		ComboBox10.Width = 50
    	End Sub
    


    Regards Les, Livingston, Scotland

    Wednesday, November 27, 2019 2:21 PM
  • Thanks for your speedy reply.

    I tried setting just the width property.   I am using VS 2017 professional editor and VB.

    The action is still weird.  When the combobox gets focus it is still moving down about 1.5 inches on the screen.   The good news is that it now stays down on the same height location when I leave and enter.

    But it is still in the wrong place.    When you indicate this may be dependent on the font in use, which font are you referring to?   Is this the setting in the preferences in Windows or is it the font on the form or perhaps the font of the control?   The font on the form is not changing nor is the font on the control but they are not equal to each other.    Can I control the font setting being used from VB.net Code?

    What a pain in the neck.

    Once again I really appreciate your assistance

    Wednesday, November 27, 2019 2:45 PM
  • Hi

    The font I referred to is the ComboBox font which effects the Height of the control.

    I can't imagine what could be effecting your results. I can't get anything like that here.

    Would you show the code of your second version please.


    Regards Les, Livingston, Scotland


    • Edited by leshay Wednesday, November 27, 2019 2:53 PM
    Wednesday, November 27, 2019 2:52 PM
  • AW,

    What is the text and other magnification in the control panel display settings?

    ie 150 percent?

    How do you know the box is the size and location you want?

    Wednesday, November 27, 2019 2:55 PM
  • Private Sub ComboBox10_GotFocus(sender As Object, e As EventArgs) Handles ComboBox10.GotFocus

            ComboBox10.BringToFront()

            

            ' ComboBox10.Size = New System.Drawing.Size(1706, 33)

            ComboBox10.Location = New System.Drawing.Point(153, 692)

            ComboBox10.Width = 1206

        End Sub

     

        Private Sub ComboBox10_LostFocus(sender As Object, e As EventArgs) Handles ComboBox10.LostFocus

            ComboBox10.SendToBack()

            ComboBox10.Location = New System.Drawing.Point(1257, 692)

            ' ComboBox10.Size = New System.Drawing.Size(602, 33)

            ComboBox10.Width = 602

        End Sub

    Wednesday, November 27, 2019 3:43 PM
  • I can place it where I want and then get both the location and size readings from the properties of the combobox.   SO first I place it with a location for when it is small and then for the location when it is big.   Very visual approach and I can see it in relation to other controls on the screen.

    Maybe I need to set the display setting for my running of the software.  How do I do that so it only applies to my running code and not other code they may be running?

    Thanks for your help on this.

    Wednesday, November 27, 2019 3:56 PM
  • Hi

    Well, I can make a guess.  Although I can't get the issue you mention, I have to wonder if the starting point of the location for the ComboBox differs from the 'resting state' (ie not focused) location . If (say) the starting point was (20,20) and when focused goes to (100,100) the, lost focus to (100,20), what would be seen is:

    1. CB at (10,10) not focused - first run of form.

    2. CB at (100,100) focused

    3 CB at  (100,20) lost focus

    and repeating step 2 & 3

    This may explain the effect you mention where it settled down to correct behavior after initial position.


    Regards Les, Livingston, Scotland

    Wednesday, November 27, 2019 4:00 PM
  • I can place it where I want and then get both the location and size readings from the properties of the combobox.   SO first I place it with a location for when it is small and then for the location when it is big.   Very visual approach and I can see it in relation to other controls on the screen.

    Maybe I need to set the display setting for my running of the software.  How do I do that so it only applies to my running code and not other code they may be running?

    Thanks for your help on this.

    Hi

    OK, the point Tommy raised may well be relevant here. I can only refer to my setup, but, if I try to depend on positions as per the Designer and then try to depend on them at run time, I will always be disappointed. I believe it does have something to do with the User screen settings, scale etc., but in any case, given the need to do what you seem to be doing, I would set the initial position in the Load event of the Form, run and rerun until happy, then set the new position/width as needed in the appropriate events and run and rerun until happy.

    There is some sort of disconnect with the Forms/Controls regarding User screen settings.


    Regards Les, Livingston, Scotland


    • Edited by leshay Wednesday, November 27, 2019 4:59 PM
    Wednesday, November 27, 2019 4:12 PM
  • I can place it where I want and then get both the location and size readings from the properties of the combobox.   SO first I place it with a location for when it is small and then for the location when it is big.   Very visual approach and I can see it in relation to other controls on the screen.

    Maybe I need to set the display setting for my running of the software.  How do I do that so it only applies to my running code and not other code they may be running?

    Thanks for your help on this.

    I dont understand what you are describing exactly.

    "I can place it where I want "

    What is it? Combobox? Form? You car?

    "then get both the location and size readings from the properties of the combobox."

    How do you get it? Is the application running?

    "Very visual approach and I can see it in relation to other controls on the screen."

    Can see what? Form? The refigerator?

    :)

    Just tell us what your text scaling setting is now. Is it 150 percent? If so set it to 100 and what happens. If it is on 100 then that is not the problem unless you are seeing a difference between two different systems..

    You need to make a reproducable example.

    It is all very complicated I dont claim to understand it anymore.

    What verion of windows are you?

    PS Show a picture of what you mean.

    Wednesday, November 27, 2019 4:32 PM
  • I did look at that issue.  The concern would be if it somehow the CB was landing in a panel or other container.

    But I was aware of issues with that and insured the combobox was at all time on the main form.  

    I even took the extra step of making sure it was moved to the front when it has focus so that it would be above other controls and containers.   You can see that code in the sample I included.

    The properties of the combobox indicate that the settings are exactly the same in the first run and the lost focus situation.   Clearly the lost focus and got focus events are triggering something different than the load event.

    Confusing.   

    I did test the screen by changing in Windows 10 from the recommended scaling screen size enhancement from 125 back to 100.   It had no impact on the results.

    Maybe I will need to do some math and just make sure it lands where I want it by changing the settings to compensate for the issue.   I really do not like that and I am not sure what results might impact users in the field with different resolution screens.    Maybe the difference in resolution between my laptop screen (1920X1080) versus my second screen where I do my design work (3840x2160) is causing the issue?   The running program is on the smaller screen.

    Wednesday, November 27, 2019 5:17 PM
  • AW,

    All we can do is guess without an example and description of exactly what the problem is.

    Maybe it has nothing to do with the scaling issues which can be set in app.manifest and depends which version of windows exactly how they work.

    But I will guess your large monitor is set differently? Is that what you mean different between two systems?

    Here is some reading.

    https://docs.microsoft.com/en-us/dotnet/framework/winforms/automatic-scaling-in-windows-forms

    https://docs.microsoft.com/en-us/dotnet/framework/winforms/high-dpi-support-in-windows-forms

    Wednesday, November 27, 2019 5:51 PM
  • PS A work around or better maybe is pop up a new control something with the info instead of resize the existing control? But that is tempory. Even a tool tip?

    There are form settings for autoscale font or dpi etc. Settings in app.manifest...

    Even the graphics update for win10, version .net 4.7, I forget exactly...

    I would make a new simple one form example project and run it on diff things and see if I can find a pattern. etc.

    PS you can use one of the new layout tables maybe with autosizes and etc it might do it automatically...


    Wednesday, November 27, 2019 6:21 PM
  • Hi

    One other odd thing that may be worth a try.

    When you are in the Designer view, and have completed any editing of the Form and controls, before leaving back to code window, or, running application, resize the Designer Form to something like (500,300)  or less - that doesn't change anything on the Form, but it was one of the tweak some of the strange control positioning.


    Regards Les, Livingston, Scotland

    Wednesday, November 27, 2019 6:47 PM
  • Did you consider a code like this:

    ComboBox10.Location = New System.Drawing.Point(153, ComboBox10.Location.Y) ?

    Wednesday, November 27, 2019 7:25 PM
  • I will try using the old location Y to update the new one.  

    I think there is something different that happens once the form has completed being loaded.   I am thinking to test different position settings for the control and see what gives the desired result.

    Maybe instead of using the combobox10 location, maybe I use the location of a dummy control that is normally set to not visible, but set it to visible for testing.  If it then it is positioned correctly great.  If not perhaps that will give me a mathematical way to determine the correct location for the screen scalar that a user may have.   And I have a kluge method of fixing the problem.

    Perhaps even simpler would be to have two identical controls as Tommytwotrain suggested.  Then when the large one is being used, make it visible and the small one not.   Then reverse that when the large one loses focus.   As soon as the small one gets focus, then it becomes not visible and the big one takes over.  the small one just becomes a place holder that shows which choice was made. Then I will not need to move the control at all.   Not an elegant solution.

     

    Wednesday, November 27, 2019 8:20 PM