|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Apr 2007
Messaggi: 263
|
[c#] Problema con ridimensionamento di un Form
Salve a tutti,
Sto creando un piccolo progetto in c#. Ho creato un Form senza barra del titolo al cui interno ho messo una Listbox(modificata per poter visualizzare le immagini) e ho settato dock = fill; ![]() Come sapete una Listbox modifica la dimensione in modo che nessun'elemento sia visibile solo per metà. Vorrei avere lo stesso comportamente anche sul Form, così da non avere spazi vuoti(come nell'immagine). Ho provato a sovrascrivere la funzione OnResize: Codice:
protected override void OnResize(EventArgs e)
{
this.Height = (this.Height / 16) * 16 + 4;
base.OnResize(e);
}
|
|
|
|
|
|
#2 | |
|
Senior Member
Iscritto dal: Dec 2004
Messaggi: 3210
|
Quote:
|
|
|
|
|
|
|
#3 | |
|
Member
Iscritto dal: Apr 2007
Messaggi: 263
|
Quote:
Codice:
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
public const Int32 WM_NCHITTEST = 132;
public const Int32 HTTOP = 12;
public const Int32 HTTOPLEFT = 13;
public const Int32 HTTOPRIGHT = 14;
public const Int32 HTBOTTOMLEFT = 16;
public const Int32 HTBOTTOMRIGHT = 17;
public const int WM_SIZING = 0x214;
public const Int32 WMSZ_LEFT = 1;
public const Int32 WMSZ_RIGHT = 2;
public const Int32 WMSZ_TOP = 3;
public const Int32 WMSZ_BOTTOM = 6;
public const Int32 WMSZ_BOTTOMLEFT = 7;
public const Int32 WMSZ_BOTTOMRIGHT = 8;
protected override void WndProc(ref Message m)
{
Int32 res;
switch (m.Msg)
{
case WM_NCHITTEST:
{
base.WndProc(ref m);
res = m.Result.ToInt32();
}
break;
case WM_SIZING:
{
RECT rc = (RECT)Marshal.PtrToStructure(m.LParam, typeof(RECT));
res = m.WParam.ToInt32();
if (res == WMSZ_RIGHT || res == WMSZ_LEFT || res == WMSZ_BOTTOM || res == WMSZ_BOTTOMLEFT || res == WMSZ_BOTTOMRIGHT)
{
int deltaW = this.Width - this.ClientSize.Width;
int deltaH = this.Height - this.ClientSize.Height;
rc.Bottom = rc.Top + Math.Min(((rc.Bottom - rc.Top - deltaH) / 16), this.Count) * 16 + 4 + deltaH; // Adjust size
}
else
{
int deltaW = this.Width - this.ClientSize.Width;
int deltaH = this.Height - this.ClientSize.Height;
rc.Top = rc.Bottom - (Math.Min(((rc.Bottom - rc.Top - deltaH) / 16), this.Count) * 16 + 4 + deltaH); // Adjust size
}
Marshal.StructureToPtr(rc, m.LParam, true);
}
break;
default:
break;
}
base.WndProc(ref m);
}
|
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 20:14.




















