24.6.11

CDrom Detect with VB.NET

Hi Everybody,
I would like to discuss one of the most common FAQs regarding how we can detect CDroom with VB.NET 2010 Windows application? If any question, please feel free and contact me y_turkeli@yahoo.com or yenerturkeli@v-basic.net.

1-)We are creating a new Windows Application Project (cdrom_detect)



2-)We are designing this windows form in a similar way to the picture below




3-) We are writing this code

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


Dim my_Drives() As IO.DriveInfo = IO.DriveInfo.GetDrives()


Dim driver_info As IO.DriveInfo


For Each driver_info In my_Drives



ListBox1.Items.Add(driver_info.Name)

If driver_info.DriveType = DriveType.CDRom Then
TextBox1.Text = driver_info.Name
End If




Next


End Sub


4-) Lets run application and click button

18.6.11

Working with Rich Text Format(Image)

Hi Everybody,
I would like to discuss one of the most common FAQs regarding how we can work RTF(Rich Text Format) files and images with VB.NET 2010 Windows application? If any question, please feel free and contact me y_turkeli@yahoo.com or yenerturkeli@v-basic.net.

1-) We are creating a new Windows Application Project (richtextbox_codes)



2-)We are designing this windows form in a similar way to the picture below





3-)We are writing this code



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = RichTextBox1.Rtf
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim open_file As New OpenFileDialog
open_file.Filter = "Files (*.rtf) *.rtf"

Try
If open_file.ShowDialog() = DialogResult.OK Then

RichTextBox1.LoadFile(open_file.FileName)
RichTextBox1.Modified = True
Else
MsgBox("Please select a file", vbInformation, "RTF Application")

End If
Catch ex As Exception
MsgBox(ex.Message, vbCritical, "RTF Application")
End Try

End Sub

4-) We are creating a RTF file with Microsoft Word (image, text etc)





5-) Lets run the application




Have a great day

Yener Turkeli
yenerturkeli@v-basic.net

1.6.11

Working With Multithread Application

Hi Everybody,
I would like to discuss one of the most common FAQs regarding how we can work multithread with VB.NET 2010 Windows application? If any question, please feel free and contact me y_turkeli@yahoo.com or yenerturkeli@v-basic.net.

Why we use multithread?
Multithread applications are working without freezing while these application are processing. New Operation systems(Windows XP, Windows Vista, Windows 7, Windows 2003-2008 so on) allow a application in order to work one or more threads. There are a lot of advantages for working multithread application, In other words, multithread application are working paralel processing instead of serial processing. They dont need to wait main process response, they are working separately. It means there is no need to wait others process responses, they are working under different sessions .

1-) We are creating a new Windows Application Project (multi_thread)



2-) We are designing this windows form in a similar way to the picture below




3-)We are writing this code

Public Class Form1
Private i, y

Sub increase_i_number()
'go on i = 5000
Do Until i = 5000

' increase i
i = i + 2

'indicate label
thread1_lbl.Text = i

' refresh form
Me.Refresh()

Loop

End Sub

Sub increase_y_number()

'go on y = 5000
Do Until y = 5000

' increase y
y = y + 2

'indicate label
thread2_lbl.Text = y

' refresh form
Me.Refresh()
Loop

End Sub






Private Sub thread1_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles thread1_btn.Click

'give permission for cross thread
Me.CheckForIllegalCrossThreadCalls = False

'if thread check
If thread_rd1.Checked = True Then

' call sub form with this thread
Dim my_thread1 As New System.Threading.Thread( _
AddressOf increase_i_number)

'start thread
my_thread1.Start()

'if wthread checked call without thread
ElseIf wthread_rd1.Checked = True Then

'call sub form
increase_i_number()

End If
End Sub

Private Sub thread2_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles thread2_btn.Click

'if thread2 checked
If thread_rd2.Checked = True Then

'call sub form with thread
Dim my_thread2 As New System.Threading.Thread( _
AddressOf increase_y_number)

'thread start
my_thread2.Start()

'if without thread checked start without thread
ElseIf wthread_rd2.Checked = True Then

'call sub form directly
increase_y_number()
End If
End Sub

End Class

4-)Lets run application and start application multi thread and without multi thread




Have a great day

Yener Turkeli
yenerturkeli@v-basic.net