A problem with "Location" and "Size"

  • Thread starter Thread starter JMUApache
  • Start date Start date
J

JMUApache

Hi,

A have a problem with Inhreit Control.

I try to Change its Size in Construct Function, And it works.

Code Here:
--------------------------------------------------
public class UserControl:TextBox
{
public UserControl()
{
this.Size = new Size (100, 100);
}
}
--------------------------------------------------


And then I try to Change it's Location, but it won't work.

Code Here:
--------------------------------------------------
public class UserControl:TextBox
{
public UserControl()
{
this.Location = new Point (100, 100);
}
}
--------------------------------------------------


What can I do if I want to change the Control's Location by the
Control itself?

Any help would be appreciate!

Thanks

chen
 
...
A have a problem with Inhreit Control.

I try to Change its Size in Construct Function, And it works.

[snipped code]
And then I try to Change it's Location, but it won't work.

[snipped code]
What can I do if I want to change the Control's Location
by the Control itself?

You both can and can't...

Actually what you did with both the Size and Location was to change the
"default" values, but both of those are made void by the *user* of your
control.

If you use some graphical IDE for placing the control on a Form or likewise,
that will cause the IDE to generate code for at least the Location (the
place where you clicked in the control on the form) and the user can change
the Size in the same IDE, which replaces the "default" values of your
control.

// Bjorn A
 
Hi, Bjorn

First Thanks for your answer. Maybe I have not Describe my
question Well.

I didn't drag this control to the form but use code "new"

code here
-------------------------------------------
UserControl uc = new UserControl ();
--------------------------------------------

and I did not change its "Location" or "Size" property on my code.
It work well with "Size", but "Location" not.

And I then write a "SetLocation" Function in the UserControl
class, then call it from the form. The "SetLocation" do not work,
either.

Thanks for reply.

chen hui







...
A have a problem with Inhreit Control.

I try to Change its Size in Construct Function, And it works.

[snipped code]
And then I try to Change it's Location, but it won't work.

[snipped code]
What can I do if I want to change the Control's Location
by the Control itself?

You both can and can't...

Actually what you did with both the Size and Location was to change the
"default" values, but both of those are made void by the *user* of your
control.

If you use some graphical IDE for placing the control on a Form or likewise,
that will cause the IDE to generate code for at least the Location (the
place where you clicked in the control on the form) and the user can change
the Size in the same IDE, which replaces the "default" values of your
control.

// Bjorn A
 
...
First Thanks for your answer. Maybe I have not Describe my
question Well.

I didn't drag this control to the form but use code "new"

code here
-------------------------------------------
UserControl uc = new UserControl ();
--------------------------------------------

and I did not change its "Location" or "Size" property on my code.
It work well with "Size", but "Location" not.

And I then write a "SetLocation" Function in the UserControl
class, then call it from the form. The "SetLocation" do not work,
either.


In that case, could you provide a small but complete example, where your
problem occurs.

How I try, I can't replicate your problem.

In this small sample the Location is set at {100, 100}:


using System;
using System.Drawing;
using System.Windows.Forms;

class UserControl : System.Windows.Forms.TextBox
{
public UserControl()
{
Location = new Point (100, 100);
}
}

public class Form1 : System.Windows.Forms.Form
{
public Form1()
{
UserControl uc = new UserControl ();
this.Size = new System.Drawing.Size(300,300);
this.Controls.Add(uc);
}

static void Main()
{
Application.Run(new Form1());
}
}


// Bjorn A
 
Hi Bjorn:

Thank you.

The reson it does not work it is that I set it's Location
property another place.

Thanks for your reply.

chen hui
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top