473,408 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Proprietà Height di ComboBox non impostabile e che cambia da 20 a 21

Ciao a tutti,
leggendo qua e là per il forum ho scoperto che non sono l'unico ad
avere questo problema.
Se si inserisce un controllo ComboBox in un form di C#, non è
possibile impostare la sua altezza ad un valore diverso da 21. Forse,
cambiando la dimensione del font, si potrebbe riuscire a cambiare anche
l'impostazione dell'altezza... (MS farebbe comunque meglio ad
introdurre per il ComboBox una proprietà AutoSize impostabile a
"false" come nel caso del TextBox).
La cosa strana è però la seguente:
al momento del caricamento del form (tramite il relativo costruttore di
classe), l'altezza del ComboBox è impostata a 20; finito il
caricamento, il valore cambia a 21... Pazzesco!!!
Ho fatto una prova molto semplice: ho costruito un form in cui ho
inserito 3 ComboBox uno sotto l'altro. Ho impostato la proprietà Top
di ciascun ComboBox come la somma della proprietà Top di quello sopra
+ la sua altezza + 20. In più, ho anche inserito alcuni altri
controlli per notare come invece le loro altezze restano invariate.
Alla fine del costruttore del form ho scritto una chiamata ad una
procedura che stampa sulla Console Window le posizioni e le dimensioni
dei vari controlli (l'altezza dei vari ComboBox a quel punto risulta
20). Cliccando su un pulsante "Print" viene chiamata la stessa
procedura, che stavolta però evidenzierà che l'altezza dei ComboBox
è ora a 21.
Cliccando infine su un pulsante "Relocate" viene chiamata una procedura
che riesegue le stesse istruzioni di Location dei controlli eseguite
nel costruttore del form (con le proprietà Top calcolate nel modo
suddetto, solo che stavolta cambieranno anch'esse, essendo le altezze
aumentate di 1). L'effetto visivo è che, quando si clicca su
"Relocate", si vedrà i ComboBox abbassarsi leggermente... Cliccando di
nuovo su "Print" ci si renderà conto del cambiamento dei valori delle
proprietà Top.
Poco male, basta impostare il Top di un ComboBox come il Top del
ComboBox sovrastante + 20 (la sua altezza teorica) + altri 20 = 40...

Qui sotto, se qualcuno vuole fare la prova, metto il codice sorgente...
Ciao

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

