Advertisement
| Hall of Fame |
|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: |
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace gridCustomControl
{
public partial class GridCustomControl : UserControl
{
private int _cols;
private int _rows;
private int _width; // Cell width
private int _height; // Cell height
private float _zoom;
private Color _cellColor;
private Color _borderColor;
public GridCustomControl()
{
InitializeComponent();
// The following SetStyles are needed for double buffering:
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
_cols = Cols;
_rows = Rows;
_width = CellWidth;
_height = CellHeight;
_cellColor = CellColor;
_borderColor = BorderColor;
this.ControlSize = new Size(_width * _cols, _height * _rows);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.FillRectangle(Brushes.White, this.ClientRectangle);
int cellHeight = this.CellHeight;
int cellWidth = this.CellWidth;
int nbrColumns = this.Cols;
int nbrRows = this.Rows;
// Draw cells
for (int row = 0; row < nbrRows; row++)
{
for (int col = 0; col < nbrColumns; col++)
{
Point cellLocation = new Point(col * cellWidth, row * cellHeight);
Rectangle cellRect = new Rectangle(cellLocation.X,
cellLocation.Y,
cellWidth, cellHeight);
if (cellRect.IntersectsWith(e.ClipRectangle))
{
g.FillRectangle(new SolidBrush(_cellColor), cellRect);
g.DrawRectangle(new Pen(_borderColor, 1), cellRect);
}
else
{
// Do nothing...
}
}
}
this.Invalidate(); // Redraw the whole control
}
[Browsable(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public int Cols
{
get { return _cols; }
set { _cols = value; }
}
public int Rows
{
get { return _rows; }
set { _rows = value; }
}
public int CellWidth
{
get { return _width; }
set { _width = value; }
}
public int CellHeight
{
get { return _height; }
set { _height = value; }
}
public float Zoom
{
get { return _zoom; }
set { _zoom = value; }
}
public Size ControlSize
{
// This property references the 'this' because there
// aren't any private members that need to be created
// to hold the size value.
get { return this.Size; }
set
{
_width = value.Width;
_height = value.Height;
// 1 is added otherwize the most very most right line and
// the very most bottom line will not show.
this.Size = new Size(_width * _cols + 1, _height * _rows + 1);
this.Invalidate(); // Redraw the whole control
}
}
public Color CellColor
{
get { return _cellColor; }
set { _cellColor = value; }
}
public Color BorderColor
{
get { return _borderColor; }
set { _borderColor = value; }
}
}
}
|