473,791 Members | 3,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Resize components in a Form

Hello

With the code below I can resize all the components on a Form when ever the
Form resizes.

For the time beeing it dosn't allow a component to contain another
component, but with a little extra work I can make it work at any dept!

Problem: I can change Left,Top,Width, Height, but I can change the
Font.Size.

Can anybody help me?
Thanks in advance

Best regards

Poul C

// ---- further explanation -----------

Form1_Load: Left,Top,Width, Height are saved in the "Tag" property,
seperated with ";"

Form1_Resize: the components old values for Left,Top,Width, Height are
multiplyed by a factor = newFormSize/oldFormSize
I can use Left,Top,Width, Height without "type-casting" all-though I am using
a "super-component", because all components have the Left,Top,Width, Height
properties.

Of course I can't do the same to the proterty "Font.Size" , because all
components do not have that property!!
I have tryed to change the line:

cc.Font = new System.Drawing. Font ("Verdana", 10,
System.Drawing. FontStyle.Bold) ;

to:

Label ccc = (System.Windows .Forms.Label)cc ;

ccc.Font = new System.Drawing. Font ("Verdana",
10,System.Drawi ng.FontStyle.Bo ld);

But this dosn't work either!

Please read the remarks in this code:
//------ code ------

private void Form1_Load(obje ct sender, System.EventArg s e) {
// Left,Top,Width, Height are saved in the "Tag" property,
separated with ";"

foreach (Control cc in Controls) cc.Tag = cc.Left+ ";" +
cc.Top+";"+cc.W idth+";"+cc.Hei ght;
}
private void Form1_Resize(ob ject sender, System.EventArg s e) {
char[] sep = {';'};
Array a;
foreach (Control cc in Controls)
{
a = ((String)cc.Tag ).Split(sep);
// This works fine! ==>
cc.Left =
(int)(this.Disp layRectangle.Wi dth*int.Parse(( String)a.GetVal ue(0))/800);
cc.Top =
(int)(this.Disp layRectangle.He ight*int.Parse( (String)a.GetVa lue(1))/600);
cc.Width =(int)(this.Dis playRectangle.W idth*
int.Parse((Stri ng)a.GetValue(2 ))/800);
cc.Height
=(int)(this.Dis playRectangle.H eight*int.Parse ((String)a.GetV alue(3))/600);
if
(cc.GetType()== Type.GetType("S ystem.Windows.F orms.Label")) {//<= only Labels
goes here!
// Here is the problem: the size of the Font
does not change!!
cc.Font = new System.Drawing. Font
("Verdana", 10, System.Drawing. FontStyle.Bold) ;
// The 10 is only for test purpose
}

// Test purpose: this works fine! ==>
label1.Font = new System.Drawing. Font ("Verdana", 10,
System.Drawing. FontStyle.Bold) ;

}
Nov 16 '05 #1
3 6227
Hello again!

Yes, - I'll bee the first to answer my own letter:

"Poul C" wrote:

Problem: I can change Left,Top,Width, Height, but I can change the
Font.Size.


This line should read:
Problem: I can change Left,Top,Width, Height, but I can * n o t * change the
Font.Size.

Best regards Poul C
Nov 16 '05 #2
R
You can't change just onw of the Font properties!

You need to do something like:
foo.Font = new System.Drawing. Font("Arial", 17F);

R
--
Due to heavy (20,000+/week!!) spam reception, I use a fake email.
Please reply in this group, which would help others as well.

Help fight spam:
NEVER reply to spam
NEVER buy anything from spamers
NEVER unsubscribe from a spam-list

"Poul C" <te****@hafnet. dk> wrote in message
news:40******** *************@n ntp04.dk.telia. net...
Hello again!

Yes, - I'll bee the first to answer my own letter:

"Poul C" wrote:

Problem: I can change Left,Top,Width, Height, but I can change the
Font.Size.
This line should read:
Problem: I can change Left,Top,Width, Height, but I can * n o t * change

the Font.Size.

Best regards Poul C

Nov 16 '05 #3
Hello R

"R" <fo*@bar.com> wrote...
You can't change just onw of the Font properties!

You need to do something like:
foo.Font = new System.Drawing. Font("Arial", 17F);
R


I kwow, - and that was just what I was doing (source-code at the bottom af
my letter):

cc.Font = new System.Drawing. Font ("Verdana",
10,System.Drawi ng.FontStyle.Bo ld);

or:

Label ccc = (System.Windows .Forms.Label)cc ;

ccc.Font = new System.Drawing. Font
("Verdana",10,S ystem.Drawing.F ontStyle.Bold);
Best regards Poul C
Nov 16 '05 #4

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

Similar topics

6
8341
by: Ty Salistean | last post by:
I have a form that I inherited from System.Windows.Forms. I use that form everywhere in my system. I went back to my base class form and changed the size, expecting all of my children forms to inherit the base class forms size. This is not what happened. All of my children forms thought the size property was overridden. They stayed the old size. How can I get my children forms to respect the parents size property? I am assuming...
2
2153
by: IkBenHet | last post by:
Hello, I use an ASP.NET script on my website to upload images (complete script is listed at the end of this message). Now, I want to limit the size (in width and height, but also in bytes). For example, if the image is max. 400 pixel in height or max. 400 pixel width or max. 100 Kb. The image is not uploaded. How can I do this? Additionally, I also want to resize the images to a valid size when
4
3490
by: Rob Richardson | last post by:
Greetings! I have a form with a listview, a menu, and a few text boxes, labels and command buttons. I want to resize the listview when the form is resized to that the widths of the spaces between the borders of the listview and the borders of the form remain constant. I am finding this to be unexpectedly hard. For one thing, I initialized some values in the form's Load event, and I'm doing the control resizing in the form's Resize...
2
5823
by: Kevin L | last post by:
How would I go about resizing a panel control using a mouse at runtime?
2
4544
by: Peter Proost | last post by:
Hi group I have the following piece of code that should resize the bitmap in a picture box but it doesn't work as I tought it would. Can someone help me with it? thnx Peter Public Class Form1 Inherits System.Windows.Forms.Form
6
5206
by: Rob | last post by:
I need to create a form that will resize only the verticle size of the Form and not the width. So far I'm partial to the following code. Can someone please elaborate the ??? . . . . Const WM_SIZE = &H5 Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Call MyBase.WndProc(m)
4
2460
by: michael sorens | last post by:
In a Windows Form application, when a user resizes the window, I typically want different components in the form to take different actions. For example, a text box in the middle should grow with the window; a button panel at the bottom should remain the same height but re-center horizontally; etc. What I have settled on as a technique for managing this is to start witha table container (dock=fill), then by combining rowspans,...
0
1030
by: Beemer Biker | last post by:
I cannot account for this and have been unable to get an answer from the vendors forum. They are asking me if I am using 1.1 or 2.0 dot net so I assume they can't duplicate my problem. From a working asp.net, VS80, SP1, If I resize their control, the source code is changed and valid source code become invalid. This is what it looks like:
3
2318
by: monadel | last post by:
Hi guys, How do you resize a form in VB. Basically when user drag the form to minimise or maximise, it will resize all the components inside the form. thanks
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10207
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
10156
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
9997
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...
1
7537
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
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
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.