我想區分表單中的強制性TextBox字段。我通過用每種形式調用的方法創建一個類來實現這一點。該方法所做的是接收一個文本框列表,併爲每個文本框設置另一個背景顏色。在每個文本框內繪製一個矩形c#winform
public static void Mostrar_campos_obligatorios(List<TextBox> lista_textbox)
{
foreach (TextBox tbx in lista_textbox)
{
tbx.Paint += new PaintEventHandler(TextBoxRectangle);
}
}
我現在已經改變了圖形用戶界面,而且我不喜歡它的外觀時,背景色是變了樣,然後我想畫一個矩形,如我在接下來的畫面:
給我留下漸變的東西,我只需要幫助繪製每個文本框高度相同的矩形並位於它的末尾。我也想使用該方法定義(我的意思是,接收文本框列表)。
請注意,該方法是靜態的..
我想是這樣的:
public static void TextBoxRectangle(object sender, PaintEventArgs e)
{
tbx = (TextBox)sender;
Color c1 = Color.FromArgb(255, 113, 255, 0);
Color c2 = Color.FromArgb(255, 2, 143, 17);
LinearGradientBrush br = new LinearGradientBrush(e.CellBounds, c1, c2, 90, true);
ColorBlend cb = new ColorBlend();
cb.Positions = new[] { 0, (float)1 };
cb.Colors = new[] { c1, c2 };
br.InterpolationColors = cb;
Rectangle rect = new Rectangle(tbx.Location.X + 4, tbx.Location.Y + 4, 13, 13);
e.Graphics.FillRectangle(br, rect);
}
但不工作。它甚至不訪問TextBoxRectangle()
。我認爲I'm做非常錯誤..
是的,我真的用表情混合。但我爲我的應用程序使用Winforms。毫無疑問,這是最好的答案。我真的在做一些簡單的事情,一些非常複雜的事情。謝謝! – Andres