Hi
I have this in a method which is called when my form is created

public CreateDevice()
{
// Set the initial size of our form
this.Top = 0;
this.Left = 0;
this.Size = new System.Drawing.Size(500,800);
//this.ClientSize = new System.Drawing.Size(400,300);
// And it's caption
this.Text = "Rhubarb: CreateDevice";
// Load our icon from the resources of the .exe
this.Icon = new Icon(this.GetType(), "directx.ico");
}

the method is being called OK, because the forms text is being set to
what ever I want it to be. But attempts to set the Top, Left or Size
members are having no effect at all, the same with attempts to set the
ClientSize member.
I can resize the form by dragging, when it is running.
I am completely new to C# so it may be something really dumb.

Any ideas

Kevin R.

Re: Visual C# Unable to alter size or position of form by Kevin

Kevin
Fri Dec 31 09:04:29 CST 2004

On Fri, 31 Dec 2004 14:13:46 +0000, Kevin R <me@privacy.net> wrote:

>Hi
>I have this in a method which is called when my form is created
>
>public CreateDevice()
>{
> // Set the initial size of our form
> this.Top = 0;
> this.Left = 0;
> this.Size = new System.Drawing.Size(500,800);
> //this.ClientSize = new System.Drawing.Size(400,300);
> // And it's caption
> this.Text = "Rhubarb: CreateDevice";
> // Load our icon from the resources of the .exe
> this.Icon = new Icon(this.GetType(), "directx.ico");
>}
>
>the method is being called OK, because the forms text is being set to
>what ever I want it to be. But attempts to set the Top, Left or Size
>members are having no effect at all, the same with attempts to set the
>ClientSize member.
>I can resize the form by dragging, when it is running.
>I am completely new to C# so it may be something really dumb.
>
>Any ideas
>
>Kevin R.


The form is actually called CreateDevice. Hence the method above is
the constructor.

I can set the Left and Top properties dynamically provided that at
design time I set the form's StartPosition property to Manual.

If I move my attempts to set the size to the InitializeComponent()
method then all is OK.

Strange that I can set the Text, Left and Top properties within the
constructor, but not the Size property. I am probably missing
something.

Problem is sorted for know, but I would be interested to know what the
problem with doing this in the constructor was.

Kevin R.

Re: Visual C# Unable to alter size or position of form by Ken

Ken
Fri Dec 31 10:22:22 CST 2004

In general, these types of changes should be made in the Load() handler,
and not in the constructor, as the underlying Windows objects do not yet
exist.

-ken

Kevin R wrote:
> On Fri, 31 Dec 2004 14:13:46 +0000, Kevin R <me@privacy.net> wrote:
>
>
>>Hi
>>I have this in a method which is called when my form is created
>>
>>public CreateDevice()
>>{
>> // Set the initial size of our form
>> this.Top = 0;
>> this.Left = 0;
>> this.Size = new System.Drawing.Size(500,800);
>> //this.ClientSize = new System.Drawing.Size(400,300);
>> // And it's caption
>> this.Text = "Rhubarb: CreateDevice";
>> // Load our icon from the resources of the .exe
>> this.Icon = new Icon(this.GetType(), "directx.ico");
>>}
>>
>>the method is being called OK, because the forms text is being set to
>>what ever I want it to be. But attempts to set the Top, Left or Size
>>members are having no effect at all, the same with attempts to set the
>>ClientSize member.
>>I can resize the form by dragging, when it is running.
>>I am completely new to C# so it may be something really dumb.
>>
>>Any ideas
>>
>>Kevin R.
>
>
>
> The form is actually called CreateDevice. Hence the method above is
> the constructor.
>
> I can set the Left and Top properties dynamically provided that at
> design time I set the form's StartPosition property to Manual.
>
> If I move my attempts to set the size to the InitializeComponent()
> method then all is OK.
>
> Strange that I can set the Text, Left and Top properties within the
> constructor, but not the Size property. I am probably missing
> something.
>
> Problem is sorted for know, but I would be interested to know what the
> problem with doing this in the constructor was.
>
> Kevin R.