陳恩點在此為你解答如有錯誤請見諒:
創(chuàng)新互聯(lián)公司是一家專注于成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計與策劃設(shè)計,措美網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)十載,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:措美等地區(qū)。措美做網(wǎng)站價格咨詢:18980820575
好復(fù)雜的 這個編程有一定難度啊
有沒有報酬啊
也不是不可以實現(xiàn),只不過復(fù)雜一點而已,具體看下面代碼。不過在需要換行等情況下的文本顯示,還是建議用RichTextBox開啟只讀屬性比較省心、比較合適。
Private?Sub?AutoNextRow()
'獲取ListBox行集合文本
Dim?length?As?Integer?=?(ListBox1.Items.Count?-?1)
Dim?items(length)?As?String?'行文本數(shù)組
For?i?As?Integer?=?0?To?length
items(i)?=?ListBox1.Items(i).ToString
Next
'處理ListBox換行
ListBox1.Items.Clear()?'清空行內(nèi)容
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)?'填充行內(nèi)容
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
陳恩點原創(chuàng),轉(zhuǎn)載請保留!
'================================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
陳恩點原創(chuàng),轉(zhuǎn)載請保留!