How To Play A Wave Sound File In Background Mode In C#

wave file

this is gonna be a snippet and i call it a useful snippet , you just need to add a namespace and add 4 lines of codes to a event .

add this namespace :

Using System.Media;

after that you need to add these 4 lines of codes for a event (for example form_load , button_click)

SoundPlayer wave = new SoundPlayer();
            string path = "path to .WAV";
            wave.SoundLocation = path; 
            wave.Play(); 

now replace path to .WAV with the destination (for example C:/new folder/hello.wav)

i hope you enjoy this !

Drop Shadow At The Form Border In C#

shadow


i hope you guys didn't forget the same thing that i have written for VB.NET . alright like that we are now going to make the form border drop shadow that will make the form look awesome :) if your on a project that doesn't matter or create a new project to test it .

under

    public partial class Form1 : Form
    {


add these codes

 protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ClassStyle |= CS_DROPSHADOW;
                return cp;
            }
        }

now debug and enjoy the shadow

c# shadow at form

share ! comment ! like us on facebook ! follow us on twitter !

How To Validate Textbox : Only Numbers, Only Characters, Not Null, Only Email in VB.NET

vb.net , textbox


Today I have brought you something delicious :) so you guys wonder how it works , first we have to create a module and we just have to assign the textbox for a validation (Only Number,Only Characters,Not Null,Only Email) so first of all lets create a new module and add this codes

