添加Microsoft Forms 2.0 控件,它是一組與vb一樣的控件,backStyle屬性可以設(shè)置為透明的。
創(chuàng)新互聯(lián)專注于瓊中黎族企業(yè)網(wǎng)站建設(shè),自適應(yīng)網(wǎng)站建設(shè),商城建設(shè)。瓊中黎族網(wǎng)站建設(shè)公司,為瓊中黎族等地區(qū)提供建站服務(wù)。全流程按需求定制制作,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
設(shè)置文本框的 BackStyle 屬性該屬性可以取兩個(gè)值,即0 和 1 。如果為 0 ,則是透明的。
該屬性可以在屬性窗口中設(shè)置,也可以通過代碼設(shè)置。其格式為:
對(duì)象.BackStyle[=0 或 1]
1、將窗口的TransparencyKey屬性設(shè)置成某一種顏色(在顯示時(shí),這種顏色會(huì)顯示為透明),如:
Me.TransparencyKey = System.Drawing.Color.Red(可在屬性窗口中指定或通過代碼設(shè)置)
2、將Label的BackColor屬性設(shè)置為與窗口的TransparencyKey屬性相同的顏色,如:
Me.label1.BackColor = System.Drawing.Color.Red(可在屬性窗口中指定或通過代碼設(shè)置)
或
Me.label1.BackColor = Me.TransparencyKey(只能通過代碼設(shè)置)
3、將Label的ForeColor屬性設(shè)置為與窗口的TransparencyKey屬性不相的顏色,如:
Me.label1.ForeColor = System.Drawing.Color.Blue(可在屬性窗口中指定或通過代碼設(shè)置)
這種功能讀winform來說只有容器才能設(shè)置透明度,如form、panel類控件,其他的不是不可以,要重寫背景參數(shù),而且重寫完了后與win7、Xp互不兼容,閃爍,并不提倡。.net的解決辦法是wpf,控件可以設(shè)置opation屬性,靈活控制透明度,并且后臺(tái)靜態(tài)刷新,因?yàn)樗莤aml機(jī)制構(gòu)造。
好東東!可惜我e文也不太好...給你翻譯一點(diǎn):
先在左上角把類給下載了,然后,使用方法----
This sample presents a small class that allows you to tile a bitmap into the background of a TextBox. Note that the technique only works on multi-line text boxes, as the drawing of single-line TextBoxes is done in a different way and cannot be easily overridden in code.
這例子向你展示怎么用一個(gè)類給textbox貼上背景圖片。要注意的是,這種方法只能用在多行文本框上。至于單行文本框,要用另外一種方法,并且不是那么容易用代碼實(shí)現(xiàn)的。
......(中間省略無數(shù)行)
The cTextBoxBackground class
To make this easier to use, I've wrapped the code up in a simple class. This class has the following methods:
為了讓用著方便些,我把代碼都打包到一個(gè)簡單的類里面了。這個(gè)類有下面這些方法:
Attach(ByVal hWndA As Long)
Attaches the class to the multi-line text box with the specified hWnd. Don't call this method until you've set up the background picture first.
讓類與多行文本框連接(Attach),需指定hWnd。你必須先設(shè)置好背景圖片,才能call這個(gè)方法。
Detach()
Detaches from the class so the text box painting goes back to normal. Called automatically when the TextBox is destroyed.
取消連接,使文本框會(huì)到原來的模式。文本框被摧毀(例如unload窗體)時(shí)會(huì)自動(dòng)執(zhí)行。
SetBackdrop(pic As IPicture)
Sets the background bitmap from a standard VB picture object (for example, a StdPicture returned from LoadPicture or the picture returned by a PictureBox's Picture property.
用一個(gè)標(biāo)準(zhǔn)的vb圖片對(duì)象(例如一個(gè)由LoadPicture()函數(shù)返回的StdPicture對(duì)象,或者PictureBox的Picture 屬性)設(shè)置背景位圖
TileArea(ByVal hdcTo As Long, ByVal x As Long, ByVal y As Long, ByVal Width As Long, ByVal Height As Long)
The bitmap tiling function is exposed to allow you to tile the bitmap onto any other objects with a hDC property. This is used in the second sample form in the demo to tile the background of the form.
這個(gè)方法能讓你通過把位圖貼到其它對(duì)象上,只要你能提供它的hDC屬性。在示例里的第二個(gè)窗體有用這個(gè)方法貼窗體背景的例子。
TileOffsetX() As Long
Gets or Sets the initial X offset in the bitmap to start tiling from.
返回或者設(shè)置位圖繪制起始點(diǎn)的X坐標(biāo)。
TileOffsetY() As Long
Gets or Sets the initial Y offset in the bitmap to start tiling from.
返回或者設(shè)置位圖繪制起始點(diǎn)的Y坐標(biāo)。
To use it, first add a TextBox to a form, set it to multi-line mode and then create a form level instance of the cTextBoxBackground class (here I'm assuming it's called m_cLargeTextBoxBack). Then set the background picture and attach it to the text box as follows:
使用的時(shí)候,先放上一個(gè)TextBox,設(shè)置為multi-line模式;然后聲明一個(gè)模塊級(jí)的cTextBoxBackground實(shí)例(我假定是那實(shí)例叫m_cLargeTextBoxBack)。最后像下面那樣設(shè)置背景圖片并把它貼到TextBox上:
Set m_cLargeTextBoxBack = New cTextBoxBackground
m_cLargeTextBoxBack.SetBackdrop LoadPicture(App.Path "\back.bmp")
m_cLargeTextBoxBack.Attach txtTest.hwnd
要考四級(jí)了,算是練習(xí)吧...555...祝我好運(yùn)...