Setup for Chessboard:
I have a new Windows Applicaiton in VS 2005 using C#. Then I added a user control to the project and placed it on the form. On this control, I want to draw a grid that resizes. What triggers the paint event for the control? There is presently no code in the form.cs file. The following code is in the user control: (some lines are commented out while I am working on parts but I can see in debug that this event is not being fired. I welcome any help on this code and the trigger for it)
using System;
using System.Collections.Generic
;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace Chess
{
public partial class GamePanel : UserControl
{
public GamePanel()
{
InitializeComponent();
// bit flag enum
this.SetStyle(ControlStyle
s.AllPaint
ingInWmPai
nt |
ControlStyles.UserPaint |
ControlStyles.DoubleBuffer
|
ControlStyles.ResizeRedraw
, true);
}
private void GamePanel_Load(object sender, EventArgs e)
{
}
private void GamePanel_Paint(object sender, PaintEventArgs e)
{
// string alignment -- center.
//StringFormat sf = new StringFormat();
//sf.Alignment = StringAlignment.Center;
//sf.LineAlignment = StringAlignment.Center;
//Pen black = new Pen(Color.Black);
// this.ClientRectangle;
e.Graphics.DrawLine(Pens.B
lack,0, 15, 150, 15); // test drawing a line
// anchor control
// this.ClientRectangle.Right
;
// this.ClientRectangle.Botto
m;
// draw grid
float rowHt = this.ClientRectangle.Heigh
t/9;
for (int row = 1; row < 9; row ++){
Rectangle r = new Rectangle(0, (int)(row * rowHt),
this.ClientRectangle.Width
,(int)rowH
t);
e.Graphics.DrawLine(Pens.B
lack, 0f, rowHt * rowHt, (float)this.ClientRectangl
e.Width, rowHt * row);
}
// Brush base = new SolidBrush Brush(Color, Fromargb(12, 240, 210, 0);
// e.Graphics.DrawString("TES
T TEXT", thisFont, Graphics, 100, 100);
}
private void GamePanel_MouseDown(object
sender, MouseEventArgs e)
{
}
private void GamePanel_MouseUp(object sender, MouseEventArgs e)
{
}
}
}
Start Free Trial