Click here to Skip to main content
15,902,763 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Embedded OLE objects in VB .NET ? Pin
ramaseb11-Aug-04 6:56
ramaseb11-Aug-04 6:56 
GeneralRe: Embedded OLE objects in VB .NET ? Pin
smritiy11-Aug-04 7:20
smritiy11-Aug-04 7:20 
GeneralFOXPRO TABLES Pin
ramaseb11-Aug-04 6:05
ramaseb11-Aug-04 6:05 
GeneralPlease Help Me Pin
mohan_balal11-Aug-04 5:50
mohan_balal11-Aug-04 5:50 
GeneralRe: Please Help Me Pin
Dave Kreskowiak11-Aug-04 5:53
mveDave Kreskowiak11-Aug-04 5:53 
GeneralRe: Please Help Me Pin
Nick Seng11-Aug-04 15:11
Nick Seng11-Aug-04 15:11 
GeneralRe: Please Help Me Pin
ramaseb11-Aug-04 6:34
ramaseb11-Aug-04 6:34 
Questionis there someone can explain this code? Pin
Lisana11-Aug-04 5:00
Lisana11-Aug-04 5:00 
I have a hard time to understand this file DataGridButtonColumn.vb, is there someone can explain it to me? I really need this code to work. Thank you for all your help!

Option Strict Off
Option Explicit On

Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.IO
Imports System.Reflection
Imports System.Windows.Forms

_
Public Class DataGridButtonColumn
Inherits DataGridTextBoxColumn
Public Event CellButtonClicked As DataGridCellButtonClickEventHandler

Private _buttonFace As Bitmap
Private _buttonFacePressed As Bitmap
Private _columnNum As Integer
Private _pressedRow As Integer


Public Sub New(ByVal colNum As Integer)
_columnNum = colNum
_pressedRow = -1

Try
Dim strm As System.IO.Stream = Me.GetType().Assembly.GetManifestResourceStream("fullbuttonface.bmp")
_buttonFace = New Bitmap(strm)
strm = Me.GetType().Assembly.GetManifestResourceStream("fullbuttonfacepressed.bmp")
_buttonFacePressed = New Bitmap(strm)
Catch
End Try
End Sub

Private Sub DrawButton(ByVal g As Graphics, ByVal bm As Bitmap, ByVal bounds As Rectangle, ByVal row As Integer)

Dim dg As DataGrid = Me.DataGridTableStyle.DataGrid
Dim s As String = dg(row, Me._columnNum).ToString()

Dim sz As SizeF = g.MeasureString(s, dg.Font, bounds.Width - 4, StringFormat.GenericTypographic)

Dim x As Integer = bounds.Left + Math.Max(0, (bounds.Width - sz.Width) / 2)
g.DrawImage(bm, bounds, 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel)

If (sz.Height < bounds.Height) Then

Dim y As Integer = bounds.Top + (bounds.Height - sz.Height) / 2
If (_buttonFacePressed Is bm) Then
x = x + 1
End If
g.DrawString(s, dg.Font, New SolidBrush(dg.ForeColor), x, y)
End If

End Sub

Protected Overloads Overrides Sub Edit(ByVal [source] As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal bounds As System.Drawing.Rectangle, ByVal [readOnly] As Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean)
End Sub 'Edit


