65.9K
CodeProject is changing. Read more.
Home

Tips And Links

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.23/5 (12 votes)

Mar 22, 2006

4 min read

viewsIcon

41539

This article shows some useful tips & links for VB.Net.

Introduction

There are many useful tips & links we can find on VB.Net forum, but we miss them day by day. It is very difficult to retrieve them. My effort is to keep those tips forever. I have included new tips and answers that I provided to VB.Net forum.

 

Tips & Links -  Index

 

Forms

3. What Are The Codes For Custom Minimize & Maximize Buttons

4. How To Create Always On Top Form

5. How To Create A Form With A Transparent Background

14. How To Create A Dialog

Controls

6. How To Use Splitters                                                                [ Splitter ]

8. How To Print the Content of a RichTextBox                [ RichTextBox ]

9. Find And Replace Method For RichTextBox                [ RichTextBox ]

10. How To Handle Multiple Button Clicks                                 [ Button ]

 

File Handling

1. How To Open A File

13. How To Create A New Directory

Graphics Handling

2. How To Use Flash In VB.Net

11. How To Insert An Image Into A PictureBox At Run Time

Others

7. What Are The Conversion Functions In VB.Net

12. How To Get Day Of The Week

 

 

Red & Green - Tips            Blue & Purple - Links

 

 

Tips & Links

 

1. How To Open A File File Handling

You can use  this code to open a file with its associated application

System.Diagnostics.Process.Start(Filename)

 

2. How To Use Flash In VB.Net Graphics Handelling

An Example:

 

Flash MX
Create a button.
Select “Window” menu. Select “Development Panel --> Actions”
In the code editor, type this

on (release) {
fscommand ("Button1");
}


Save the movie. (“Untitled-1.fla”)
Select “Control” menu and Select “Test Movie”
Flash will create (“Untitled-1.swf”)
Exit from Flash.

VB.Net
Right click on the tool box. Select “Add/Remove Items…”. Select “COM Components”
Select “Shockwave Flash Object”. Click OK
Draw it on the form
Name it “SF1”

Right click on “SF1” and select “Properties”
Type the path to “Untitled-1.swf” in the “Movie URL” textbox.
Click OK

Double Click on SF1 ( go to Code Editor )
Select “FS Command” from Procedure List Box
Type this

Private Sub SF1_FSCommand(ByVal sender As Object, ByVal e As AxShockwaveFlashObjects.DShockwaveFlashEvents_FSCommandEvent) Handles SF1.FSCommand
If e.command = "Button1" Then
MsgBox("it works")
End If
End Sub


Run the program
Click on Button1

 

3. What Are The Codes For Custom Minimize & Maximize Buttons Forms

Me.WindowState = FormWindowState.Minimized

Me.WindowState = FormWindowState.Maximized

 

4. How To Create Always On Top Form Forms

Simple, set form's Topmost property to true

 

5. How To Create A Form With A Transparent Background Forms

Set form's TransparancyKey property to forms background color, or you can create ghostly forms by changing the Opaque property

(0 -100)

 

6. How To Use Splitters Controls [ Splitters ]

An Example:

 

1. Draw a panel on the form

2. Draw a textbox on the panel ( TextBox1.width is ( 1/2 Panel1.width ) )

3. Set TexBox1's Dock property to Left

4. Draw a splitter on the panel and set its Dock property to Left

5. Run Your Application

6. Now  resize your TextBox1 by dragging the splitter

 

7. What Are The Conversion Functions In Visual Basic Others

CBool  : Converts to Bool

CByte  : Converts to Byte

CChar  : Converts to Char

CDate  : Converts to Date

CDbl     : Converts to Double

CDec    : Converts to Decimal

CInt     : Converts to Int

CLng    : Converts to Long

CObj      : Converts to Object

CShort  : Converts to Short

CSng     : Converts to Single

CStr      : Converts to String

 

8. How To Print the Content of a RichTextBox Controls [ RichTextBox ]

http://support.microsoft.com/default.aspx?scid=kb;en-us;811401

 

9. Find And Replace Method For RichTextBox Controls [ RichTextBox ]

http://www.codeproject.com/useritems/findandriplace_rtb.asp

 

10. How To Handle Multiple Button Clicks Controls [ Buttons ]

If You have two or more buttons you can handle them like this

 

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, _ Button2.Click,Button3.Click

If sender Is Button1 Then

action1

ElseIf sender Is Button2 Then

action2

ElseIf sender Is Button3 Then

action3

End If

End Sub

 

11. How To Insert An Image Into A Picture Box At Run Time Graphics Handling

PictureBox1.Image = Image.FromFile(filename)

 

12. How To get Day Of The Week Others

'If Date is 24 March 2006

Dim strDayOfTheWeek As String

Dim intDayOfTheWeek As Integer

strDayOfTheWeek = Now.DayOfWeek.ToString ' returns Friday

intDayOfTheWeek = Now.DayOfWeek ' returns 5

 

13. How To Create A New Directory File Handling

Imports System.IO

.

.

Directory.CreateDirectory(Path) 'Example Directory.CreateDirectory( "C:\myDirectory" )

 

14. How To Create A Dialog Forms

VB.Net 2003

1. Create a new form (Form2)

2. Create two buttons

3. Set these properties

   Button1 : Name = OK_Button , Caption = OK

   Button2 : Name = Cancel_Button , Caption = Cancel

   Form2 :   Name = Dialog1 , FormBorderStyle = FixedDialog , MazimizeBox = False , MinimizeBox = False , AcceptButton = OK_Button                 , CancelButton = Cancel_Button

 

VB.Net 2005

Click Add New Items button on the standard toolbar

Select Dialog and Click Add

 

Now You Can Use Your Dialog in Form1

Dim myDialog As New Dialog1

If myDialog.ShowDialog = Windows.Forms.DialogResult.OK Then

action

End If