Imports System.Text.RegularExpressions
Module Module1
    Public Enum ValidationType
        Only_Numbers = 1
        Only_Characters = 2
        Not_Null = 3
        Only_Email = 4
    End Enum
    Public Sub AssignValidation(ByRef CTRL As Windows.Forms.TextBox, ByVal Validation_Type As ValidationType)
        Dim txt As Windows.Forms.TextBox = CTRL
        Select Case Validation_Type
            Case ValidationType.Only_Numbers
                AddHandler txt.KeyPress, AddressOf number_Leave
            Case ValidationType.Only_Characters
                AddHandler txt.KeyPress, AddressOf OCHAR_Leave
            Case ValidationType.Not_Null
                AddHandler txt.Leave, AddressOf NotNull_Leave
            Case ValidationType.Only_Email
                AddHandler txt.Leave, AddressOf Email_Leave
        End Select
    End Sub
    Public Sub number_Leave(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        Dim numbers As Windows.Forms.TextBox = sender
        If InStr("1234567890.", e.KeyChar) = 0 And Asc(e.KeyChar) <> 8 Or (e.KeyChar = "." And InStr(numbers.Text, ".") > 0) Then
            e.KeyChar = Chr(0)
            e.Handled = True
        End If
    End Sub
    Public Sub OCHAR_Leave(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        If InStr("1234567890!@#$%^&*()_+=-", e.KeyChar) > 0 Then
            e.KeyChar = Chr(0)
            e.Handled = True
        End If
    End Sub
    Public Sub NotNull_Leave(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim No As Windows.Forms.TextBox = sender
        If No.Text.Trim = "" Then
            MsgBox("This field Must be filled!")
            No.Focus()
        End If
    End Sub
    Public Sub Email_Leave(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim Email As Windows.Forms.TextBox = sender
        If Email.Text <> "" Then
            Dim rex As Match = Regex.Match(Trim(Email.Text), "^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,3})$", RegexOptions.IgnoreCase)
            If rex.Success = False Then
                MessageBox.Show("Please Enter a valid Email Address", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Email.BackColor = Color.Red
                Email.Focus()
                Exit Sub
            Else
                Email.BackColor = Color.White
            End If
        End If
    End Sub
End Module

now lets test the module i mean lets add 4 textboxes and assign each for a validation and see whether it works !

add 4 textboxes  now add labels for each like this

validate textbox in vb.net

you can only enter numbers in textbox1
you can only enter characters in textbox2
you cannot leave textbox3 blank
you can only enter email in textbox4

now go to form_load event and add these codes

    

        AssignValidation(Me.TextBox1, ValidationType.Only_Numbers)
        AssignValidation(Me.TextBox2, ValidationType.Only_Characters)
        AssignValidation(Me.TextBox3, ValidationType.Not_Null)
        AssignValidation(Me.TextBox4, ValidationType.Only_Email)

thats where we assign the textbox for a validation !!

now lets test it just debug and try entering characters in textbox1 you cannot enter , go to textbox2 try entering characters you cannot enter , go to textbox3 and without entering anything go to textbox4 a message box will popup now go to textbox4 and enter something and click into another textbox and he textbox4 will be red in color and you will get a message

thanks for reading hope this is useful ! share ! comment !

How To Make God Mode Windows 7 In C#/VB.NET



god mode is just a folder that can be used to control anything it's really easy rather than using the windows control panel because it has all the things that a user can control :) now we are going to create that folder using c# . just put these codes in button click event or form_load event


string godmode = @"D:\god.{ED7BA470-8E54-465E-825C-99712043E01C}";
            Directory.CreateDirectory(godmode);

you need to add the using system.io; namespace to make the directory applicable . now you see when i debug the program and make the event work there will be a folder called god.{ED7BA470-8E54-465E-825C-99712043E01C} remember god is the folder name and this is the extension {ED7BA470-8E54-465E-825C-99712043E01C}

if you want to do it in vb.net use this codes

        Dim godmode As String = "D:\god.{ED7BA470-8E54-465E-825C-99712043E01C}"
        Directory.CreateDirectory(godmode)

you need to add the namespace imports system.io.

now when you debug i mean when i debug i will show you the folder created in my D drive


as you see you will also see the same folder created in the directory you have given ok now i will show inside of the god folder

you have 274 files inside : how cool


i hope you enjoy this tutorial very much .

How To Make Scrolling Graphics Effect In VB.NET


hello guys :) this is something very cool and it has been created using pure graphics(2ddrawing) in vb.net . first of all i want to say you don't need work harder to understand the codes because this is created in a very simple format . ok now you see the image in the top of this post and that's how this animation works . you can add more graphics to it if your in to themebase vb.net . first you need to add a timer and i recommend you to make the form border style none for better play .

 here is the codes

Imports System.Drawing.Drawing2D
Public Class Form1

    'Author : Mohamed Shimran
    'Blog : http://www.ultimateprogrammingtutorials.blogspot.com

    Dim g As Graphics = Me.CreateGraphics
    Dim offsetvalue As Integer = 150
    Dim x, y, cx, cy As Integer
    Dim randd As New Random
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Timer1.Start()
        rota = 10
        x = randd.Next(0, Me.Width)
        y = randd.Next(0, Me.Height)
        cx = randd.Next(5, 10)
        cy = randd.Next(5, 10)
    End Sub
    Dim rota As Integer
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim g As Graphics = e.Graphics
        g.Clear(Color.Green)
        Static angle As Integer
        x += cx
        y += cy
        If x > Me.Width - 150 Then
            cx = -cx
        ElseIf x < 0 Then
            cx = -cx
        End If
        If y > Me.Height - 150 Then
            cy = -cy
        ElseIf y < 0 Then
            cy = -cy
        End If
        Dim G_path As GraphicsPath = New GraphicsPath()
        Dim rectangle As RectangleF = New RectangleF(x, y, 200, 100)
        Dim str_format As StringFormat = New StringFormat()
        str_format.Alignment = StringAlignment.Center
        str_format.LineAlignment = StringAlignment.Center
        G_path.AddRectangle(rectangle)
        G_path.AddString("Ultimate programming tutorials", Me.Font.FontFamily, CInt(Me.Font.Style), Me.Font.Height + 15, rectangle, str_format)
        angle += rota
        If angle > 360 Then
            rota = -rota

        ElseIf angle < 0 Then
            rota = -rota
        End If
        g.DrawPath(New Pen(Brushes.Black, 4), G_path)
        g.FillPath(Brushes.Azure, G_path)
        Dim matrix As Matrix = New Matrix()
        matrix.Translate(0, 0)
        matrix.RotateAt(angle, New PointF(Me.Width / 2 + (50), Me.Height / 2 - (50 / 2)))
        G_path.Transform(matrix)
        g.DrawPath(New Pen(Brushes.White, 4), G_path)
        g.FillPath(Brushes.Black, G_path)
        g.DrawPath(Pens.Black, G_path)
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Invalidate()
    End Sub
End Class


don't do anything for the timer . just tweak the codes for your need and enjoy .

How To Connect To Mysql Database In VB.NET



hello guys , i will tell you just how to connect to mysql database in vb.net . we all know that mysql is one of the bets RDBMS which means relational database management system shortly we say DBMS which means database management system . ok now first all you need to do these things
  1. you need mysql server and mysql connector
  2. you need to add the reference mysql & mysql connector

after that with this codes you can connect to the mysql database


Imports MySql.Data.MySqlClient
Public Class form1

    'Author : Mohamed Shimran
    'Blog : http://www.ultimateprogrammingtutorials.blogspot.com

    Private mysql_connect As New MySqlConnection
    Private Sub connect_mysql()
        Dim db_name As String = "Database Name"
        Dim db_host As String = "Database Host"
        Dim username As String = "Database Username"
        Dim password As String = "Database Password"


        If Not mysql_connect Is Nothing Then mysql_connect.Close()
        mysql_connect.ConnectionString = String.Format("server={0}; user id={1}; password={2}; database={3}; pooling=false", db_host, username, password, db_name)

        Try
            mysql_connect.Open()
        Catch ex As MySqlException
            MsgBox("Connecting To Database Error:[" & ex.Message & "]")
        End Try
    End Sub
End Class


replace Database Name with your database name
replace Database Host with your database host
replace Database Username with your mysql database username
replace Database Password with your mysql database password

now debug your program if you didn't get any errors your successfully connected to your database.

How To Create Snow Falling Effect On The Form In VB.NET


I am today with an awesome effect. This is something created very simply without any classes or modules ok lets make it. First of all set your form and after that add a timer and thats all you need now just double click your form and put these.


I recommend you to use a background image or a dark background color for your form as you see in the image (top image).

How To Make A Captcha Generator In VB.NET

We all know what is captcha if you don't know what is, captcha is a word test or more than one word test that is mixed and cannot identify easily that is used to verify human. Okay now we are going to make it first you need to add a class so go ahead and add a class and add the codes below to the class.





Imports System.Text
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Drawing.Drawing2D

Class Captcha

    Inherits PictureBox
    Public randomstr As String
#Region "Properties"
    Private _textcolor As Color = Color.Black
    Public Property TextColor() As Color
        Get
            Return _textcolor
        End Get
        Set(ByVal value As Color)
            _textcolor = value
            Invalidate()
        End Set
    End Property

    Private _font As New Font("Segoe UI", 20)
    Public Overrides Property Font() As Font
        Get
            Return _font
        End Get
        Set(ByVal value As Font)
            _font = value
            Invalidate()
        End Set
    End Property

    Private _texttouse As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz1234567890"
    Public Property RandomCharacters() As String
        Get
            Return _texttouse
        End Get
        Set(ByVal value As String)
            _texttouse = value
            Invalidate()
        End Set
    End Property

    Private _captchalength As Integer = 8
    Public Property CaptchaTextLength() As Integer
        Get
            Return _captchalength
        End Get
        Set(ByVal value As Integer)
            _captchalength = value
            Invalidate()
        End Set
    End Property

    Private _numberoflines As Integer = 50
    Public Property NumberOfLines() As Integer
        Get
            Return _numberoflines
        End Get
        Set(ByVal value As Integer)
            _numberoflines = value
            Invalidate()
        End Set
    End Property
#End Region

#Region "Events"
    Public Sub New()
        SetStyle(ControlStyles.AllPaintingInWmPaint, True)
        SetStyle(ControlStyles.ResizeRedraw, True)
        SetStyle(ControlStyles.UserPaint, True)
        SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
        SetStyle(ControlStyles.SupportsTransparentBackColor, True)
    End Sub

    Protected Overrides Sub CreateHandle()
        MyBase.CreateHandle()
        Me.Size = New Size(241, 69)
        Me.BorderStyle = BorderStyle.FixedSingle
    End Sub

    Public CaptchaText As String = String.Empty
    Private rnd As New Random()
    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Dim B As New Bitmap(Width, Height)
        Dim G As Graphics = Graphics.FromImage(B)

        Dim BoxSize As New Rectangle(0, 0, Me.Width, Me.Height)
        Dim txtcolor As Brush = New SolidBrush(Color.FromArgb(rnd.[Next](160, 255), _textcolor))
        G.SmoothingMode = SmoothingMode.HighQuality

        G.Clear(BackColor)

        For I As Integer = 0 To _numberoflines - 1
            G.DrawLine(New Pen(Color.FromArgb(rnd.[Next](128, 255), CreateRandomColor())), rnd.[Next](0, BoxSize.Width), rnd.[Next](0, BoxSize.Height), rnd.[Next](BoxSize.Width), rnd.[Next](BoxSize.Height))
        Next

        Dim SFormat As New StringFormat()
        SFormat.Alignment = StringAlignment.Center
        SFormat.LineAlignment = StringAlignment.Center

        G.RotateTransform(rnd.[Next](-7, 7), MatrixOrder.Append)

        randomstr = CreateRandomString()
        G.DrawString(randomstr, Font, txtcolor, BoxSize, SFormat)
        CaptchaText = randomstr

        e.Graphics.DrawImage(B, 0, 0)
        G.Dispose()
        B.Dispose()
    End Sub
#End Region

#Region "Create Randoms"
    Private Function CreateRandomColor() As Color
        Return Color.FromArgb(100, rnd.[Next](255), rnd.[Next](255), rnd.[Next](255))
    End Function

    Private Function CreateRandomString() As String
        Dim buffer As Char() = New Char(_captchalength - 1) {}
        For i As Integer = 0 To _captchalength - 1
            If _texttouse = String.Empty Then
                Dim newtext As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz1234567890"
                buffer(i) = newtext(rnd.[Next](newtext.Length))
            Else
                buffer(i) = _texttouse(rnd.[Next](_texttouse.Length))
            End If
        Next
        Return New String(buffer)
    End Function
#End Region
End Class

How To Create And Write A Text File In Java

We will see how to create and write a text file in java so basically you get the idea after reading the title whatever when you run this program it creates a txt file and write some text inside so lets start making it , i am doing this in text editor so it's good id you also use a text editor ok now create a class and add the namespace io import java.io.*; and now write down the public static void main(String args[]) by the way don't forget to add the tags ({) now write down FileOutputStream Create; after that write this PrintStream Write; alright i will just put here the whole codes to make it easier for you

import java.io.*;
public class Create_txt 
{ 

 public static void main(String args[])
   {
    FileOutputStream Create;
    PrintStream Write;
    try
   {
    Create = new FileOutputStream("Text.txt");

    Write = new PrintStream( Create );

    Write.println ("Ultimate programming tutorials");

    Write.close();
    } 
    catch (Exception e)
    {
   System.err.println ("Cannot write txt file");
   }
  }
}

now when you run a new txt file will be created named "Text.txt" and Ultimate programming tutorials will be there inside the txt file if something stopped the process you will see "Cannot write txt file" in the console , i hope this is useful.