-
26334980 said 1 year ago:
debug my programme, it’s norml, as the second picture(untitled-1.png),
but, after mouse scroll, it changed like the first picture(untitled-2.png),
the lines seem not to be changed in real-time with the mouse scrolling or sliding the scrollbar,
what’s wrong with my code,how to modify it///////////////////////////////My Code//////////////////////////////////////////
private void Form1_Load(object sender, EventArgs e)
{
_flex.Cols.Count = 6;
_flex.Rows.Count = 31;
_flex.Cols.DefaultSize = 30;
_flex.Rows.DefaultSize = 30;
_flex.Styles.Normal.TextAlign = TextAlignEnum.CenterCenter;
_flex.Cols[0].Width = 30;
for (int i = 1; i < _flex.Rows.Count; i++)
{
_flex.SetData(i, 0, i);
}
_flex[1, 1] = 0;
_flex[2, 3] = 0;
_flex[3, 2] = 0;
_flex[4, 2] = 0;
_flex[5, 5] = 0;
_flex[6, 1] = 0;
_flex[7, 4] = 0;
_flex[8, 2] = 0;
_flex[9, 3] = 0;
_flex[10, 1] = 0;
_flex[11, 1] = 0;
_flex[12, 3] = 0;
_flex[13, 2] = 0;
_flex[14, 2] = 0;
_flex[15, 5] = 0;
_flex[16, 1] = 0;
_flex[17, 4] = 0;
_flex[18, 2] = 0;
_flex[19, 3] = 0;
_flex[20, 1] = 0;
_flex[21, 1] = 0;
_flex[22, 3] = 0;
_flex[23, 2] = 0;
_flex[24, 2] = 0;
_flex[25, 5] = 0;
_flex[26, 1] = 0;
_flex[27, 4] = 0;
_flex[28, 2] = 0;
_flex[29, 3] = 0;
_flex[30, 1] = 0;
this._flex.Paint += new PaintEventHandler(_flex_Paint);
}void _flex_Paint(object sender, PaintEventArgs e)
{
//const int DefaultColWidth = 30;
//const int DefaultRowHeight = 30;
int x1 = 0;
int y1 = 0;
int x2 = 0;
int y2 = 0;System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
System.Drawing.Graphics formGraphics = e.Graphics;for (int i = 1; i < _flex.Rows.Count – 1; i++)
{
for (int j = 1; j < _flex.Cols.Count; j++)
{
var v = _flex;
if (v != null && v.ToString() == "0″)
{
x1 = _flex.Cols[j].Left + DefaultColWidth / 2;
break;
}
}for (int j = 0; j < _flex.Cols.Count; j++)
{
var v = _flex;
if (v != null && v.ToString() == "0″)
{
x2 = _flex.Cols[j].Left + DefaultColWidth / 2;
break;
}
}y1 = _flex.Rows.Top + DefaultRowHeight / 2;
y2 = _flex.Rows.Top + DefaultRowHeight / 2;formGraphics.DrawLine(myPen, x1, y1, x2, y2);
}
}
}Attachments:
You must be logged in to view attched files.| #Hello,
This behaviour is observed because you are creating the custom line in the paint event and when scrolling is done, then custom line remains at its position while the grid data is changed due to scrolling.
Therefore, I would suggest you to use OwnerDrawCell event of the flexgrid as described by our engineer on the following link:
Regards
AshishAnswer| #Viewing 2 posts - 1 through 2 (of 2 total)You must be logged in to reply to this topic.