public class FormLogicTrace: Form
{
public static void Main()
{
Application.Run(new FormLogicTrace());
}

Label lbl;
TextBox txt;
Button btn;
ComboBox cbo1, cbo2, cbo3;
Button btnPrintComboBoxesLocations_Dimensions, btnRelocateControls;

public FormLogicTrace()
{
Size = new Size(200, 420);
CenterToScreen();

lbl = new Label();
lbl.Parent = this;
lbl.Size = new Size(120, 20);
lbl.Location = new Point(20, 20);
lbl.Text = "lbl";

txt = new TextBox();
txt.Parent = this;
txt.Size = new Size(120, 20);
txt.Location = new Point(20, lbl.Top + lbl.Height + 20);
txt.Text = "txt";

btn = new Button();
btn.Parent = this;
btn.Size = new Size(120, 25);
btn.Location = new Point(20, txt.Top + txt.Height + 20);
btn.Text = "btn";

cbo1 = new ComboBox();
cbo1.Parent = this;
cbo1.Size = new Size(120, 30);
cbo1.Location = new Point(20, btn.Top + btn.Height + 20);
cbo1.DropDownStyle = ComboBoxStyle.DropDownList;
cbo1.Items.AddRange(new string[] {"cbo1", "cbo2", "cbo3"});
cbo1.SelectedIndex = 0;

cbo2 = new ComboBox();
cbo2.Parent = this;
cbo2.Size = new Size(120, 30);
cbo2.Location = new Point(20, cbo1.Top + cbo1.Height + 20);
cbo2.DropDownStyle = ComboBoxStyle.DropDownList;
cbo2.Items.AddRange(new string[] {"cbo1", "cbo2", "cbo3"});
cbo2.SelectedIndex = 0;

cbo3 = new ComboBox();
cbo3.Parent = this;
cbo3.Size = new Size(120, 30);
cbo3.Location = new Point(20, cbo2.Top + cbo2.Height + 20);
cbo3.DropDownStyle = ComboBoxStyle.DropDownList;
cbo3.Items.AddRange(new string[] {"cbo1", "cbo2", "cbo3"});
cbo3.SelectedIndex = 0;

btnPrintComboBoxesLocations_Dimensions = new Button();
btnPrintComboBoxesLocations_Dimensions.Parent = this;
btnPrintComboBoxesLocations_Dimensions.Size = new Size(120, 25);
btnPrintComboBoxesLocations_Dimensions.Location = new Point(20,
cbo3.Top + cbo3.Height + 20);
btnPrintComboBoxesLocations_Dimensions.Text = "Print";
btnPrintComboBoxesLocations_Dimensions.Click += new
EventHandler(btnPrintComboBoxDimension_Click);

btnRelocateControls = new Button();
btnRelocateControls.Parent = this;
btnRelocateControls.Size = new Size(120, 25);
btnRelocateControls.Location = new Point(20,
btnPrintComboBoxesLocations_Dimensions.Top +
btnPrintComboBoxesLocations_Dimensions.Height + 20);
btnRelocateControls.Text = "Relocate";
btnRelocateControls.Click += new
EventHandler(btnRelocateControls_Click);
PrintControlsLocations_Dimensions();
}

private void btnPrintComboBoxDimension_Click(object sender, EventArgs
e)
{
PrintControlsLocations_Dimensions();
}

void PrintControlsLocations_Dimensions()
{
Console.WriteLine("Label location / dimensions: Left = " + lbl.Left +
", Top = " + lbl.Top + ", Width = " + lbl.Width + ", Height = " +
lbl.Height);
Console.WriteLine("TextBox location / dimensions: Left = " + txt.Left
+ ", Top = " + txt.Top + ", Width = " + txt.Width + ", Height = " +
txt.Height);
Console.WriteLine("Button location / dimensions: Left = " + btn.Left
+ ", Top = " + btn.Top + ", Width = " + btn.Width + ", Height = " +
btn.Height);
Console.WriteLine("ComboBox1 location / dimensions: Left = " +
cbo1.Left + ", Top = " + cbo1.Top + ", Width = " + cbo1.Width + ",
Height = " + cbo1.Height);
Console.WriteLine("ComboBox2 location / dimensions: Left = " +
cbo2.Left + ", Top = " + cbo2.Top + ", Width = " + cbo2.Width + ",
Height = " + cbo2.Height);
Console.WriteLine("ComboBox3 location / dimensions: Left = " +
cbo3.Left + ", Top = " + cbo3.Top + ", Width = " + cbo3.Width + ",
Height = " + cbo3.Height);
Console.WriteLine("Print Button location / dimensions: Left = " +
btnPrintComboBoxesLocations_Dimensions.Left + ", Top = " +
btnPrintComboBoxesLocations_Dimensions.Top + ", Width = " +
btnPrintComboBoxesLocations_Dimensions.Width + ", Height = " +
btnPrintComboBoxesLocations_Dimensions.Height);
Console.WriteLine("Relocate Button location / dimensions: Left = " +
btnRelocateControls.Left + ", Top = " + btnRelocateControls.Top + ",
Width = " + btnRelocateControls.Width + ", Height = " +
btnRelocateControls.Height);
Console.WriteLine();
}

void RelocateControls()
{
lbl.Location = new Point(20, 20);
txt.Location = new Point(20, lbl.Top + lbl.Height + 20);
btn.Location = new Point(20, txt.Top + txt.Height + 20);
cbo1.Location = new Point(20, btn.Top + btn.Height + 20);
cbo2.Location = new Point(20, cbo1.Top + cbo1.Height + 20);
cbo3.Location = new Point(20, cbo2.Top + cbo2.Height + 20);
btnPrintComboBoxesLocations_Dimensions.Location = new Point(20,
cbo3.Top + cbo3.Height + 20);
btnRelocateControls.Location = new Point(20,
btnPrintComboBoxesLocations_Dimensions.Top +
btnPrintComboBoxesLocations_Dimensions.Height + 20);
}

private void btnRelocateControls_Click(object sender, EventArgs e)
{
RelocateControls();
}
}

Mar 22 '06 #1
1 3346
Purtroppo ci sono poche persone nel questo grupo que parlano
l'italiano, ed il mio italiano non é piu buono.

C'é un gruppo in italiano:

microsoft.public.it.dotnet.csharp

Mar 22 '06 #2

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

Similar topics

3
by: Harlin Seritt | last post by:
I've created a ghetto-ized ComboBox that should work nicely for Tkinter (unfortunately no dropdown capabilities yet). I've found why it's such a pain in the @ss to create one. You have to...
1
by: fede | last post by:
Ho visto che su Interdev si può impostare per un progetto ASP la proprietà EnableSessionsDefault a true o false.Qualcuno sa dirmi che effetti ha?E quali le conseguenze? Grazie!
1
by: Morten Wennevik | last post by:
Like a Button and RadioButton has a FlatStyle and a TextBox has a BorderStyle, is it possible to set a ComboBox to appear in the same way? No 3D borders. -- Using M2, Opera's revolutionary...
1
by: anonymous | last post by:
I've been trying to put a them, please help me out. Here's the major parts of my code: public Form1() { DataSet myDataSet = new DataSet("myDataSet"); DataTable testTable = new...
2
by: Don | last post by:
I've looked high and low for some code that will allow me to have a combobox with a flat borderstyle. I found a few examples, but nothing that was really usable for me. I had the following...
1
by: mastermirko | last post by:
Ciao a tutti, vi chiedo una cortesia. Io devo connettermi ad un Database Oracle, e devo poter leggere tutte le tabelle. Voglio però creare una classe base Tabella che sia la superclasse di tutte...
2
by: Brian Tkatch | last post by:
This is mostly for the fun of it. Just saw it in the FAQ and figured i'd quickly give it a shot. The syncfusion FAQ <URL:http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q480q>...
2
by: TomasART | last post by:
Hi All, At first i will give thanks of all who have help me in the other thread. Know my combo works :). Ok, you know the combo calls a javascript function in the onchage statement. $combo =...
0
by: wizofoz777 | last post by:
Ok here is my problem : I was creating comboboxes and I wanted to be able to use the same event for all of them. So I decided to create a combobox collection containing the event in a wrapper. When...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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...
0
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...

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.