陈恩点在此为你解答如有错误请见谅:
创新互联公司是一家专注于成都网站建设、成都网站设计与策划设计,措美网站建设哪家好?创新互联公司做网站,专注于网站建设十载,网设计领域的专业建站公司;建站业务涵盖:措美等地区。措美做网站价格咨询:18980820575
好复杂的 这个编程有一定难度啊
有没有报酬啊
也不是不可以实现,只不过复杂一点而已,具体看下面代码。不过在需要换行等情况下的文本显示,还是建议用RichTextBox开启只读属性比较省心、比较合适。
Private Sub AutoNextRow()
'获取ListBox行集合文本
Dim length As Integer = (ListBox1.Items.Count - 1)
Dim items(length) As String '行文本数组
For i As Integer = 0 To length
items(i) = ListBox1.Items(i).ToString
Next
'处理ListBox换行
ListBox1.Items.Clear() '清空行内容
Using g As Graphics = Graphics.FromHwnd(ListBox1.Handle)
Dim result As New List(Of Object)
Dim w As Single = ListBox1.ClientSize.Width
Dim sf As SizeF, str As StringBuilder
For Each s As String In items
str = New StringBuilder
For i As Integer = 0 To (s.Length - 1)
sf = g.MeasureString(str.ToString s(i), ListBox1.Font)
If sf.Width w Then
result.Add(str.ToString)
str = New StringBuilder
End If
str.Append(s(i))
If i = s.Length - 1 Then result.Add(str.ToString)
Next
Next
ListBox1.Items.AddRange(result.ToArray) '填充行内容
End Using
End Sub
'================================ACCESS=================================
Public AccessConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _
"Data Source=D:\Simple.mdb;" _
"Persist Security Info=False"
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Try
Dim AccessString As String = "SELECT * FROM 示例表 "
Dim AccessConn As New OleDb.OleDbConnection(AccessConnectionString)
AccessConn.Open()
Dim AccessAdapter As OleDbDataAdapter = New OleDbDataAdapter(AccessString, AccessConn)
'有返回值
Dim TempDataSet As New DataSet
AccessAdapter.Fill(TempDataSet)
DataGridView1.DataSource = TempDataSet.Tables(0)
AccessConn.Close()
Catch AccessException As Exception
MsgBox(AccessException.Message)
End Try
End Sub
陈恩点原创,转载请保留!
'================================SQL================================
Protected Const SqlConnectionString As String = _
"Server=CED-PC\SQLEXPRESS;" _
"DataBase=;" _
"Integrated Security=SSPI"
#Region "Display data"
' Handles the click event for the Display button. This handler gets the product
' information from the Contact table puts it into a DataSet which is used to
' bind to a DataGrid for display. Custom style objects are used to give the
' DataGrid a nice appearance.
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
If IsNothing(DataGridView1.DataSource) Then
Dim strSQL As String = _
"USE Simple" vbCrLf _
"SELECT * " _
"FROM GetContacts"
Try
' The SqlConnection class allows you to communicate with SQL Server.
' The constructor accepts a connection string as an argument. This
' connection string uses Integrated Security, which means that you
' must have a login in SQL Server, or be part of the Administrators
' group for this to work.
Dim dbConnection As New SqlConnection(connectionString)
' A SqlCommand object is used to execute the SQL commands.
Dim cmd As New SqlCommand(strSQL, dbConnection)
' The SqlDataAdapter is responsible for using a SqlCommand object to
' fill a DataSet.
Dim da As New SqlDataAdapter(cmd)
Dim dsContacts As New DataSet()
da.Fill(dsContacts, "Contact")
With Me.DataGridView1
.Visible = True
.AutoGenerateColumns = False
.AlternatingRowsDefaultCellStyle.BackColor = Color.Lavender
.BackColor = Color.WhiteSmoke
.ForeColor = Color.MidnightBlue
.CellBorderStyle = DataGridViewCellBorderStyle.None
.ColumnHeadersDefaultCellStyle.Font = New Font("Tahoma", 8.0!, FontStyle.Bold)
.ColumnHeadersDefaultCellStyle.BackColor = Color.MidnightBlue
.ColumnHeadersDefaultCellStyle.ForeColor = Color.WhiteSmoke
.DefaultCellStyle.ForeColor = Color.MidnightBlue
.DefaultCellStyle.BackColor = Color.WhiteSmoke
End With
Me.DataGridView1.DataSource = dsContacts.Tables(0)
Dim newColumn As Integer = Me.DataGridView1.Columns.Add("ContactID", "Contact ID")
Me.DataGridView1.Columns(newColumn).DataPropertyName = "ContactID"
newColumn = Me.DataGridView1.Columns.Add("FirstName", "First Name")
Me.DataGridView1.Columns(newColumn).DataPropertyName = "FirstName"
newColumn = Me.DataGridView1.Columns.Add("LastName", "Last Name")
Me.DataGridView1.Columns(newColumn).DataPropertyName = "LastName"
Catch sqlExc As SqlException
MessageBox.Show(sqlExc.ToString, "SQL Exception Error!", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub
#End Region
陈恩点原创,转载请保留!