Capture Double-click Events (VB.NET Version) - Menciic E

xiaoxiao2021-03-06  49

Option Strict Off

Option Explicit on

Imports Microsoft.visualBasic

Imports system

Imports system.componentmodel

Imports system.data

Imports system.drawing

Imports System.Windows.Forms

Namespace DataGridDoubleClick

Public Class Form1

Inherits Form

Private Withevents DataGrid1 As DataGrid

Private Withevents MyDataSet As DataSet

Private GridMouseDowntime as datetime

Private Components As Container

Public Sub New ()

Mybase.new ()

InitializeComponent ()

GridMouseDowntime = datetime.now

Setup ()

End Sub

Protected Overloads Overrides Sub Dispose (Byval Disposing as Boolean)

IF Disposing then

IF (NOT (Components) IS Nothing) THEN

Components.dispose ()

END IF

END IF

Mybase.dispose (Disposing)

End Sub

Private sub setup ()

Makedataset ()

DataGrid1.SetDataBinding (MyDataSet, "Customers")

AddCustomDataTaiStyle ()

End Sub

Private sub makeDataSet ()

MyDataSet = New Dataset ("MyDataSet")

DIM TCUSTAS DATATABLE

TCUST = New DataTable ("Customers")

DIM CCUSTID AS DATACOLUMN

CCustid = New Datacolumn ("CustID")

DIM CCUSTNAME AS Datacolumn

CCustName = New Datacolumn ("CustName")

DIM CCURRENT AS DATACOLUMN

Ccurrent = New Datacolumn ("CustCITY")

Tcust.columns.add (ccustid)

Tcust.column.add (ccustname)

Tcust.column.add (ccurrent)

MyDataSet.Tables.Add (TCUST)

DIM NewRow1 As DataRow

DIM I as integer

i = 1

Do While (i <4)

NEWROW1 = Tcust.newrow

NEWROW1 ("Custid") = i.toString ()

TCUST.ROWS.ADD (NewRow1)

i = (i 1)

Loop

TCUST.ROWS (0) ("CustName") = "[Wonderful World of Mengxian]"

TCUST.ROWS (1) ("CustName") = "Net_lover"

TCUST.ROWS (2) ("CustName") = "http://xml.sz.luohuedu.net/"tcust.rows(0) (" Custcity ") =" Beijing "

TCUST.ROWS (1) ("CustCITY") = "Shanghai"

TCUST.ROWS (2) ("CustCITY") = "Henan"

End Sub

Private sub addcustomDataTylestyle ()

DIM TS1 AS DATAGRIDTABLESTYLELELE

Ts1 = new dataGridTableStyle ()

Ts1.mappingname = "CUSTOMERS"

Ts1.alternatingbackbackcolor = color.lightgray

Dim Textcol as DataGridTextBoxColumn

Textcol = new dataGridTextBoxColumn ()

Textcol.mappingname = "custom"

TextCol.Headertext = "Sequence"

Textcol.width = 100

AddHandler Textcol.TextBox.mousedown, New MouseeventHandler (Addressof TextBoxMousedownHandler)

AddHandler Textcol.TextBox.doubleClick, New EventHandler (Addressof TextBoxDoubleClickHandler)

Ts1.gridColumnStyles.Add (Textcol)

Textcol = new dataGridTextBoxColumn ()

Textcol.mappingname = "custname"

Textcol.Headertext = "Name"

Textcol.width = 100

AddHandler Textcol.TextBox.mousedown, New MouseeventHandler (Addressof TextBoxMousedownHandler)

AddHandler Textcol.TextBox.doubleClick, New EventHandler (Addressof TextBoxDoubleClickHandler)

Ts1.gridColumnStyles.Add (Textcol)

Textcol = new dataGridTextBoxColumn ()

Textcol.mappingname = "custom"

Textcol.Headertext = "Address"

Textcol.width = 100

AddHandler Textcol.TextBox.mousedown, New MouseeventHandler (Addressof TextBoxMousedownHandler)

AddHandler Textcol.TextBox.doubleClick, New EventHandler (Addressof TextBoxDoubleClickHandler)

Ts1.gridColumnStyles.Add (Textcol)

DataGrid1.tables.Add (TS1)

End Sub

Friend Withevents Label1 As System.Windows.Forms.Label

Private subinitializeComponent ()

Me.DataGrid1 = new system.windows.Forms.DataGrid ()

Me.label1 = new system.windows.forms.label ()

Ctype (me.datagrid1, system.componentmodel.isupportinitialize) .beginInit ()

Me.suspendlayout ()

'

'DataGrid1

'

Me.DataGrid1.captionvisible = false

Me.DataGrid1.datamember = ""

Me.DataGrid1.HeaderforeColor = system.drawing.systemcolors.ControlText

Me.DataGrid1.location = new system.drawing.point (12, 8)

Me.DataGrid1.name = "DataGrid1"

Me.DataGrid1.size = new system.drawing.size (368, 128)

Me.DataGrid1.tabindex = 0

'

'Label1

'

Me.Label1.Location = new system.drawing.point (10, 149)

Me.Label1.name = "label1"

Me.label1.size = new system.drawing.size (370, 23)

Me.label1.tabindex = 1

Me.label1.textalign = system.drawing.contentAlignment.middleCenter

'

'Form1

'

Me.autoscalebasesize = new system.drawing.size (5, 13)

Me.ClientSize = new system.drawing.size (388, 189)

Me.Controls.addrange (new system.windows.forms.control () {me.label1, me.datagrid1})

Me.Name = "Form1"

Me.Text = "Example of the Mouse Double-click Event"

Ctype (me.datagrid1, system.componentmodel.isupportinitialize) .endinit ()

Me.ResumeLayout (false)

End Sub

_ _

Public Shared Sub Main ()

Application.run (New Form1 ())

End Sub

Private Sub TextBoxDoubleClickHandler (Byval E AS Object, Byval E As Eventargs)

MessageBox.show ("Truedoucast")

End Sub

Private Sub TextBoxMousedownHandler (Byval E AS Object, Byval e as mouseeventargs

IF (DateTime.Now

Messagebox.show ("GridDoubleClick:" ctype (sender, textbox) .text) End IF

Label1.text = "TextBoxMouseDownHandler"

End Sub

Private sub DataGrid1_mousedown (Byval Sender as system.object, _

Byval e as system.windows.Forms.MouseEventArgs) Handles DataGrid1.mousedown

GridMouseDowntime = datetime.now

Label1.text = "DataGrid1_mousedown"

End Sub

Private sub label1_click (Byval E AS System.Object, Byval E AS System.EventArgs)

Handles label1.click

Label1.text = ""

End Sub

Private Sub Form1_Click (Byval Sender As System.Object, ByVal E AS System.EventArgs)

Handles mybase.click

Label1.text = ""

End Sub

END CLASS

End Namespace

转载请注明原文地址:https://www.9cbs.com/read-81298.html

New Post(0)