Reputation: 337
I am trying to programmatically pull the default size (height and width) of a Form that I am creating. I am trying to use the Control.DefaultSize
Property of the CONTROL class.
Now this property returns a value of type Size
, which is a structure in the System.Drawing
namespace. Hence to store the value returned by this property I have declared a Size
type variable named store
.
Once that happens I wanted to print out the width and height properties of this structure type variable. That was my idea but its clearly not working as I am getting error in the store = form1.DeafultSize()
statement.
Can anyone tell how to make this work?
The code that I wrote:
Imports System.Windows.Forms
Imports System.Drawing
Module Module1
Sub Main()
Dim form1 As New Form()
Dim store As System.Drawing.Size
store = form1.DeafultSize() 'Error coming in this line
Console.WriteLine("Default Height of Form: {0}", store.Height)
Console.WriteLine("Default Width of Form: {0}", store.Width)
Application.Run(form1)
End Sub
End Module
Upvotes: 1
Views: 1430
Reputation: 32223
The Form.DefaultSize is a property, not a method, it's protected
- so you can access it only from a derived class or through reflection.
It's set by default to new Size(300, 300)
in a Form (as you can see in the .Net Source code).
The Control class doesn't really define a DefaultSize
value, it's virtual (Overridable
), it just returns Size.Empty
, it's an implementation-specific value (classes that implement Control define their own value overriding the Property).
If you want to know what is the Size assigned by default to your Form object, just read it:
Dim form1 As New Form()
Dim store = form1.Size
Upvotes: 1