post #1 of 1
Thread Starter 
Ok, 2hrs of googling gave no result, so here I am again, asking.

I have a panel shaped like a separator (n pixels wide, 2 pixels high).
I move this panel vertically with the mouse at runtime.

Underneath the panel I have a drawing, made with GraphicPath, filled with blue, extending from left to right as new lines are added.
Whenever the control moves, it leaves a trail of gray color over the image, which stays there until I manually re-fill the path.

The path uses antialiasing.
If I re-fill the path in the move event of the control, the transparent pixels of the antialiased image overlap, losing transparency, therefore losing the antialiasing effect.

If I clear the old image, so the new one retains antialiasing, I get flickering.
What to do?

Here are some screenshots:




EDIT:
Here's the solution:

Draw your graphic to an Bitmap object instead to a control, then set the bitmap as Image or BackgroundImage of the control.
Some code:
Code:
private Bitmap bmp;
private System.Drawing.Drawing2D.GraphicsPath path;
private System.Drawing.Graphics gImage;

...

public MyClass()
        {
            bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            gImage = Graphics.FromImage(bmp);
            gImage.SmoothingMode = SmoothingMode.AntiAlias;
        }

...

public void SomeMethod()
        {
                path = new System.Drawing.Drawing2D.GraphicsPath();
                    path.AddLine(myLine);
                    path.AddLine(myOtherLine);
                    path.AddLine(myWifesLine);

                gImage.FillPath(Brushes.Blue, path);
                pictureBox1.Image = bmp;
                pictureBox1.Refresh();
        }

And you get your drawing in your PictureBox. Now, you can place and move freely any controls over it, and it won't overwrite the image.
And of course, double-buffer your form if you'll be moving any controls.
Edited by ronnin426850 - 3/5/13 at 7:15am
My Rig
(14 items)
 
Ex-wife's Rig
(15 items)
 
 
CPUMotherboardGraphicsRAM
Core i5 4460 AsRock H81M-DG4 Sapphire Rx470 Platinum KVR 1600 16Gb 
Hard DriveHard DriveCoolingOS
2x Seagate 3Tb Samsung 850 EVO 120 Scythe Ninja 3 Rev.B Windows 10 Pro 
MonitorKeyboardPowerCase
Fujitsu Siemens A17-2A Logitech K280e SuperFlower SF-550K12XP Thermaltake Versa H25 
MouseAudio
Logitech G402 Sony MDR XD150 
CPUMotherboardGraphicsRAM
Athlon 750K 4.0Ghz AsRock FM2A75 Pro4+ Sapphire R9 270X Dual-X Kingston 2x4Gb 1600 
Hard DriveHard DriveOptical DriveCooling
Samsung 850 EVO 120  Western Digital 320Gb LiteON DVD-RW CoolerMaster Hyper Z600 
OSMonitorKeyboardPower
Windows 7 Pro x64 Toshiba 32" FullHD TV Logitech FSP Hexa 550 
CaseMouse
DeLUX Logitech 
  hide details  
Reply
My Rig
(14 items)
 
Ex-wife's Rig
(15 items)
 
 
CPUMotherboardGraphicsRAM
Core i5 4460 AsRock H81M-DG4 Sapphire Rx470 Platinum KVR 1600 16Gb 
Hard DriveHard DriveCoolingOS
2x Seagate 3Tb Samsung 850 EVO 120 Scythe Ninja 3 Rev.B Windows 10 Pro 
MonitorKeyboardPowerCase
Fujitsu Siemens A17-2A Logitech K280e SuperFlower SF-550K12XP Thermaltake Versa H25 
MouseAudio
Logitech G402 Sony MDR XD150 
CPUMotherboardGraphicsRAM
Athlon 750K 4.0Ghz AsRock FM2A75 Pro4+ Sapphire R9 270X Dual-X Kingston 2x4Gb 1600 
Hard DriveHard DriveOptical DriveCooling
Samsung 850 EVO 120  Western Digital 320Gb LiteON DVD-RW CoolerMaster Hyper Z600 
OSMonitorKeyboardPower
Windows 7 Pro x64 Toshiba 32" FullHD TV Logitech FSP Hexa 550 
CaseMouse
DeLUX Logitech 
  hide details  
Reply