After work, I collected some small code segments for you to search.
1.Statistical Method of a single character in a regular expressionDim STR as string = "fkdsajfl Gan jdsa Gan kfjdsflaf" <br/> dim Reg as new text. regularexpressions. regEx ("Gan") <br/> msgbox (Reg. matches (STR ). count)
2.Hide tabcontrol labels
Private sub frmpersonsetting_resize (byval sender as object, byval e as system. eventargs) handles me. resize <br/> me. tabcontrol1.region = new region (New rectanglef (Me. tabpage1.left, me. tabpage1.top, me. tabpage1.width, me. tabpage1.height) <br/> end sub
3.FTP data upload
Try <br/> dim client as new net. webClient <br/> client. credentials = new net. networkcredential (str_username, str_password) <br/> client. uploadfile (str_path, str_filename) <br/> catch ex as exception <br/> msgbox (ex. tostring) <br/> end try
4. Use the read text method to export Excel (this method is fast)
Public sub exporttoexcel (byval dgv as system. windows. forms. datagridview) <br/> dim STR as string = "" <br/> dim tempstr as string = "" <br/> dim filename as string = "" <br/> dim SaveFile new savefiledialog <br/> SaveFile. filter = "execl files (*. XLS) | *. xls "<br/> SaveFile. filterindex = 0 <br/> SaveFile. restoredirectory = true <br/> SaveFile. title = "export to excel" <br/> SaveFile. showdialog () <br/> filename = SaveFile. filename <br/> If filename = "" Then exit sub <br/> using SW as streamwriter = new streamwriter (filename, false, system. text. encoding. getencoding (-0) <br/> try <br/> for I as integer = 0 to dgv. columns. count-1 <br/> If I> 0 then <br/> STR = STR & vbtab <br/> end if <br/> STR = STR & dgv. columns (I ). headertext. trim <br/> next <br/> SW. writeline (STR) <br/> for J as integer = 0 to dgv. rows. count-1 <br/> tempstr = "" <br/> for K as integer = 0 to dgv. columns. count-1 <br/> if k> 0 then <br/> tempstr = tempstr & vbtab <br/> end if <br/> tempstr = tempstr & dgv. rows (j ). cells (k ). value. tostring. trim <br/> next <br/> SW. writeline (tempstr) <br/> next </P> <p> SW. close () <br/> catch ex as exception <br/> msgbox (ex. tostring. trim) <br/> end try <br/> end using <br/> end sub
5. screenshots
Private declare function createdc lib "GDI32" alias "createdca" (byval lpdrivername as string, byval lpdevicename as string, byval lpoutput as string, byval lpinitdata as int32) as int32 <br/> private declare function bitblt lib "GDI32" (byval hdestdc as integer, byval X as integer, byval y as integer, byval nwidth as integer, byval nheight as integer, byval hsrcdc as integer, byval xsrc as integer, byval ysrc as integer, byval dwdrop as integer) as integer <br/> private picture as bitmap = nothing 'uses picture as the sound of the image format <br/> Public sub capture_window () <br/> me. visible = false <br/> dim capture1 as intptr = createdc ("display", nothing) <br/> dim get1 as graphics = graphics. fromhdc (capture1) <br/> 'create a new graphics object <br/> picture = new Bitmap (screen. primaryscreen. bounds. width, screen. primaryscreen. bounds. height, get1) <br/> 'create a bitmap of the same size based on the screen size <br/> dim get2 as graphics = graphics. fromimage (picture) <br/> dim get3 as intptr = get1.gethdc () 'Get the screen handle <br/> dim get4 as intptr = get2.gethdc () 'obtain the bitmap handle <br/> bitblt (get4, 0, 0, screen. primaryscreen. bounds. width, screen. primaryscreen. bounds. height, get3, _ <br/> 0, 0, 13369376) 'Copy the current screen to the correct graph. <br/> get1.releasehdc (get3) 'release the screen handle <br/> get2.releasehdc (get4) 'release the bitmap handle <br/> picture. save ("capturepicture.jpg", imageformat. JPEG) <br/> MessageBox. show ("You have saved the screenshots to capturepicture.jpg and checked the program root directory") <br/> me. visible = true <br/> end sub
6. Obtain the system font
Private sub form1_load (byval sender as object, byval e as system. eventargs) handles mybase. load <br/> dim installedfont as new system. drawing. text. installedfontcollection <br/> dim fonts as system. drawing. fontfamily () = installedfont. families <br/> me. combobox1.datasource = fonts <br/> me. combobox1.displaymember = "name" <br/> end sub </P> <p> private sub combobox#selectedindexchanged (byval sender as object, byval e as system. eventargs) handles combobox1.selectedindexchanged <br/> if me. combobox1.selecteditem is nothing then exit sub <br/> me. textbox1.font = new font (ctype (Me. combobox1.selecteditem, system. drawing. fontfamily), 20) <br/> end sub
7.Traverse the Registry
Dim key, subkey, No1, NO2, NO3, No4, sitekey as Microsoft. win32.registrykey <br/> dim site, valuename as string <br/> valuename = "path" <br/> key = Microsoft. win32.registry. localmachine <br/> subkey = key. opensubkey ("software") <br/> No1 = subkey. opensubkey ("Microsoft") <br/> NO2 = no1.opensubkey ("Windows") <br/> NO3 = no2.opensubkey ("CurrentVersion ") <br/> No4 = no3.opensubkey ("app paths") <br/> for each site in no4.getsubkeynames () <br/> sitekey = no4.opensubkey (SITE) <br/> for each valuename in sitekey. getvaluenames () <br/> If comment Rev (sitekey. getvalue (valuename ). tostring ,". ")> 0 and sitekey. getvalue (valuename ). tostring. length> 4 then <br/> me. listlj. items. add (sitekey. getvalue (valuename) <br/> end if <br/> next
For more code, visit my website.
Code trio