Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET Interface and Graphics (http://www.xtremevbtalk.com/-net-interface-and-graphics/)
-   -   Picturebox size in design phase & while running MISMATCH (http://www.xtremevbtalk.com/-net-interface-and-graphics/327587-picturebox-size-design-phase-running-mismatch.html)

Oswald 04-24-2015 10:46 AM

Picturebox size in design phase & while running MISMATCH
 
2 Attachment(s)
how is this possible? :huh: I'm new to .net, but I know it doesnt scale at all like vb6.

see the attachment for picturebox size and what the output was (on form title).

its set to 200 in the IDE, and form_load returns 150, without doing anything else, this was a blank project to make sure everything is default

Code:

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Text = CStr(PictureBox1.Width)
    End Sub
End Class


passel 04-24-2015 12:46 PM

That kind of thing could happen in VB6 as well, but more rarely. You sometimes had to do a Me.Show to make the form visible before trying to read some things because some properties aren't actually valid until the control is drawn.
That said, I tried it and I got 200, in all the places that I tried, so I don't know why you're showing 150 in your case.
Code:

Public Class Form1

  Private Sub Form1_Activated(sender As Object, e As System.EventArgs) Handles Me.Activated
    Debug.Print("Picturebox1 size in Activated Event: {0}", PictureBox1.Size.ToString)
  End Sub

  Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Me.Text = CStr(PictureBox1.Width)
    Debug.Print("Picturebox1 size in Load Event: {0}", PictureBox1.Size.ToString)
  End Sub

  Private Sub Form1_Shown(sender As Object, e As System.EventArgs) Handles Me.Shown
    Debug.Print("Picturebox1 size in Shown Event: {0}", PictureBox1.Size.ToString)
  End Sub
End Class


Oswald 04-24-2015 01:45 PM

thanks for the effort. well, finally I invstigated and its the same problem I had with VB6 and XP once. I've changed the size of "gui elements" to be bigger in windows, and it affects control sizing implicitly somewhere somehow.

Gruff 04-24-2015 04:00 PM

My take on it is that you cannot trust sizes in the form_load event as graphics have not been generated at that point.

In vb6 I used to use a timer control set for a couple of seconds after form_load.
In the timer event I would do my graphics measurement.


In VB.NET you should use the Form_Shown event as Passel shows or the SizeChanged event if you are creating a control.


All times are GMT -6. The time now is 03:33 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.