Posts

How to create a button dinamically in VB

How to create a button by code ? take a look here, this is very simple... create a form , add a button then double click on it : or you just call it from main form routine ; (as you wish...) ...were call the sub CreateButton() (add a image to resource if you want to have button with image _ but be careful whit image size is important)     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click         CreateButton()     End Sub then create a sub routine :  Sub CreateButton()         ' Create a Button object         ' Set Button properties ,location and size         dynamicButton.Location = New Point(10, 100)         dynamicButton.Height = 30         dynamicButton.Width = 100    ...

How to create a rectangle

Create a rectangle in VB  This method will use a graphics draw function so will draw over all object the rectangle. create a form , add a button and double-click on it and copy the next code in : createRectangle() like so :    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click         createRectangle()     End Sub then create a sub-form were the "magic" is happening :      Private Sub createRectangle()         Dim myPen As Pen         'set color and thickness of border         myPen = New Pen(Drawing.Color.DodgerBlue, 2)         Dim myGraphics As Graphics = Me.CreateGraphics         'give it a location         myGraphics.DrawRectangle(myPen, 5, 95, 400...

Mouse location (move object were is the mouse)

Simple code to demonstrate the location of cursor. Create a form , drag in a Panel and copy the next code in code editor : Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles_ Me.MouseDown         If e.Button = Windows.Forms.MouseButtons.Right Then             Panel1.Visible = True             Panel1.Location = New Point(e.X, e.Y)         Else             Panel1.Visible = False         End If     End Sub the Panel will apaire when the left button of mouse will be pressed.

MessageBox Result Buttons

Here is a simple code for interpret Buttons from a message box :             Select Case MsgBox ( "bal, bla... your text" , MsgBoxStyle . YesNoCancel , "Title..." ) Case MsgBoxResult . Yes MessageBox . Show ( "you choose Yes button" ) Case MsgBoxResult . Cancel MessageBox . Show ( " you choose Cancel button" ) Case MsgBoxResult . No MessageBox . Show ( " you choose NO button" ) End Select

Move bordless Form

Image
This is not a tutorial , I suppose you are at least a middle range VB programmer if you are need something like this : to create a Bord-less Form. You can customize the form how do you what, change color , add picture or other things. Here is a very simple code to move your Form without border and disable standard control box. Create a simple Form ,double click on it and write the next code :     Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None    ' this code will disable the main form bord    'or you can do this simple from Form properties... but I'm sure you choose this way because is much more easy to work whit UI in this meaner... Declare this above Form Load :     Public BeingDragged As Boolean = False     Public MouseDownX As Integer     Public MouseDownY As Integer Add from ToolBox  a ToolStrip ,double click on it and then choose MouseUp , MouseDown and MouseMove EVENT. we...

DataGridView - Add row from TextBoxs

A simple way to add  a new row to a DataGridView in Visual Basic from TextBoxses is with next command:  Button_click :  DataGridView1.Rows.Add(TextBox1.Text, TextBox2.Text, TextBox3.Text..and so on...) Of course there are many ways to do this ...but this is my easy way...

DataGridView - Deleting rows

There are many ways to delete a row from your datagridview , but I prefer to use the next command :         For Each row As DataGridViewRow In DataGridView1.SelectedRows             DataGridView1.Rows.Remove(row)         Next