How do I make the snake move in all directions continuosly without having to press the buttons always
public partial class Form1 : Form
{
Rectangle rectangle;
Size recSize;
Point firstPoint;
Point[,] grid;
Graphics graphics;
Point[] snake;
Random rng;
Pen pen;
int width = 0;
int height = 0;
public Form1()
{
InitializeComponent();
firstPoint = new Point(0, 0);
recSize = new Size(this.ClientSize.Width, this.ClientSize.Height);
rectangle = new Rectangle(firstPoint, recSize);
graphics = this.CreateGraphics();
width = rectangle.Width;
height = rectangle.Height;
grid = new Point[width/4, height/4];
snake = new Point[400];
rng = new Random();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
pen = new Pen(new SolidBrush(Color.Green));
//e.Graphics.DrawRectangle(pen, rectangle);
e.Graphics.FillRectangle(new SolidBrush(Color.Green), rectangle);
}
private void GameButton_Click(object sender, EventArgs e)
{
for (int i = 0; i < width / 4; i++)
{
for (int j = 0; j < height / 4; j++)
{
grid[i, j] = new Point();
grid[i, j].X = firstPoint.X + (i * 4);
grid[i, j].Y = firstPoint.Y + (j * 4);
graphics.DrawEllipse(new Pen(new SolidBrush(Color.FromArgb(255, 0,0,0))), new Rectangle(grid[i, j], new Size(2, 2)));
}
}
snake[0] = new Point();
snake[0] = grid[width /4/ 2 , height /4/ 2 ];
graphics.DrawEllipse(new Pen(new SolidBrush(Color.Black)), new Rectangle(snake[0], new Size(4, 4)));
graphics.FillEllipse(new SolidBrush(Color.Black), new Rectangle(snake[0], new Size(4, 4)));
}
private void moveSnake(KeyEventArgs e)
{
switch (e.KeyData)
{
case Keys.Up:
this.graphics.Clear(Color.Green);
snake[0].Y -= 4;
graphics.DrawEllipse(new Pen(new SolidBrush(Color.Black)), new Rectangle(snake[0], new Size(4, 4)));
graphics.FillEllipse(new SolidBrush(Color.Black), new Rectangle(snake[0], new Size(4, 4)));
graphics.Flush();
this.Invalidate();
System.Threading.Thread.Sleep(500);
// this.Refresh();
//moveSnake(e);
break;
case Keys.Down:
this.graphics.Clear(Color.Green);
snake[0].Y += 4;
graphics.DrawEllipse(new Pen(new SolidBrush(Color.Black)), new Rectangle(snake[0], new Size(4, 4)));
graphics.FillEllipse(new SolidBrush(Color.Black), new Rectangle(snake[0], new Size(4, 4)));
this.Invalidate();
System.Threading.Thread.Sleep(500);
//this.Refresh();
break;
case Keys.Left:
this.graphics.Clear(Color.Green);
snake[0].X -= 4;
graphics.DrawEllipse(new Pen(new SolidBrush(Color.Black)), new Rectangle(snake[0], new Size(4, 4)));
graphics.FillEllipse(new SolidBrush(Color.Black), new Rectangle(snake[0], new Size(4, 4)));
this.Invalidate();
System.Threading.Thread.Sleep(500);
//this.Refresh();
break;
case Keys.Right:
this.graphics.Clear(Color.Green);
snake[0].X += 4;
graphics.DrawEllipse(new Pen(new SolidBrush(Color.Black)), new Rectangle(snake[0], new Size(4, 4)));
graphics.FillEllipse(new SolidBrush(Color.Black), new Rectangle(snake[0], new Size(4, 4)));
this.Invalidate();
System.Threading.Thread.Sleep(500);
//this.Refresh();
break;
}
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
moveSnake(e);
this.Refresh();
}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
MessageBox.Show(e.KeyChar.ToString());
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress(e);
MessageBox.Show(e.KeyChar.ToString());
}
}
you need a timer on the form and for every tick move in last direction one square.
With this you can speed up the snake a higher difficulty.
Instead of having Form1_KeyDown processing the keystroke immediately using moveSnake, store the keystroke value in a form level variable then process it with moveSnake using a timer.
Also get rid with the System.Threading.Thread.Sleep(500); in the moveSnake
Related
I have tried using the following code:
pictureBox1.Invalidate();
//or
pictureBox1.Update();
//or
Refresh();
But it just did nothing on it. I want to clear all the drawn graphics on my picture box as after I click the next page I want to draw the new rectangles on it. So, please don't provide me such a solution:
g.FillRectangle(Brushes.Black, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height))
or
Graphics.Clear();
Anyone want to share the solution with me? I am appreciated with it.
page 2
page 3
Form2.cs
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Pen pen = new Pen(Color.Red, 2);
e.Graphics.DrawRectangle(pen, rect);
}
bool draw;
int x_start, y_start;
Rectangle rect;
//UserRect rect;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
}
else if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
pictureBox1.Cursor = Cursors.Cross;
draw = true;
x_start = e.X;
y_start = e.Y;
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
}else if(e.Button == MouseButtons.Right)
{
pictureBox1.Cursor = Cursors.Cross;
}
if (!draw) return;
LocalMousePosition = pictureBox1.PointToClient(Cursor.Position);
int x = Math.Min(x_start, LocalMousePosition.X);
int y = Math.Min(y_start, LocalMousePosition.Y);
int width = Math.Max(x_start, LocalMousePosition.X) - Math.Min(x_start, LocalMousePosition.X);
int height = Math.Max(y_start, LocalMousePosition.Y) - Math.Min(y_start, LocalMousePosition.Y);
rect = new Rectangle(x, y, width, height);
xx = x;
yy = y;
ww = width;
hh = height;
Refresh();
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
//pictureBox1.Cursor = Cursors.Default;
draw = false;
rectang = new UserRect(rect);
rect = new Rectangle(e.X, e.Y, 0, 0);
rectang.SetPictureBox(this.pictureBox1);
}
else if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
pictureBox1.Cursor = Cursors.Default;
_tracking = false;
}
}
UserRect.cs
public void Draw(Graphics g)
{
g.DrawRectangle(new Pen(Color.Green), rect);
foreach (PosSizableRect pos in Enum.GetValues(typeof(PosSizableRect)))
{
g.DrawRectangle(new Pen(Color.Red), GetRect(pos));
}
}
public void SetPictureBox(PictureBox p)
{
this.mPictureBox = p;
mPictureBox.MouseDown += new MouseEventHandler(mPictureBox_MouseDown);
mPictureBox.MouseUp += new MouseEventHandler(mPictureBox_MouseUp);
mPictureBox.MouseMove += new MouseEventHandler(mPictureBox_MouseMove);
mPictureBox.Paint += new PaintEventHandler(mPictureBox_Paint);
}
private void mPictureBox_Paint(object sender, PaintEventArgs e)
{
try
{
Draw(e.Graphics);
}
catch (Exception exp)
{
System.Console.WriteLine(exp.Message);
}
}
private void mPictureBox_MouseDown(object sender, MouseEventArgs e)
{
mIsClick = true;
nodeSelected = PosSizableRect.None;
nodeSelected = GetNodeSelectable(e.Location);
if (rect.Contains(new Point(e.X, e.Y)))
{
mMove = true;
}
oldX = e.X;
oldY = e.Y;
}
private void mPictureBox_MouseUp(object sender, MouseEventArgs e)
{
//MessageBox.Show(rect.ToString());
mIsClick = false;
mMove = false;
}
private void mPictureBox_MouseMove(object sender, MouseEventArgs e)
{
ChangeCursor(e.Location);
if (mIsClick == false)
{
return;
}
Rectangle backupRect = rect;
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
switch (nodeSelected)
{
case PosSizableRect.LeftUp:
rect.X += e.X - oldX;
rect.Width -= e.X - oldX;
rect.Y += e.Y - oldY;
rect.Height -= e.Y - oldY;
break;
case PosSizableRect.LeftMiddle:
rect.X += e.X - oldX;
rect.Width -= e.X - oldX;
break;
case PosSizableRect.LeftBottom:
rect.Width -= e.X - oldX;
rect.X += e.X - oldX;
rect.Height += e.Y - oldY;
break;
case PosSizableRect.BottomMiddle:
rect.Height += e.Y - oldY;
break;
case PosSizableRect.RightUp:
rect.Width += e.X - oldX;
rect.Y += e.Y - oldY;
rect.Height -= e.Y - oldY;
break;
case PosSizableRect.RightBottom:
rect.Width += e.X - oldX;
rect.Height += e.Y - oldY;
break;
case PosSizableRect.RightMiddle:
rect.Width += e.X - oldX;
break;
case PosSizableRect.UpMiddle:
rect.Y += e.Y - oldY;
rect.Height -= e.Y - oldY;
break;
default:
if (mMove)
{
rect.X = rect.X + e.X - oldX;
rect.Y = rect.Y + e.Y - oldY;
}
break;
}
}
oldX = e.X;
oldY = e.Y;
if (rect.Width < 5 || rect.Height < 5)
{
rect = backupRect;
}
TestIfRectInsideArea();
mPictureBox.Invalidate();
}
Generally, I would split drawing graphics between _Paint event as you have it (for interactive drawing, such as selection box and mouse-move related stuff) and separate underlaying image.
There are several reasons for that, such as control over what you want to draw (imagine you want to draw only retangle 1, 3 and 5, if a some checkbox is not checked and then draw all of 1 to 6 if it is checked) and performance (with large amount of data).
You can do all of that in _Paint, but it will bloat. In contrast to that, you can split draw task into several functions, which is very handy for large drawing.
Very simplified example - VB.NET:
Dim UnderlayingImage as Image
UnderLayingImage = New Bitmap(Me.PictureBox1.Width, Me.Picturebox1.Height)
Dim g As Graphics = Graphics.FromImage(UnderLayingImage)
Dim bgBrush As SolidBrush = New SolidBrush(Color.LightSlateGray)
Dim bgBrushWhite As SolidBrush = New SolidBrush(Color.White)
Dim shPen As Pen = New Pen(Color.Black)
Dim rect As RectangleF = New RectangleF(50, 50, 100, 100)
g.FillRectangle(bgBrush, rect)
g.DrawRectangle(Pens.Black, Rectangle.Round(rect))
Me.PictureBoxDrawing.Image = UnderLayingImage
Translated to C#:
Image UnderlayingImage;
UnderLayingImage = new Bitmap(this.PictureBox1.Width, this.Picturebox1.Height);
Graphics g = Graphics.FromImage(UnderLayingImage);
SolidBrush bgBrush = new SolidBrush(Color.LightSlateGray);
SolidBrush bgBrushWhite = new SolidBrush(Color.White);
Pen shPen = new Pen(Color.Black);
RectangleF rect = new RectangleF(50, 50, 100, 100);
g.FillRectangle(bgBrush, rect);
g.DrawRectangle(Pens.Black, Rectangle.Round(rect));
this.PictureBoxDrawing.Image = UnderLayingImage;
And back to your question: This way you don't Clear your drawing, but you redraw it and in the process you decide what to include and what to ommit.
I am having problems creating a protected variable that can be access and updated by an external method.
In other words, I have got a print method that prints multiple pages.
I needs an external variable to initialize this method and keep track of the pages.
Is it possible someone could get me started in coding this class? as I knowledge on OOP is limited
Below is the print method
Thanks in advance
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics graphics = e.Graphics;
int ypos = 78;
Font f1 = new Font("Arial", 14, FontStyle.Bold, GraphicsUnit.Pixel);
Brush brush = new SolidBrush(Color.LightSlateGray);
graphics.FillRectangle(brush, new Rectangle(10, 10, 770, 50));
Pen blackpen = new Pen(Color.Black);
Pen graypen = new Pen(Color.LightGray);
Pen redpen = new Pen(Color.Red);
graphics.DrawRectangle(blackpen, new Rectangle(10, 10, 770, 50));
Brush B = new SolidBrush(listView1.ForeColor);
graphics.DrawLine(blackpen, 10, 10, 10, 1132);
graphics.DrawString("FORENAME", f1, Brushes.Black, new Point(20, 25));
graphics.DrawLine(blackpen, 130, 10, 130, 1132);
graphics.DrawString("SURNAME", f1, Brushes.Black, new Point(140, 25));
graphics.DrawLine(blackpen, 290, 10, 290, 1132);
graphics.DrawString("EXT.", f1, Brushes.Black, new Point(300, 25));
graphics.DrawLine(blackpen, 380, 10, 380, 1132);
graphics.DrawString("JOB TITLE", f1, Brushes.Black, new Point(410, 25));
graphics.DrawLine(blackpen, 780, 10, 780, 1132);
int[] X = { 15, 140, 300, 390, 720 };
int Y = 60;
f1 = listView1.Font;
for (int I = 0; I < listView1.Items.Count; I++){
for (int J = 0; J < listView1.Items[I].SubItems.Count - 1; J++){
graphics.DrawString(listView1.Items[I].SubItems[J].Text, f1, B, X[J], Y);
}
}
Y += f1.Height;
graphics.DrawLine(graypen, 10, ypos, 780, ypos);
ypos = ypos + 17;
if (ypos > 1132){
e.HasMorePages = true;
return;
}
graphics.Dispose();
}
Try below function, and call print event
public void PrintDocument()
{
try
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler
(this.printDocument1_PrintPage);
pd.Print();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Why after drawing circles their colors change? , in fact, I draw circles but my problem is that after every time double click, the color of next circles change from blue to the background color.
public Form1()
{
InitializeComponent();
pictureBox1.Paint += new PaintEventHandler(pic_Paint);
}
public Point positionCursor { get; set; }
private List<Point> points = new List<Point>();
public int circleNumber { get; set; }
private void pictureBox1_DoubleClick(object sender, EventArgs e)
{
positionCursor = this.PointToClient(new Point(Cursor.Position.X - 25, Cursor.Position.Y - 25));
points.Add(positionCursor);
pictureBox1.Invalidate();
}
private void pic_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
foreach (Point pt in points)
{
Pen p = new Pen(Color.Tomato, 2);
g.FillEllipse(Brushes.Blue, positionCursor.X, positionCursor.Y, 20, 20);
g.DrawEllipse(p, pt.X, pt.Y, 20, 20);
p.Dispose();
}
}
You're drawing the ellipses correctly, but you always fill only one of them (the last one added, at the cursor's position).
// This is ok
g.DrawEllipse(p, pt.X, pt.Y, 20, 20);
// You should use pt.X and pt.Y here
g.FillEllipse(Brushes.Blue, positionCursor.X, positionCursor.Y, 20, 20);
change pic_Paint as below
private void pic_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
foreach (Point pt in points)
{
Pen p = new Pen(Color.Tomato, 2);
g.DrawEllipse(p, pt.X, pt.Y, 20, 20);
g.FillEllipse(Brushes.Blue, pt.X, pt.Y, 20, 20);
p.Dispose();
}
}
Recently, I have been working on this graphing system in C#, and I am having problems with the coordinate system. As we all know, C# uses the top left corner as 0,0 coordinates. What I want to accomplish is to make 0 in the middle of the windows form.
Currently, this is what I have...
As you can see, 0,0 is on the top left, making the center of the graph 400. So is there a way to transform the coordinates into a proper mathematical graph coordinate?
I hope I was able to explain this situation well as my English is not very well.
public partial class Form1 : Form
{
public static int _wWidth;
public static int _wHeight;
int mouseX, mouseY;
Point _center = new Point(_wWidth / 2, _wHeight / 2);
public Form1()
{
InitializeComponent();
foreach (Control c in this.Controls)
{
c.MouseDown += ShowMouseDown;
}
this.MouseDown += (s, e) => { this.label3.Text = "{X: " + e.X + " Y:" + e.Y + "}"; mouseX = e.X; mouseY = e.Y; };
}
private void ShowMouseDown(object sender, MouseEventArgs e)
{
var x = e.X + ((Control)sender).Left;
var y = e.Y + ((Control)sender).Top;
this.label3.Text = x + " " + y;
}
public void Form1_Load(object sender, EventArgs e)
{
this.ClientSize = new Size(800, 800);
int windowWidth = this.ClientSize.Width;
int windowHeight = this.ClientSize.Height;
_wWidth = windowWidth;
_wHeight = windowHeight;
button1.Location = new Point(_wWidth - button1.Width,0);
//AllocConsole(); /***** Enable console for debugging *****/
}
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AllocConsole();
public void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
_drawPlain(e);
}
public void _drawPlain(PaintEventArgs e){
Graphics formGraphics = this.CreateGraphics();
for(int x = 0; x < _wHeight; x+=50)
{
e.Graphics.DrawLine(new Pen(Color.FromArgb(80, 75, 75)), new Point(0, x), new Point(_wWidth, x));
Console.ForegroundColor = ConsoleColor.Green; if (x == 20) { Console.Write("X - "); } Console.WriteLine(x);
e.Graphics.DrawString(x.ToString(), new Font("Arial", 10), new SolidBrush(Color.White), new Point(_wWidth/2,x));
}
for (int y = 0; y < _wWidth; y += 50)
{
e.Graphics.DrawLine(new Pen(Color.FromArgb(80, 75, 75)), new Point(y, 0), new Point(y, _wHeight));
Console.ForegroundColor = ConsoleColor.Red; if (y == 20) { Console.Write("Y - "); } Console.WriteLine(y);
int num = y;
e.Graphics.DrawString(num.ToString(), new Font("Arial", 10), new SolidBrush(Color.White), new Point(y, _wHeight/2));
}
e.Graphics.DrawLine(Pens.Green, new Point(0, _wHeight/2), new Point(_wWidth, _wHeight/2));
e.Graphics.DrawLine(Pens.DarkRed, new Point(_wWidth/2, 0), new Point(_wWidth/2, _wHeight));
//e.Graphics.DrawString("0", new Font("Arial", 10), new SolidBrush(Color.White), new Point(_wWidth / 2, _wHeight / 2));
//// Create pen.
//Pen blackPen = new Pen(Color.Black, 3);
//// Create points that define polygon.
//Point point1 = new Point(100, 200);
//Point point2 = new Point(300, 200);
//Point point3 = new Point(200, 50);
//Point[] curvePoints =
// {
// point1,
// point2,
// point3
// };
//// Draw polygon to screen.
//e.Graphics.DrawPolygon(blackPen, curvePoints);
}
public static int _yCellCount()
{
int _cell = 0;
for (int i = 0; i < 20; i++)
{
_cell++;
}
return _cell;
}
private void button1_Click(object sender, EventArgs e)
{
this.Refresh();
}
private void Form1_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
g.SmoothingMode = SmoothingMode.AntiAlias;
g.DrawLine(Pens.Yellow,new Point(mouseX,mouseY),new Point(_wWidth/2,400));
}
}
I have painted the datagridview column header and called the repaint event in the scroll event ,but it does not seems to repaint properly . The text in the painted rectangle gets scettered ( see the second image)
here is my code,
void dataGridView1_Scroll(object sender, ScrollEventArgs e)
{
Rectangle rtHeader = this.dataGridView1.DisplayRectangle;
rtHeader.Y += 0;
rtHeader.Height = this.dataGridView1.ColumnHeadersHeight;
}
Rectangle r1;
void dataGridView1_Paint(object sender, PaintEventArgs e)
{
string[] monthes = { "APPLE", "MANGO", "CHERRY", "GRAPES", "PINEAPPLE" };
for (int j = 0; j < this.dataGridView1.ColumnCount; )
{
r1 = this.dataGridView1.GetCellDisplayRectangle(j, -1, true);
int w2 = this.dataGridView1.GetCellDisplayRectangle(j + 1, -1, true).Width;
r1.X += -2;
r1.Y += 30;
r1.Width = r1.Width + w2 - 1;
r1.Height = r1.Height / 3 - 2;
e.Graphics.FillRectangle(new SolidBrush(this.dataGridView1.ColumnHeadersDefaultCellStyle.BackColor), r1);
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
e.Graphics.DrawRectangle(new Pen(Color.Black), r1);
e.Graphics.DrawString(monthes[j / 2], this.dataGridView1.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(this.dataGridView1.ColumnHeadersDefaultCellStyle.ForeColor), r1, format);
j += 2;
}
string[] year = { "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY" };
//for (int i = 0; i < this.dataGridView1.ColumnCount; )
//{
Rectangle rec = this.dataGridView1.GetCellDisplayRectangle(0, -1, true);
int wid = this.dataGridView1.GetCellDisplayRectangle(1, -1, true).Width;
rec.X += -2;
rec.Y += 1;
rec.Width = this.dataGridView1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible);
rec.Height = rec.Height / 3 - 2;
e.Graphics.FillRectangle(new SolidBrush(this.dataGridView1.ColumnHeadersDefaultCellStyle.BackColor), rec);
StringFormat frm = new StringFormat();
frm.Alignment = StringAlignment.Center;
frm.LineAlignment = StringAlignment.Center;
e.Graphics.DrawRectangle(new Pen(Color.Black), rec);
e.Graphics.DrawString("Favourite fruits", new Font("Times new roman", 16, FontStyle.Regular), new SolidBrush(Color.CornflowerBlue), rec, frm);
}
private void dataGridView1_Scroll(object sender, ScrollEventArgs e)
{
/*
Rectangle rtHeader = this.dataGridView1.DisplayRectangle;
rtHeader.Y += 0;
rtHeader.Height = this.dataGridView1.ColumnHeadersHeight;
this.dataGridView1.Invalidate(rtHeader);
*/
this.dataGridView1.Invalidate();
}
if (e.RowIndex == -1 && e.ColumnIndex > -1)
{
e.PaintBackground(e.CellBounds, true);
RenderColumnHeader(e.Graphics, e.CellBounds, e.CellBounds.Contains(hotSpot) ? hotSpotColor : backColor);
RenderColumnHeaderBorder(e.Graphics, e.CellBounds, e.ColumnIndex);
using (Brush brush = new SolidBrush(e.CellStyle.ForeColor))
{
using (StringFormat sf = new StringFormat() { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center })
{
e.Graphics.DrawString(e.Value.ToString(), e.CellStyle.Font, brush, e.CellBounds, sf);
}
}
e.Handled = true;
}
}
Color hotSpotColor = Color.LightGreen;//For hover backcolor
Color backColor = Color.MediumSeaGreen; //For backColor
Point hotSpot;
private void RenderColumnHeader(Graphics g, Rectangle headerBounds, Color c)
{
int topHeight = 10;
Rectangle topRect = new Rectangle(headerBounds.Left, headerBounds.Top + 1, headerBounds.Width, topHeight);
RectangleF bottomRect = new RectangleF(headerBounds.Left, headerBounds.Top + 1 + topHeight, headerBounds.Width, headerBounds.Height - topHeight - 4);
Color c1 = Color.FromArgb(180, c);
using (SolidBrush brush = new SolidBrush(c1))
{
g.FillRectangle(brush, topRect);
brush.Color = c;
g.FillRectangle(brush, bottomRect);
}
}
private void RenderColumnHeaderBorder(Graphics g, Rectangle headerBounds, int colIndex)
{
ControlPaint.DrawBorder3D(g, headerBounds, Border3DStyle.Raised, Border3DSide.All & ~Border3DSide.Middle);
}
//MouseMove event handler for your dataGridView1
private void dataGridView1_MouseMove(object sender, MouseEventArgs e)
{
hotSpot = e.Location;
}
//MouseLeave event handler for your dataGridView1
private void dataGridView1_MouseLeave(object sender, EventArgs e)
{
hotSpot = Point.Empty;
}