473,803 Members | 3,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Wrong size of UserControl

Hello

I have a UserControl sized to 100; 200
When I drop it in my form the initial size is 100;200 (as I prefer). Then I
decided to change the size of my UserControl to 200;200 but although I have
not set any value to the size of the dropped control in my form, recompiling
the project does not affect the new size of the user control in my form.

Surprisingly if I reset the Size property of my user control in the form,
the size changes to 150; 150! It seems some how, there is a DefaultValue for
Size property.

How can I solve my problem? I prefer when I resize my UserControl in form
designer, it affects all places it is used. another statement is I want my
default size affects from the main UserControl class.

Thanks in advance.
Hamed
Jun 27 '08 #1
4 9330
On May 28, 1:09 am, "Hamed" <ha...@raymehr. netwrote:
Hello

I have a UserControl sized to 100; 200
When I drop it in my form the initial size is 100;200 (as I prefer). Then I
decided to change the size of my UserControl to 200;200 but although I have
not set any value to the size of the dropped control in my form, recompiling
the project does not affect the new size of the user control in my form.

Surprisingly if I reset the Size property of my user control in the form,
the size changes to 150; 150! It seems some how, there is a DefaultValue for
Size property.

How can I solve my problem? I prefer when I resize my UserControl in form
designer, it affects all places it is used. another statement is I want my
default size affects from the main UserControl class.

