Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Sibeesh VenuRank #27 · 42.9K reputationPosted Jan 19, 2015, 6:19 PM EST
Public Class Form1 Private m_countFont As New Font("Tahoma", 10) Private m_displayFont As New Font("Cambria", 120) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.ConfigureBoard() End Sub Private m_board(2, 2) As Play Private m_isXPlayer As Boolean = False Private m_count As Integer = 0 Private Sub ConfigureBoard() Me.dgv.ColumnHeadersVisible = False Me.dgv.RowHeadersVisible = False Me.dgv.RowTemplate.Height = Me.dgv.Height / 3 Me.dgv.RowCount = 3 Me.dgv.ColumnCount = 3 Me.dgv.Columns(0).Width = Me.dgv.Width / 3 Me.dgv.Columns(1).Width = Me.dgv.Width / 3 Me.dgv.Columns(2).Width = Me.dgv.Width / 3 Me.dgv.ScrollBars = ScrollBars.None Me.dgv.EditMode = DataGridViewEditMode.EditProgrammatically AddHandler Me.dgv.CellPainting, AddressOf OnPaintCell AddHandler Me.dgv.CellMouseDown, AddressOf OnCellMouseDown End Sub Private Sub OnPaintCell(ByVal sender As Object, ByVal e As DataGridViewCellPaintingEventArgs) Dim play As Play = m_board(e.RowIndex, e.ColumnIndex) If play IsNot Nothing Then Dim countRect As New Rectangle(e.CellBounds.Left, e.CellBounds.Bottom - m_countFont.Height - 10, e.CellBounds.Width, m_countFont.Height) Dim format As New StringFormat() format.LineAlignment = StringAlignment.Center format.Alignment = StringAlignment.Center e.Graphics.DrawString(play.Count, m_countFont, Brushes.Red, countRect, format) Dim displayRect = New Rectangle(e.CellBounds.Left, e.CellBounds.Top, e.CellBounds.Width, e.CellBounds.Height - m_countFont.Height) e.Graphics.DrawString(IIf(play.IsX, "X", "O"), m_displayFont, Brushes.SteelBlue, displayRect, format) e.Handled = True End If End Sub Private Sub OnCellMouseDown(ByVal sender As Object, ByVal e As DataGridViewCellMouseEventArgs) If e.Button = Windows.Forms.MouseButtons.Left Then m_isXPlayer = Not m_isXPlayer ' What there a play for the current cell. If m_board(e.RowIndex, e.ColumnIndex) Is Nothing Then m_count += 1 m_board(e.RowIndex, e.ColumnIndex) = New Play(m_count, m_isXPlayer) Me.dgv.Invalidate() End If End If End Sub Private Class Play Public Count As Integer Public IsX As Boolean Public Sub New(ByVal currentCount As Integer, ByVal currentPlayerX As Boolean) Count = currentCount IsX = currentPlayerX End Sub End Class End ClassRead more
http://www.experts-exchange.com/Programming/Languages/.NET/Q_24198256.html
Please accept and up vote if it helped you.
Kindest Regards
Sibeesh
http://sibeeshpassion.com/
Chinna NethaRank #5,573 · 294 reputationPosted Jan 19, 2015, 11:36 PM EST
i want c# code
plz help me sir...
Sibeesh VenuRank #27 · 42.9K reputationPosted Jan 20, 2015, 7:24 AM EST
Please refer
http://converter.telerik.com/
http://www.developerfusion.com/tools/convert/vb-to-csharp/
Please accept and up vote if it helped you.
Kindest Regards
Sibeesh
http://sibeeshpassion.com/