Getting H & W Values of your Form

Use this board to post your code snippets - tips and tricks
10 posts Page 1 of 1
Contributors
User avatar
hungryhounduk
VIP - Site Partner
VIP - Site Partner
Posts: 2870
Joined: Mon Jul 27, 2009 11:58 am

Hi All
As i was searcing around my External Harddrive i came across this, A very simple way of getting your Height and Width Size of your Form.

On your Form

2 textbox's
2 Labels
1 Timer ( interval =1 & Enabled)

Timer Tick Code
Code: Select all
TextBox1.Text = me.Height
TextBox2.Text = Me.Width
And that is it :)

Form set up

Image

And as you drag out the Form/Window with your Mouse or Maximise your Window it will
adjust your Width and Height Coordinates.

Image

Anyways, I just thought I would post this up for those who are Interested

Attachment Below ( working ex )


Chris
You do not have the required permissions to view the files attached to this post.
Image
User avatar
Harlem9191
Top Poster
Top Poster
Posts: 87
Joined: Mon Jan 18, 2010 8:45 pm

You don't need a timer for that. You can put it in the Resizing event which triggers whenever the form has changed size.
User avatar
zachman61
VIP - Donator
VIP - Donator
Posts: 1891
Joined: Wed Dec 16, 2009 9:56 pm

this is for newer members Harlem not for the better coders
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that :)
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Wouldn't newer members find it easier to use the resize event?
User avatar
hungryhounduk
VIP - Site Partner
VIP - Site Partner
Posts: 2870
Joined: Mon Jul 27, 2009 11:58 am

"Well i just can across it and Posted it up" Just in case anyone was Interested :)
Why dont you recreate one your way and Post it up and we can see the differences and the Code that lays behind it?

Chris
Image
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Code: Select all
    Private Sub Form1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        TextBox1.Text = Me.Height
        TextBox2.Text = Me.Width
    End Sub
User avatar
Cheatmasterbw
Coding God
Coding God
Posts: 1506
Joined: Fri Jan 01, 2010 2:30 pm

This will update the size when the text boxes are changed:
Code: Select all
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    try
        me.width = textbox1.text
    catch ex as exception
        MsgBox("Error: " & ex.message)
    end try
End Sub

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
    try
        me.Height = TextBox2.text
    catch ex as exception
        MsgBox("Error: " & ex.message)
    end try
End Sub
http://www.megaapps.tk/
User avatar
Harlem9191
Top Poster
Top Poster
Posts: 87
Joined: Mon Jan 18, 2010 8:45 pm

That isn't too clever considering as soon as you type in the first number (e.g. a 2) the width or height would be '2' and the textbox wouldn't be visible.
User avatar
Cheatmasterbw
Coding God
Coding God
Posts: 1506
Joined: Fri Jan 01, 2010 2:30 pm

good point.
http://www.megaapps.tk/
User avatar
mikethedj4
VIP - Site Partner
VIP - Site Partner
Posts: 2592
Joined: Thu Mar 25, 2010 4:36 am

I posted something very close to this here. Although I didn't have a timer, I had 2 labels, 2 textboxs, and a button.
10 posts Page 1 of 1
Return to “Quick Snips”