I am trying to create a program that is able to analyze DNA data and visualize the differences compared to a reference sequence of DNA. This involves a big number of letters that I want drawn on a Panel with each base (A, C, G, T) having a different background color. So horizontal lines would represent a single line of DNA.
Up to now I have this as a test :
Creating the bitmap
Bitmap bit;
public Form1()
{
InitializeComponent();
bit = new Bitmap(15, 15);
Graphics g = Graphics.FromImage(bit);
g.FillRectangle(new SolidBrush(Color.Red), new Rectangle(1, 1, 13, 13));
g.Dispose();
}
And this is the Onpaint handler of the Panel i am drawing on:
private void p_Paint(object sender, PaintEventArgs e)
{
int x_Start = e.ClipRectangle.X;
int x_Length = e.ClipRectangle.Width;
int y_Start = e.ClipRectangle.Y;
int y_Length = e.ClipRectangle.Height;
Bitmap insb = new Bitmap(RoundUp(x_Length), RoundUp(y_Length));
Panel p = (Panel)sender;
Graphics g = p.CreateGraphics();
Graphics bmp = Graphics.FromImage(insb);
for (int y = 0; y < insb.Height; y += 15)
{
for (int x = 0; x < insb.Width; x += 15)
{
bmp.DrawImage(bit, x, y);
}
}
g.DrawImage(insb, x_Start, y_Start);
bmp.Dispose();
g.Dispose();
}
This creates a grid of squares but when I scroll this it flickers like crazy...
I have set the Doublebuffered property of the Panel to true like this :
typeof(Panel).InvokeMember("DoubleBuffered",
BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
null, listHolder.Controls[0], new object[] { true });
And this made a slight improvement but it is still far from where I want it to be. What am i doing wrong? (Also this is my first post so be gentle please ;))