none
Form Not Sizing Correctly - Surface Tablet RRS feed

  • Question

  • I am developing a LOB application that we want to put on a Surface Tablet device.  I am using VS 2013 and am running into all kinds of problems.  The main problem is that I cannot get the main form to size correctly.

    I have tried sizing the form in VS and it just isn't working correctly.  In the design editor, I have the form size set to 445, 763.  When I run the program, the form takes up the whole screen (and it should not as the screen resolution is set to 768 x 1280).  I thought that I could fix it by sizing the form in the load event but that isn't working either.

    In my load event, I get the size of the screen and then set the size of the form so that it fits within the screen.  When I run this code I get:

    Working Area: Height: 1232 Width: 768

    Final Size: Height: 1291 Width: 780

    Final Location: X -9 Y: -9

    I have tried everything including using Me.Height and Me.Width to set the form dimensions no avail.

    This is a showstopper because when I run it, the program fills the entire screen including the taskbar.  In my program, I display a dialog box with a text box.  When this dialog appears, I can't access the on screen keyboard because the taskbar is covered with the form.

    I have spent several hours on this and have gotten nowhere.

    Any hints or clues would be appreciated.

        Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            Try
                Dim workingRectangle As System.Drawing.Rectangle = Screen.PrimaryScreen.WorkingArea
                Debug.Writeline("Working Area: Height: " + CStr(workingRectangle.Height) + " Width: " + CStr(workingRectangle.Width))
    
                Me.Location = New System.Drawing.Point(5, 5)
    Me.Size = New Size(workingRectangle.Height - 100, workingRectangle.Width - 10) Debug.Writeline("Final Size: Height: " + CStr(Me.Height) + " Width: " + CStr(Me.Width)) Debug.Writeline("Final Location: X: " + CStr(Me.Location.X) + " Y: " + CStr(Me.Location.Y)) Catch ex As Exception MsgBox("ERROR: " + ex.Message) End Try End Sub


    John

    Tuesday, March 10, 2015 7:04 PM

All replies

  • It seems to work if you don't use the .size but use .height and .width. I am not sure why

            Dim workingRectangle As System.Drawing.Rectangle = Screen.PrimaryScreen.WorkingArea
            Me.Location = New System.Drawing.Point(0, 0)
            'Me.Size = New Size(workingRectangle.Height - 300, workingRectangle.Width - 10)
            Me.Height = workingRectangle.Height - 300
            Me.Width = workingRectangle.Width - 10
    

    Wednesday, March 11, 2015 2:29 AM
  • It seems to work if you don't use the .size but use .height and .width. I am not sure why

            Dim workingRectangle As System.Drawing.Rectangle = Screen.PrimaryScreen.WorkingArea
            Me.Location = New System.Drawing.Point(0, 0)
            'Me.Size = New Size(workingRectangle.Height - 300, workingRectangle.Width - 10)
            Me.Height = workingRectangle.Height - 300
            Me.Width = workingRectangle.Width - 10

    Oh I see you have the height and width reversed:

    Me.Size = New Size(workingRectangle.Width - 10, workingRectangle.Height - 300)

    Wednesday, March 11, 2015 2:34 AM
  • Are you doing this on a Windows Surface Tablet?  I agree that it works fine on a regular Windows machine but it does not work at all on a tablet.  I have tried it on two different tablets and it has the same behavior on both.

    John

    Wednesday, March 11, 2015 4:29 PM
  • Are you doing this on a Windows Surface Tablet?  I agree that it works fine on a regular Windows machine but it does not work at all on a tablet.  I have tried it on two different tablets and it has the same behavior on both.

    John

    No. Its my desktop.

    When I run your original code above it does not size to the screen properly. So I figured that was the problem?

    Reversing the width and height makes your code fit to the screen on my desktop.

    I have never used surface but I would think it works the same but I could be wrong.

    PS This line is an error, so you have to fix it first as it does not work on any monitor this way.

    Me.Size = New Size(workingRectangle.Height - 100, workingRectangle.Width - 10)

    Wednesday, March 11, 2015 6:56 PM
  • Are you doing this on a Windows Surface Tablet?  I agree that it works fine on a regular Windows machine but it does not work at all on a tablet.  I have tried it on two different tablets and it has the same behavior on both.

    John

    Perhaps you should read this old article. I don't know which Surface Tablet you have therefore I don't know if this article will help regarding the code in it but you should be able to search for information for newer Surface regarding the same issue presented in this link - Detecting Screen Orientation and Screen Rotation in Tablet PC Applications

    Also found these.

    ApplicationServices.InitialOrientation Property - Probably this is what you need. You can use Telerik to convert C# to VB.Net. I'm guessing your app may be orienting correctly. However you can know by orientation in degrees what is considered width and height on the surface as those may not change if the surface orientation changes from portrait to landscape or whatever goes on. I'll provide a post for detecting the height of the taskbar that works on a PC but I don't know if it will work on a Surface Tablet.

    Orienting the Application Window

    UserOrientation Enumeration

    UPDATE: Instead of providing code I suppose you could review various threads in these Google search results for "Get height of taskbar vb.net" to see if something would work on a Surface in order to decrease the height of your app so it does not cover the TaskBar.


    La vida loca

    • Edited by Mr. Monkeyboy Thursday, March 12, 2015 8:09 AM UPDATE
    Thursday, March 12, 2015 7:49 AM