TextBox com borda inferior
eu quero terTextBox
com borda inferior, mas gráficos desenhados paraTextBox
distorcido / quebrado no redimensionamento por causa deColor.Transparent
.
Usando um código que encontrei, consegui criar um TextBox sublinhado (retângulo desenhado com parte superior transparente, esquerda e direita). O problema é quando redimensiono o formulário / janela: quando redimensiono para menor, e redimensiono novamente para expandi-lo, os gráficos desenhados ficam distorcidos.Alguma correção para isso?
Aqui estão as fotos:A segunda foto já foi redimensionada em tamanho menor e depois voltada para um tamanho maior.
Aqui está o código:
[DllImport("user32")]
private static extern IntPtr GetWindowDC(IntPtr hwnd);
struct RECT {
public int left, top, right, bottom;
}
struct NCCALSIZE_PARAMS {
public RECT newWindow;
public RECT oldWindow;
public RECT clientWindow;
IntPtr windowPos;
}
float clientPadding = 0;
int actualBorderWidth = 2;
Color borderColor = Color.Black;
protected override void WndProc(ref Message m) {
//We have to change the clientsize to make room for borders
//if not, the border is limited in how thick it is.
if (m.Msg == 0x83) { //WM_NCCALCSIZE
if (m.WParam == IntPtr.Zero) {
RECT rect = (RECT)Marshal.PtrToStructure(m.LParam, typeof(RECT));
rect.left += 2;
rect.right -= 2;
rect.top += 0;
rect.bottom -= 0;// (int)clientPadding;
Marshal.StructureToPtr(rect, m.LParam, false);
} else {
NCCALSIZE_PARAMS rects = (NCCALSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(NCCALSIZE_PARAMS));
rects.newWindow.left += (int)clientPadding;
rects.newWindow.right -= (int)clientPadding;
rects.newWindow.top += (int)clientPadding;
rects.newWindow.bottom -= 2;
Marshal.StructureToPtr(rects, m.LParam, false);
}
}
if (m.Msg == 0x85) {//WM_NCPAINT
IntPtr wDC = GetWindowDC(Handle);
using (Graphics g = Graphics.FromHdc(wDC)) {
ControlPaint.DrawBorder(g, new Rectangle(0, 0, Size.Width, Size.Height),
Color.Transparent, 1, ButtonBorderStyle.Solid,
Color.Transparent, 1, ButtonBorderStyle.Solid,
Color.Transparent, 1, ButtonBorderStyle.Solid,
borderColor, actualBorderWidth, ButtonBorderStyle.Solid);
}
return;
}
base.WndProc(ref m);
}
Color.Transparent
Corrigi-o alterando-o para Color.White, pois tenho um fundo branco. Mas então, isso nem sempre seria o caso,como impedir que "tremer / rasgar" enquanto estiver usando Color.Transparent?