Public Sub HandleMouseUp(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim dg As DataGrid = Me.DataGridTableStyle.DataGrid
Dim hti As DataGrid.HitTestInfo = dg.HitTest(New Point(e.X, e.Y))
Dim isClickInCell As Boolean = (hti.Column = Me._columnNum And hti.Row > -1)

_pressedRow = -1

Dim rect As New Rectangle(0, 0, 0, 0)

If isClickInCell Then
rect = dg.GetCellBounds(hti.Row, hti.Column)
isClickInCell = e.X > rect.Right - Me._buttonFace.Width
End If
If isClickInCell Then
Dim g As Graphics = Graphics.FromHwnd(dg.Handle)
DrawButton(g, Me._buttonFace, rect, hti.Row)
g.Dispose()
RaiseEvent CellButtonClicked(Me, New DataGridCellButtonClickEventArgs(hti.Row, hti.Column))
End If
End Sub

Public Sub HandleMouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim dg As DataGrid = Me.DataGridTableStyle.DataGrid
Dim hti As DataGrid.HitTestInfo = dg.HitTest(New Point(e.X, e.Y))
Dim isClickInCell As Boolean = (hti.Column = Me._columnNum And hti.Row > -1)
Dim rect As New Rectangle(0, 0, 0, 0)
If isClickInCell Then
rect = dg.GetCellBounds(hti.Row, hti.Column)
isClickInCell = e.X > rect.Right - Me._buttonFace.Width
End If

If isClickInCell Then
Dim g As Graphics = Graphics.FromHwnd(dg.Handle)
DrawButton(g, Me._buttonFacePressed, rect, hti.Row)
g.Dispose()
_pressedRow = hti.Row
End If
End Sub


Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal [source] As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal backBrush As System.Drawing.Brush, ByVal foreBrush As System.Drawing.Brush, ByVal alignToRight As Boolean)
Dim parent As DataGrid = Me.DataGridTableStyle.DataGrid
Dim current As Boolean = parent.IsSelected(rowNum) Or (parent.CurrentRowIndex = rowNum And parent.CurrentCell.ColumnNumber = Me._columnNum)

Dim BackColor As Color
If current Then BackColor = parent.SelectionBackColor Else BackColor = parent.BackColor
Dim ForeColor As Color
If current Then ForeColor = parent.SelectionForeColor Else ForeColor = parent.ForeColor

g.FillRectangle(New SolidBrush(BackColor), bounds)

Dim s As String = Me.GetColumnValueAtRow([source], rowNum).ToString()

Dim bm As Bitmap
If _pressedRow = rowNum Then bm = Me._buttonFacePressed Else bm = Me._buttonFace
DrawButton(g, bm, bounds, rowNum)
End Sub
End Class

The main part I dont understand is the drawbutton, HandleMouseUp, HandleMouseDown Sub.

Lisa
AnswerRe: is there someone can explain this code? Pin
Anonymous11-Aug-04 14:04
Anonymous11-Aug-04 14:04 
Answeroriginal source code Pin
Anonymous11-Aug-04 14:27
Anonymous11-Aug-04 14:27 
GeneralRe: original source code Pin
Lisana11-Aug-04 14:35
Lisana11-Aug-04 14:35 
AnswerRe: is there someone can explain this code? Pin
Nick Seng11-Aug-04 15:09
Nick Seng11-Aug-04 15:09 
GeneralRe: is there someone can explain this code? Pin
Lisana11-Aug-04 15:24
Lisana11-Aug-04 15:24 
Generalhelp! error: BC30389: 'C' is not accessible in this context because it is 'Private' Pin
isnapols11-Aug-04 3:21
isnapols11-Aug-04 3:21 
GeneralRe: help! error: BC30389: 'C' is not accessible in this context because it is 'Private' Pin
Colin Angus Mackay11-Aug-04 4:00
Colin Angus Mackay11-Aug-04 4:00 
GeneralKodak Image controls Pin
Brad Fackrell11-Aug-04 3:02
Brad Fackrell11-Aug-04 3:02 
GeneralRe: Kodak Image controls Pin
Dave Kreskowiak11-Aug-04 5:18
mveDave Kreskowiak11-Aug-04 5:18 
GeneralRe: Kodak Image controls Pin
Brad Fackrell11-Aug-04 12:12
Brad Fackrell11-Aug-04 12:12 
GeneralWriting data to binary files Pin
Simon Kearn11-Aug-04 0:16
sussSimon Kearn11-Aug-04 0:16 
GeneralRe: Writing data to binary files Pin
Simon Kearn11-Aug-04 5:42
sussSimon Kearn11-Aug-04 5:42 
GeneralRe: Writing data to binary files Pin
Dave Kreskowiak11-Aug-04 6:01
mveDave Kreskowiak11-Aug-04 6:01 
Generalpdf conversion example program Pin
franco_8210-Aug-04 20:30
franco_8210-Aug-04 20:30 
GeneralRe: pdf conversion example program Pin
Member 53081011-Aug-04 3:17
Member 53081011-Aug-04 3:17 
GeneralRe: pdf conversion example program Pin
Dave Kreskowiak11-Aug-04 4:53
mveDave Kreskowiak11-Aug-04 4:53 
GeneralMessageBox And MsgBox Pin
beowulfagate10-Aug-04 16:25
beowulfagate10-Aug-04 16:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.