C# 我的面板上有几层图纸
我创建了一个面板,并用DrawString和DrawRectangle将文本放在上面。要绘制面板,我使用Paint事件和Invalidate方法,但当调用Invalidate时,我得到以下结果(背景色透明): 如您所见,文本是绘制的,但其背后的内容不会消失,就好像Invalidate完成了他的一半工作一样 我已将DoubleBuffered设置为true,并尝试了图形。清晰但没有成功 有人能帮我吗 代码如下:C# 我的面板上有几层图纸,c#,winforms,panel,paint,C#,Winforms,Panel,Paint,我创建了一个面板,并用DrawString和DrawRectangle将文本放在上面。要绘制面板,我使用Paint事件和Invalidate方法,但当调用Invalidate时,我得到以下结果(背景色透明): 如您所见,文本是绘制的,但其背后的内容不会消失,就好像Invalidate完成了他的一半工作一样 我已将DoubleBuffered设置为true,并尝试了图形。清晰但没有成功 有人能帮我吗 代码如下: int x = 0; int y = arro
int x = 0;
int y = arrowUpHeight;
int traceIndex = 0;
lock (_lockDraw)
{
while (y < Height)
{
rect = new Rectangle(x, y, Width, 20);
r = new Rectangle(x, y, rect.Width + 1, rect.Height + 1);
bufferGraphics.SetClip(r);
if (traceIndex < traceList.Count)
{
if (traceIndex < numberOfTraces)
{
Line data = traceList[traceIndex];
if (traceIndex % 2 == 0)
{
bufferGraphics.FillRectangle(brushEven, rect);
}
else
{
bufferGraphics.FillRectangle(brushOdd, rect);
}
if (y < mousePositionY && mousePositionY < y + 20)
{
traceSelected = true;
traceList[traceIndex].Selected = true;
listLinesVisible[traceIndex].Selected = true;
listLines[listLines.IndexOf(traceList[traceIndex])].Selected = true;
indexRightClick = traceIndex;
}
else
{
if (listLines.IndexOf(traceList[traceIndex]) < listLines.Count && listLines.IndexOf(traceList[traceIndex]) >= 0)
{
traceList[traceIndex].Selected = false;
listLinesVisible[traceIndex].Selected = false;
listLines[listLines.IndexOf(traceList[traceIndex])].Selected = false;
}
}
if (traceList[traceIndex].Message.ToUpper().Contains(textBoxRUISearch.MyTextBox.Text.ToUpper()) && textBoxRUISearch.MyTextBox.Text != String.Empty)
{
bufferGraphics.FillRectangle(searchBrush, rect);
}
if (traceList[traceIndex].Selected)
{
//doesn't work correctly for the moment when scrolling
bufferGraphics.FillRectangle(selectedBrush, rect);
bufferGraphics.DrawString(data.Date, traceFont, selectedStringBrush, xTime, y);
bufferGraphics.DrawString(data.LevelString, traceFont, selectedStringBrush, xLevel, y);
bufferGraphics.DrawString(data.Source, traceFont, selectedStringBrush, xSource, y);
if (data.Attachment != null)
{
bufferGraphics.DrawString("Attachment : ", traceFont, selectedStringBrush, xMessage, y);
bufferGraphics.DrawString(data.Message, traceFont, selectedStringBrush, xMessage + (xMessage / 5), y);
}
else
bufferGraphics.DrawString(data.Message, traceFont, selectedStringBrush, xMessage, y);
}
else
{
bufferGraphics.DrawString(data.Date, traceFont, stringBrush, xTime, y);
// Info = 1, Warning = 2, Error = 3, Debug = 5, Special = 6
switch (data.LevelString)
{
case "Info":
bufferGraphics.DrawString(data.LevelString, traceFont, brushInfo, xLevel, y);
break;
case "Warning":
bufferGraphics.DrawString(data.LevelString, traceFont, brushWarning, xLevel, y);
break;
case "Error":
bufferGraphics.DrawString(data.LevelString, traceFont, brushError, xLevel, y);
break;
case "Debug":
bufferGraphics.DrawString(data.LevelString, traceFont, brushDebug, xLevel, y);
break;
default:
break;
}
bufferGraphics.DrawString(data.Source, traceFont, stringBrush, xSource, y);
if (data.Attachment != null)
{
bufferGraphics.DrawString("Attachment : ", traceFont, brushAttachment, xMessage, y);
bufferGraphics.DrawString(data.Message, traceFont, stringBrush, xMessage + (xMessage / 5), y);
}
else
bufferGraphics.DrawString(data.Message, traceFont, stringBrush, xMessage, y);
}
bufferGraphics.DrawRectangle(Pens.LightGray, rect);
//
// if (data.selected)
// {
// Color color = Color.FromArgb(100, 0, 0, 255);
// Brush brush = new SolidBrush(color);
// _bufferGraphics.FillRectangle(brush, rect);
// }
}
else
{
if (listLines.ElementAtOrDefault(listLines.Count - 1) != null)
listLines.RemoveAt(listLines.Count - 1);
if (listLinesVisible.ElementAtOrDefault(listLinesVisible.Count - 1) != null)
listLinesVisible.RemoveAt(listLinesVisible.Count - 1);
y -= 20;
}
}
else
bufferGraphics.FillRectangle(brushUnderTraces, rect);
y += 20;
traceIndex++;
}
}
this.panelTraces.Invalidate();
intx=0;
int y=箭头方向;
int traceIndex=0;
锁定(_lockdaw)
{
while(y<高度)
{
rect=新矩形(x,y,宽度,20);
r=新矩形(x,y,矩形宽度+1,矩形高度+1);
bufferGraphics.SetClip(r);
if(traceIndex=0
{
traceList[traceIndex].Selected=false;
listLinesVisible[traceIndex].Selected=false;
listLines[listLines.IndexOf(traceList[traceIndex])。Selected=false;
}
}
if(traceList[traceIndex].Message.ToUpper()包含(textBoxRUISearch.MyTextBox.Text.ToUpper())和&textBoxRUISearch.MyTextBox.Text!=String.Empty)
{
bufferGraphics.FillRectangle(searchBrush,rect);
}
如果(traceList[traceIndex]。选中)
{
//滚动时暂时无法正常工作
bufferGraphics.FillRectangle(selectedBrush,rect);
bufferGraphics.DrawString(data.Date、traceFont、selectedStringBrush、xTime、y);
bufferGraphics.DrawString(data.LevelString、traceFont、selectedStringBrush、xLevel、y);
bufferGraphics.DrawString(data.Source、traceFont、selectedStringBrush、xSource、y);
if(data.Attachment!=null)
{
bufferGraphics.DrawString(“附件:”,traceFont,selectedStringBrush,xMessage,y);
bufferGraphics.DrawString(data.Message,traceFont,selectedStringBrush,xMessage+(xMessage/5),y);
}
其他的
bufferGraphics.DrawString(data.Message、traceFont、selectedStringBrush、xMessage、y);
}
其他的
{
bufferGraphics.DrawString(data.Date、traceFont、stringBrush、xTime、y);
//信息=1,警告=2,错误=3,调试=5,特殊=6
开关(data.LevelString)
{
案例“信息”:
bufferGraphics.DrawString(data.LevelString、traceFont、brushInfo、xLevel、y);
打破
案例“警告”:
bufferGraphics.DrawString(data.LevelString、traceFont、brushWarning、xLevel、y);
打破
案例“错误”:
bufferGraphics.DrawString(data.LevelString、traceFont、brushError、xLevel、y);
打破
案例“调试”:
bufferGraphics.DrawString(data.LevelString、traceFont、brushDebug、xLevel、y);
打破
违约:
打破
}
bufferGraphics.DrawString(data.Source、traceFont、stringBrush、xSource、y);
if(data.Attachment!=null)
{
bufferGraphics.DrawString(“附件:”,traceFont,brushAttachment,xMessage,y);
bufferGraphics.DrawString(data.Message,traceFont,stringBrush,xMessage+(xMessage/5),y);
}
其他的
bufferGraphics.DrawString(data.Message、traceFont、stringBrush、xMessage、y);
}
bufferGraphics.DrawRectangle(Pens.LightGray,rect);
//
//如果(数据已选定)
// {