Phone, Tablet or other?

I was hoping to use the following code to determine whether I was on an iPhone or on an iPad, to determine whether to use an iPhoneLayout or an iPadLayout after I have logged in.

If System.Device.UserInterfaceType = System.Device.UserInterfaceType.Phone Then
MessageBox "It's a phone"
ElseIf System.Device.UserInterfaceType = System.Device.UserInterfaceType.Tablet Then
MessageBox "It's a tablet"
End if

But the compile error says that System.Device.UserInterfaceTypes has no member named “Phone” despite auto-completing and being in the Help. I have tried with DeviceData instead of Device and get a different error.

What is the best way to determine if you’re on a phone or tablet?

Did you forgot the “s” after UserInterfaceTypes?

If System.Device.UserInterfaceType = System.Device.UserInterfaceTypes.Phone Then
MessageBox "It's a phone"
ElseIf System.Device.UserInterfaceType = System.Device.UserInterfaceTypes.Tablet Then
MessageBox "It's a tablet"
End if
1 Like

When I add the ‘s’ it not only doesn’t auto-complete, but gives the error System.DeviceData has no member named “UserInterfaceTypes”, so I don’t think that’s the solution.

This does work here:

If System.Device.UserInterfaceType = System.DeviceData.UserInterfaceTypes.Phone Then
  MessageBox "It's a phone"
Elseif System.Device.UserInterfaceType = System.DeviceData.UserInterfaceTypes.Tablet Then
  MessageBox "It's a tablet"
End If

Showing “It’s a phone” in ios iphone simulator

1 Like

Thank you @DerkJ it is working here too now!

1 Like