vb.net .vb How to show Form1 Size in msgbox

vmars316 621 Reputation points
2020-08-31T18:19:28.553+00:00

Hello & Tanks ;
vb.net .vb How to show Form1 Size in msgbox
Error msg: 1>\Form1.vb(35,53): error BC30469: Reference to a non-shared member requires an object reference.

It would be be quite helpful in Form Design .

Below is my code .
Thanks for your Help...

    Private Sub Form1_ResizeEnd(ByVal sender As Object, ByVal e As EventArgs)
        MessageBox.Show("Form1. Width is Now = ." & Control.Size.Width)
    End Sub
Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,863 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 113.7K Reputation points
    2020-08-31T18:49:31.95+00:00

    Try two possibilities:

    MessageBox.Show("Form1 size: " & Me.Size.ToString)
     -- or --
    MessageBox.Show($"Form1 size: {Me.Size}")
    

    To show the width only:

    MessageBox.Show($"Form1 width = {Me.Width}.")
    
    1 person found this answer helpful.
    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. vmars316 621 Reputation points
    2020-08-31T21:51:47.64+00:00

    Thanks ;

    Turns out neither of those work , so I just tried
    MsgBox("Form1 size: " & " Sub Form1_Resize ")
    Which also didn't work ,
    so I conclude that the Resize event is not firing .
    Your thoughts & how to fix ?
    Thanks...

    0 comments No comments

  2. vmars316 621 Reputation points
    2020-08-31T21:52:40.143+00:00

    Oops here's the code:

        Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs)
    
            '    Private Sub Form1_ResizeEnd(ByVal sender As Object, ByVal e As EventArgs)
            EachSetLine.Text = EachSetLine.Text & Me.Size.ToString
            '        MsgBox("Form1 size: " & Me.Size.ToString)
            '        MessageBox.Show($"Form1 width = {Me.Width}.")
            MsgBox("Form1 size: " & " Sub Form1_Resize ")
        End Sub
    

  3. vmars316 621 Reputation points
    2020-09-05T16:47:07.077+00:00

    Thanks Daniel ;
    Yes that works fine .
    Why doesnt this Location work ? :

            Private Sub GetElementsByTagName_Load(sender As Object, e As EventArgs) Handles MyBase.Load
                WebBrowser1.ScriptErrorsSuppressed = True
                Me.Size = New System.Drawing.Size(1000, 650)
                Me.MinimumSize = New Size(1000, 650)
                '        GetElementsByTagName.Location = New Point(40, 20); 
                '        Me.StartPosition = FormStartPosition.CenterScreen
                '        GetElementsByTagName.Left = 40; 
                '        GetElementsByTagName.Top = 20; 
                WebBrowser1.Navigate("http://vmars.us/SafeBrowser/SafeBrowserHome.html")
            End Sub
    

    Thanks

    0 comments No comments

  4. vmars316 621 Reputation points
    2020-09-06T00:15:43.117+00:00

    Thanks ;
    This confused me for hours :
    Me.Size = New System.Drawing.Size(1000, 650)
    Turns out I didnt really need it .

    But I did really need this ;
    Me.StartPosition = FormStartPosition.CenterScreen
    Before I could get this to work :
    Me.Left = 40
    Me.Top = 20

        Private Sub GetElementsByTagName_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            WebBrowser1.ScriptErrorsSuppressed = True
            WebBrowser1.IsWebBrowserContextMenuEnabled = False
            Me.MinimumSize = New Size(1000, 650)
            Me.StartPosition = FormStartPosition.CenterScreen
            Me.Left = 40
            Me.Top = 20
            WebBrowser1.Navigate("http://vmars.us/SafeBrowser/SafeBrowserHome.html")
        End Sub
    

    Thanks

    0 comments No comments