I want to draw a polygon filled with LinearGradientBrush. This works fine in static mode.
Now I want to make its right edge follow my mouse movement.
I use the following code:
using System.Runtime.InteropServices; // for LockWindowUpdate
[DllImport("user32.dll", EntryPoint = "LockWindowUpdate")]
static extern Int32 LockWindowUpdate(Int32 hwndLock);
public int MouseX = 0;
private void uxButtonPanel_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
Graphics g = e.Graphics;
Point PolyPoints = new Point;
PolyPoints = new Point(0,0);
PolyPoints = new Point(MouseX,0);
PolyPoints = new Point(MouseX,130);
PolyPoints = new Point(0,80);
LinearGradientBrush myBrush = new LinearGradientBrush(new Point(0,0), new Point(MouseX,0), Color.Green,Color.Blue);
private void uxButtonPanel_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
//SetStyle( ControlStyles.UserPaint, true );
//SetStyle( ControlStyles.AllPaintingInWmPaint, true );
//SetStyle( ControlStyles.DoubleBuffer, true );
MouseX = Cursor.Position.X;
I am not sure what is the best strategy to handle the events in the right sequence and when to lock which window so that everything works perfectly smooth.
I am also not sure, if I need double buffering and if I do so, where to place the lines of code..
Thank you very much for helping in advance!