By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,276 Members | 2,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,276 IT Pros & Developers. It's quick & easy.

A problem with "Location" and "Size"

P: n/a
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


Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"JMUApache" wrote...
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
Nov 17 '05 #2

P: n/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



On Sat, 20 Aug 2005 11:25:19 +0200, ""
<bj**********@DoNotSpam.hotmail.com> wrote:

"JMUApache" wrote...
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


Nov 17 '05 #3

P: n/a

"JMUApache" wrote...
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
Nov 17 '05 #4

P: n/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

On Sat, 20 Aug 2005 20:12:53 +0200, "Bjorn Abelli"
<bj**********@DoNotSpam.hotmail.com> wrote:

"JMUApache" wrote...
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


Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.