Thanks in advance.
Hamed
Unless you add an attribute to your size property in your usercontrol,
it will not have a default size as far as the designer is concerned -
so the designer will add code that sets the size explicitly to the
size set when the control is created at design time.
To prevent this happening you need to tell the designer that this
control's size has a default.YOu should be able to do this using
[DefaultValue(ty peof(System.Dra wing.Size), "100, 200"] as an attribute
to the size property.

(I actrually just tried this, and it didn't work, as teh IDE seems to
still serialize the Size. As a work around, you can open the
Designer.cs file, and delete the line that sets your contorl's size -
from then on changing your usercontrol
s size will be reflected in the form where it is used. I'm not sure
why the DefaultValue isn't working 'properly' though- but I am sure
someone far cleverer than what I am will let us all know !)
Max
Jun 27 '08 #2
Max,
Thanks for your pay attention but:

1 - how do you assign DefaultValue attribute to the Size property that is
inherited from Control class?

2 - If I delete the line that sets Size, it will be created next time that I
open the form and do some changes.

Any suggestion is welcomed.

Hamed

>
(I actrually just tried this, and it didn't work, as teh IDE seems to
still serialize the Size. As a work around, you can open the
Designer.cs file, and delete the line that sets your contorl's size -
from then on changing your usercontrol
s size will be reflected in the form where it is used. I'm not sure
why the DefaultValue isn't working 'properly' though- but I am sure
someone far cleverer than what I am will let us all know !)
Max

Jun 27 '08 #3
Since Size property isn't virtual, overloading isn't possible, however
hiding is. Using the following property declaration in your user
control I believe you will make the designer respect your settings:

[DefaultValue(ty peof(Size), "300,300")]
public new Size Size { get; set; }

Just note that property hiding doesn't have the same effect as
overriding and you should be careful with how to use it. With that,
you would still have to "Reset" the Size property on every control of
that type (there's a "cure" for this also, like choosing to not
persist the Size property at all, but I'm not sure that's always a
good idea).
And a suggestion - Once happy with the final layout/size, I would
remove the above property declaration and let the final size persist
as it should.

Andrej

On 28 maj, 08:04, "Hamed" <ha...@raymehr. netwrote:
Max,
Thanks for your pay attention but:

1 - how do you assign DefaultValue attribute to the Size property that is
inherited from Control class?

2 - If I delete the line that sets Size, it will be created next time thatI
open the form and do some changes.

Any suggestion is welcomed.

Hamed


(I actrually just tried this, and it didn't work, as teh IDE seems to
still serialize the Size. As a work around, you can open the
Designer.cs file, and delete the line that sets your contorl's size -
from then on changing your usercontrol
s size will be reflected in the form where it is used. I'm not sure
why the DefaultValue isn't working 'properly' though- but I am sure
someone far cleverer than what I am will let us all know !)
Max- Skrij navedeno besedilo -

- Prikaži navedeno besedilo -
Jun 27 '08 #4
A quick look with Rflector shosw the following in the UserControl.

protected override Size get_DefaultSize ()
{
return new Size(150, 150);
}

Setting the DefaultValue attribute does not change this value. You should
override the property yourself to change it.
You can however set the default value to whatever your derived control
returns so that the designer will not highlight the value with bold text to
indicate that the value is not the default.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Hamed" <ha***@raymehr. netwrote in message
news:OD******** ******@TK2MSFTN GP03.phx.gbl...
Hello

I have a UserControl sized to 100; 200
When I drop it in my form the initial size is 100;200 (as I prefer). Then
I decided to change the size of my UserControl to 200;200 but although I
have not set any value to the size of the dropped control in my form,
recompiling the project does not affect the new size of the user control
in my form.

Surprisingly if I reset the Size property of my user control in the form,
the size changes to 150; 150! It seems some how, there is a DefaultValue
for Size property.

How can I solve my problem? I prefer when I resize my UserControl in form
designer, it affects all places it is used. another statement is I want my
default size affects from the main UserControl class.

Thanks in advance.
Hamed
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
7501
by: Lecture Snoddddgrass | last post by:
Hi, When I create a UserControl-derived object, I often expose various public properties. One of the things that I hate about the WinForms designer is that if I decide to embed one of these controls in a form (or another control), the designer likes to "touch" each of my custom properties -- either by trying to "set" it to a default value (null/zero) or trying to "get" it's value. This is a real PITA because often times calling "get" on...
4
1874
by: Derrick | last post by:
Hello all; I'm trying to simulate a "scrollable context menu". What I want is to have a listbox fill the entire area of a small form (with no border). Using the designer and property grid, I noticed that if I set the form size first, then try to copy and paste this value into the size of the listbox (making sure the listbox is in location 0,0 first), the designer won't let the listbox fill the entire form area - there are 9 pixels of...
0
5084
by: Miquel | last post by:
Hi all. I felt frustrated when developing an 'UserControl' derivated from textBox, because sequence event (and Validate event) seems to fail. I Always thought my code was wrong. But after trying the UserControl a lot of hours I have the feeling that c# (or .Net) fails. Thus, I have developed a simple program with 3 textBox, 1 Botton and 1 ListBox (for showing results) which fire OnEnter, OnGotFocus,
4
1576
by: JMUApache | last post by:
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 {
2
4635
by: Sascha | last post by:
Hi there, I searched carefully through the web before finally deciding to post this message, because I could not find a solution for my problem. Hopefully someone will have a hint or explanation for me! I apologize for the length of this posting, but I wanted to make sure that I get an answer other than "Hey man, just use LoadControl!", because this is not what I want. The Task: Isolate a collection of web forms which are created as
41
4335
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based on some initialization information obtained elsewhere. Basically, I'm going to create my own dynamic toolbar where the toolbarbuttons can change. I'm not using the VB toolbar because of limitations in changing things like backcolor (I can't get...
12
2216
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control server. It "serves" back the required control (either WebControl or UserControl) based on the contents of an xml file. The code in the webform places each control in a TableCell. My problem is that the control server works as far as returning the...
4
8901
by: Martijn Mulder | last post by:
I want my custom UserControl to size and resize with its parent, a Form. But when I use the code Size=Parent.ClientSize; in the constructor of myUserControl, Parent is null and the operation fails. What is the proper place to put this code?
2
8935
by: Rene Sørensen | last post by:
In VS 2005 I'm trying to create a usercontrol, but I have some problems with it right now I can't figure out how to fix. The size of my usercontrol is "Size 574; 619" I have anchored all controls added to the form, so I can resize it up and down, and not left and rigth. My usercontrol is a usercontrol project. In my main program I just drag and drop the control from the Toolbox, her the problems starts, the size of all subcontrols changes...
0
10309
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10289
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9119
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7600
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5496
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3795
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2968
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.