Search This Blog
Friday, July 10, 2009
How to show LINE NUMBER in source code in vb.net
Tools -> Options -> Text Editor -> Basic -> General -> View -> [ ] "Line Numbers".
Thursday, July 9, 2009
Update ms ACCESS using vb.net
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Im_ETM\dbase\settings.mdb;")
'provider to be used when working with access database
If cn.State = ConnectionState.Closed Then
cn.Open()
' MessageBox.Show("open")
Else
MessageBox.Show("open already")
End If
If cn.State = ConnectionState.Open Then
'MessageBox.Show(objCh1_FULL.isON & " " & objCh1_FULL.isScale)
'QUERY TO UPDATE ALL SETTINGS
cmd = New OleDbCommand("UPDATE allSettings set Channel_on_off = '" & objCh1_FULL.isON & "', Channel_name= '" & objCh1_FULL.Name & "', Div_Shunt='" & objCh1_FULL.isModeDivider & "', Divider_Ratio='" & objCh1_FULL.Ratio & "', Amplitue='" & _
objCh1_FULL.Ampl & "', Measuring_Time='" & objCh1_FULL.MeasureTime & "', UnderShoot='" & objCh1_FULL.UnderShoot & "', Polarity='" & objCh1_FULL.isPositivePolarity & "', Trigger_Level ='" & objCh1_FULL.trigger & "', Suggested='" & objCh1_FULL.suggested & _
"', Suggested_Manual='" & objCh1_FULL.suggested_sel & "', Offset='" & objCh1_FULL.Offset & "', Internal_Divider='" & objCh1_FULL.InternalDivider & "', Max_Voltage='" & objCh1_FULL.maxVolt & "', BIL_Level='" & objCh1_FULL.billevel & _
"', Auto_Manual='" & objCh1_FULL.isScale & "' where File_type='Full_A'", cn)
dr = cmd.ExecuteReader
dr.Close()
cn.Close()
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Im_ETM\dbase\settings.mdb;")
'provider to be used when working with access database
If cn.State = ConnectionState.Closed Then
cn.Open()
' MessageBox.Show("open")
Else
MessageBox.Show("open already")
End If
If cn.State = ConnectionState.Open Then
'MessageBox.Show(objCh1_FULL.isON & " " & objCh1_FULL.isScale)
'QUERY TO UPDATE ALL SETTINGS
cmd = New OleDbCommand("UPDATE allSettings set Channel_on_off = '" & objCh1_FULL.isON & "', Channel_name= '" & objCh1_FULL.Name & "', Div_Shunt='" & objCh1_FULL.isModeDivider & "', Divider_Ratio='" & objCh1_FULL.Ratio & "', Amplitue='" & _
objCh1_FULL.Ampl & "', Measuring_Time='" & objCh1_FULL.MeasureTime & "', UnderShoot='" & objCh1_FULL.UnderShoot & "', Polarity='" & objCh1_FULL.isPositivePolarity & "', Trigger_Level ='" & objCh1_FULL.trigger & "', Suggested='" & objCh1_FULL.suggested & _
"', Suggested_Manual='" & objCh1_FULL.suggested_sel & "', Offset='" & objCh1_FULL.Offset & "', Internal_Divider='" & objCh1_FULL.InternalDivider & "', Max_Voltage='" & objCh1_FULL.maxVolt & "', BIL_Level='" & objCh1_FULL.billevel & _
"', Auto_Manual='" & objCh1_FULL.isScale & "' where File_type='Full_A'", cn)
dr = cmd.ExecuteReader
dr.Close()
cn.Close()
Connecting And Reading MS ACCESS using vb.net
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Im_ETM\dbase\settings.mdb;")
'provider to be used when working with access database
If cn.State = ConnectionState.Closed Then
cn.Open()
Else
MessageBox.Show("Opened Already")
End If
If cn.State = ConnectionState.Open Then
'MessageBox.Show("open")
cmd = New OleDbCommand("select * from allSettings where File_type='Full_A'", cn)
dr = cmd.ExecuteReader
readDatabase(cmd, cn, dr, objCh1_FULL)
cmd = New OleDbCommand("select * from allSettings where File_type='Full_B'", cn)
dr = cmd.ExecuteReader
If dr.HasRows Then
While dr.Read()
' MessageBox.Show(dr(0) & dr(1) & dr(2))
' loading data into TextBoxes by column index
objch.isON = dr(2)
' MessageBox.Show(objch.isON)
objch.name = dr(3)
objch.ismodedivider = dr(4)
end while
end if
dr.Close()
cn.Close()
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Im_ETM\dbase\settings.mdb;")
'provider to be used when working with access database
If cn.State = ConnectionState.Closed Then
cn.Open()
Else
MessageBox.Show("Opened Already")
End If
If cn.State = ConnectionState.Open Then
'MessageBox.Show("open")
cmd = New OleDbCommand("select * from allSettings where File_type='Full_A'", cn)
dr = cmd.ExecuteReader
readDatabase(cmd, cn, dr, objCh1_FULL)
cmd = New OleDbCommand("select * from allSettings where File_type='Full_B'", cn)
dr = cmd.ExecuteReader
If dr.HasRows Then
While dr.Read()
' MessageBox.Show(dr(0) & dr(1) & dr(2))
' loading data into TextBoxes by column index
objch.isON = dr(2)
' MessageBox.Show(objch.isON)
objch.name = dr(3)
objch.ismodedivider = dr(4)
end while
end if
dr.Close()
cn.Close()
Deleting a table and Copy all data from other table MS ACCESS using vb.net
Dim AccessConnection As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\dbase\settings.mdb;")
AccessConnection.Open()
Dim AccessCommand = New System.Data.OleDb.OleDbCommand("DELETE * from allSettings", AccessConnection)
AccessCommand.CommandType = CommandType.Text
AccessCommand.ExecuteNonQuery()
AccessCommand = New System.Data.OleDb.OleDbCommand("INSERT INTO allSettings SELECT * FROM allSettings_default", AccessConnection)
'AccessCommand = New System.Data.OleDb.OleDbCommand("SELECT * INTO allSettings FROM allSettings_default", AccessConnection)
AccessCommand.CommandType = CommandType.Text
AccessCommand.ExecuteNonQuery()
AccessConnection.Close()
AccessConnection.Open()
Dim AccessCommand = New System.Data.OleDb.OleDbCommand("DELETE * from allSettings", AccessConnection)
AccessCommand.CommandType = CommandType.Text
AccessCommand.ExecuteNonQuery()
AccessCommand = New System.Data.OleDb.OleDbCommand("INSERT INTO allSettings SELECT * FROM allSettings_default", AccessConnection)
'AccessCommand = New System.Data.OleDb.OleDbCommand("SELECT * INTO allSettings FROM allSettings_default", AccessConnection)
AccessCommand.CommandType = CommandType.Text
AccessCommand.ExecuteNonQuery()
AccessConnection.Close()
Wednesday, July 8, 2009
Hide Navigation Bar of the Blog
Add following code in the HTML code where other style code is written,
Use Edit HTML in custmization
#navbar-iframe {
height:0px;
visibility:hidden;
display:none;
}
Hide Navigation Bar of the Blog
Add following code in the HTML code where other style code is written,
Use Edit HTML in custmization
#navbar-iframe {
height:0px;
visibility:hidden;
display:none;
}
Page Setup, Print Preview & Print code in vb.net
Page Setup, Print Preview & Print code in vb.net
' PGAE SETUP CODE
'ADD Control PrintDocument, Pagesetup, PrintDialog
Private Sub ToolStripMenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem7.Click
'PAGE SETUP
With PageSetupDialog1
.PageSettings = PrintDocument1.DefaultPageSettings
End With
With PageSetupDialog1
.PageSettings = PrintDocument1.DefaultPageSettings
End With
Try
If PageSetupDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings
End If
Catch es As Exception
MessageBox.Show(es.Message)
End Try
End Sub
'PRINT PREVIEW CODE
Private Sub ToolStripMenuItem13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem13.Click
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.WindowState = FormWindowState.Maximized
PrintPreviewDialog1.ShowDialog()
End Sub
'PRINT CODE
Private Sub ToolStripMenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem5.Click
'PRINT
Try
PrintDocument1.Print()
Catch es As Exception
MessageBox.Show(es.Message)
End Try
'pd = New Printing.PrintDocument
' GetFormImage()
End Sub
'NOW PRINTPAGE EVENT HANDLER CODE means what to preview
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As _
System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
'PrintPage is the foundational printing event. This event gets fired for every
' page that will be printed
' MessageBox.Show("vikas")
' declaring a static variable to hold the position of the last printed char
Dim font As New Font("Verdana", 14)
' initializing the font to be used for printing
Dim PrintAreaHeight, PrintAreaWidth, marginLeft, marginTop As Int32
With print_Graphs_cpy2.PrintDocument1.DefaultPageSettings
' initializing local variables that contain the bounds of the printing area rectangle
PrintAreaHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom
PrintAreaWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
' initializing local variables to hold margin values that will serve
' as the X and Y coordinates for the upper left corner of the printing
' area rectangle.
marginLeft = .Margins.Left
marginTop = .Margins.Top
' X and Y coordinate
End With
If print_Graphs_cpy2.PrintDocument1.DefaultPageSettings.Landscape Then
Dim intTemp As Int32
intTemp = PrintAreaHeight
PrintAreaHeight = PrintAreaWidth
PrintAreaWidth = intTemp
' if the user selects landscape mode, swap the printing area height and width
End If
Dim intLineCount As Int32 = CInt(PrintAreaHeight / font.Height)
' calculating the total number of lines in the document based on the height of
' the printing area and the height of the font
Dim rectPrintingArea As New RectangleF(marginLeft, marginTop, PrintAreaWidth, PrintAreaHeight)
' initializing the rectangle structure that defines the printing area
Dim fmt As New StringFormat(StringFormatFlags.LineLimit
'LET THIS FUNCTION IS CREATE A IMAGE OF A FROM, A POST IS ALSO THERE FOR THIS, AND CREATE A IMAGE NAMED formImage
GetFormImage()
e.Graphics.DrawString("PRINTING", font, Brushes.Black, 4, 15)
e.Graphics.DrawImage( formImage, 4, 100)
'YOU CAN ADD ANY OTHER THINGS LIKE THAT
End Sub
' PGAE SETUP CODE
'ADD Control PrintDocument, Pagesetup, PrintDialog
Private Sub ToolStripMenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem7.Click
'PAGE SETUP
With PageSetupDialog1
.PageSettings = PrintDocument1.DefaultPageSettings
End With
With PageSetupDialog1
.PageSettings = PrintDocument1.DefaultPageSettings
End With
Try
If PageSetupDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings
End If
Catch es As Exception
MessageBox.Show(es.Message)
End Try
End Sub
'PRINT PREVIEW CODE
Private Sub ToolStripMenuItem13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem13.Click
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.WindowState = FormWindowState.Maximized
PrintPreviewDialog1.ShowDialog()
End Sub
'PRINT CODE
Private Sub ToolStripMenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem5.Click
Try
PrintDocument1.Print()
Catch es As Exception
MessageBox.Show(es.Message)
End Try
'pd = New Printing.PrintDocument
' GetFormImage()
End Sub
'NOW PRINTPAGE EVENT HANDLER CODE means what to preview
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As _
System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
'PrintPage is the foundational printing event. This event gets fired for every
' page that will be printed
' MessageBox.Show("vikas")
' declaring a static variable to hold the position of the last printed char
Dim font As New Font("Verdana", 14)
' initializing the font to be used for printing
Dim PrintAreaHeight, PrintAreaWidth, marginLeft, marginTop As Int32
With print_Graphs_cpy2.PrintDocument1.DefaultPageSettings
' initializing local variables that contain the bounds of the printing area rectangle
PrintAreaHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom
PrintAreaWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
' initializing local variables to hold margin values that will serve
' as the X and Y coordinates for the upper left corner of the printing
' area rectangle.
marginLeft = .Margins.Left
marginTop = .Margins.Top
' X and Y coordinate
End With
If print_Graphs_cpy2.PrintDocument1.DefaultPageSettings.Landscape Then
Dim intTemp As Int32
intTemp = PrintAreaHeight
PrintAreaHeight = PrintAreaWidth
PrintAreaWidth = intTemp
' if the user selects landscape mode, swap the printing area height and width
End If
Dim intLineCount As Int32 = CInt(PrintAreaHeight / font.Height)
' calculating the total number of lines in the document based on the height of
' the printing area and the height of the font
Dim rectPrintingArea As New RectangleF(marginLeft, marginTop, PrintAreaWidth, PrintAreaHeight)
' initializing the rectangle structure that defines the printing area
Dim fmt As New StringFormat(StringFormatFlags.LineLimit
'LET THIS FUNCTION IS CREATE A IMAGE OF A FROM, A POST IS ALSO THERE FOR THIS, AND CREATE A IMAGE NAMED formImage
GetFormImage()
e.Graphics.DrawString("PRINTING", font, Brushes.Black, 4, 15)
e.Graphics.DrawImage( formImage, 4, 100)
'YOU CAN ADD ANY OTHER THINGS LIKE THAT
End Sub
How to create a image of form in vb.net?
'DLL FUNCTION USED TO CREATE A FORM IMGAE
Public Declare Function BitBlt Lib "gdi32.dll" Alias _
"BitBlt" (ByVal hdcDest As IntPtr, _
ByVal nXDest As Integer, ByVal nYDest As _
Integer, ByVal nWidth As Integer, _
ByVal nHeight As Integer, ByVal _
hdcSrc As IntPtr, ByVal nXSrc As Integer, _
ByVal nYSrc As Integer, _
ByVal dwRop As System.Int32) As Long
Public formImage As Bitmap
Public Sub GetFormImage()
'CRATING A IMAGE OF THE FORM TO PRINT
' print_Graphs_cpy2 is a form
Dim g As Graphics = print_Graphs_cpy2.CreateGraphics
Dim s As Size = print_Graphs_cpy2.Size
formImage = New Bitmap(s.Width - 50, s.Height, g)
Dim mg As Graphics = Graphics.FromImage(formImage)
Dim dc1 As IntPtr = g.GetHdc
Dim dc2 As IntPtr = mg.GetHdc
' added code to compute and capture the form
' title bar and borders
Dim widthDiff As Integer = _
(print_Graphs_cpy2.Width - print_Graphs_cpy2.ClientRectangle.Width - 50)
Dim heightDiff As Integer = _
(print_Graphs_cpy2.Height - print_Graphs_cpy2.ClientRectangle.Height)
Dim borderSize As Integer = widthDiff \ 2
Dim heightTitleBar As Integer = heightDiff - borderSize
BitBlt(dc2, 0, 0, _
print_Graphs_cpy2.ClientRectangle.Width - 50 + widthDiff, _
print_Graphs_cpy2.ClientRectangle.Height + heightDiff, dc1, _
0 - borderSize, 0 - heightTitleBar, 13369376)
g.ReleaseHdc(dc1)
mg.ReleaseHdc(dc2)
formImage.Save("c:\grpah.jpg")
End Sub
Public Declare Function BitBlt Lib "gdi32.dll" Alias _
"BitBlt" (ByVal hdcDest As IntPtr, _
ByVal nXDest As Integer, ByVal nYDest As _
Integer, ByVal nWidth As Integer, _
ByVal nHeight As Integer, ByVal _
hdcSrc As IntPtr, ByVal nXSrc As Integer, _
ByVal nYSrc As Integer, _
ByVal dwRop As System.Int32) As Long
Public formImage As Bitmap
Public Sub GetFormImage()
'CRATING A IMAGE OF THE FORM TO PRINT
' print_Graphs_cpy2 is a form
Dim g As Graphics = print_Graphs_cpy2.CreateGraphics
Dim s As Size = print_Graphs_cpy2.Size
formImage = New Bitmap(s.Width - 50, s.Height, g)
Dim mg As Graphics = Graphics.FromImage(formImage)
Dim dc1 As IntPtr = g.GetHdc
Dim dc2 As IntPtr = mg.GetHdc
' added code to compute and capture the form
' title bar and borders
Dim widthDiff As Integer = _
(print_Graphs_cpy2.Width - print_Graphs_cpy2.ClientRectangle.Width - 50)
Dim heightDiff As Integer = _
(print_Graphs_cpy2.Height - print_Graphs_cpy2.ClientRectangle.Height)
Dim borderSize As Integer = widthDiff \ 2
Dim heightTitleBar As Integer = heightDiff - borderSize
BitBlt(dc2, 0, 0, _
print_Graphs_cpy2.ClientRectangle.Width - 50 + widthDiff, _
print_Graphs_cpy2.ClientRectangle.Height + heightDiff, dc1, _
0 - borderSize, 0 - heightTitleBar, 13369376)
g.ReleaseHdc(dc1)
mg.ReleaseHdc(dc2)
formImage.Save("c:\grpah.jpg")
End Sub
Save a ZedGraph as a picture in vb.net
Dim objBitmap As Bitmap = New Bitmap(850, 1100)
Dim g As Graphics = Graphics.FromImage(objBitmap)
Public PB As System.Windows.Forms.PictureBox
PB.Image = ZedGraphControlA.GetImage()
g.DrawImage(PB.Image, 0, 747)
objBitmap.Save("c:\Graph.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
Dim g As Graphics = Graphics.FromImage(objBitmap)
Public PB As System.Windows.Forms.PictureBox
PB.Image = ZedGraphControlA.GetImage()
g.DrawImage(PB.Image, 0, 747)
objBitmap.Save("c:\Graph.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
Create a PDF using iTextSharp in C#
Imports iTextSharp
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.text.xml
Imports System.Text
Imports System.IO
'download and add as reference iTextSharp DLL
'//Create Document class obejct and set its size to letter and give space left, right, Top, Bottom Margin
'Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
' Try
'{
'PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("c:\\Test11.pdf", FileMode.Create));
'//Open Document to write
'doc.Open;
'//Write some content
'Paragraph paragraph = new Paragraph("This is my first line using Paragraph.");
'Phrase pharse = new Phrase("This is my second line using Pharse.");
'Chunk chunk = new Chunk(" This is my third line using Chunk.");
'// Now add the above created text using different class object to our pdf document
'doc.Add(paragraph);
'doc.Add(pharse);
'doc.Add(chunk);
'}
'catch (DocumentException dex)
'{
'//Handle document exception
'}
'catch (IOException ioex)
'{
'//Handle IO exception
'}
'catch (Exception ex)
'{
'//Handle Other Exception
'}
' Finally
'{
'doc.Close(); //Close document
'}
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.text.xml
Imports System.Text
Imports System.IO
'download and add as reference iTextSharp DLL
'//Create Document class obejct and set its size to letter and give space left, right, Top, Bottom Margin
'Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
' Try
'{
'PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("c:\\Test11.pdf", FileMode.Create));
'//Open Document to write
'doc.Open;
'//Write some content
'Paragraph paragraph = new Paragraph("This is my first line using Paragraph.");
'Phrase pharse = new Phrase("This is my second line using Pharse.");
'Chunk chunk = new Chunk(" This is my third line using Chunk.");
'// Now add the above created text using different class object to our pdf document
'doc.Add(paragraph);
'doc.Add(pharse);
'doc.Add(chunk);
'}
'catch (DocumentException dex)
'{
'//Handle document exception
'}
'catch (IOException ioex)
'{
'//Handle IO exception
'}
'catch (Exception ex)
'{
'//Handle Other Exception
'}
' Finally
'{
'doc.Close(); //Close document
'}
Create a PDF using iTextSharp in vb.net
Imports iTextSharp
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.text.xml
Imports System.Text
Imports System.IO
'Download the iTextSharp DLL in add as reference
Public Sub create_pdf()
Dim rct As New Rectangle(850, 1100)
'Create Document class obejct and set its size to letter and give space left, right, Top, Bottom Margin
'file_name_pdf variable name of the pdf set as per necessity, rct is size of pdf
Dim doc As New Document(rct, 3, 3, 3, 3)
Try
If file_name_pdf <> "" Then
Dim file As System.IO.FileInfo = New FileInfo(file_name_pdf)
Dim wri As PdfWriter = PdfWriter.GetInstance(doc, New FileStream(file.DirectoryName & "\" & file.Name & ".pdf", FileMode.Create))
Else
Dim wri As PdfWriter = PdfWriter.GetInstance(doc, New FileStream("c:\Graph.pdf", FileMode.Create))
End If
'Open Document to write
doc.Open()
'Write some content
Dim paragraph As New Paragraph("Paragraph.")
Dim pharse As New Phrase("Pharse.")
Dim chunk As New Chunk(" Chunk.")
' Dim img As iTextSharp.text.Image = Nothing
' Dim underContent As iTextSharp.text.pdf.PdfContentByte = Nothing
' Dim rect As iTextSharp.text.Rectangle = Nothing
doc.Add(paragraph)
doc.Add(pharse)
doc.Add(chunk)
Dim gif As Image
'file_name_pdf variable name of the pdf set as per necessity
If file_name_pdf <> "" Then
'MessageBox.Show(file_name_pdf)
gif = Image.GetInstance(file_name_pdf + ".jpg")
Else
gif = Image.GetInstance("c:\" + "Graph.jpg")
End If
'Adding a gif file
doc.Add(gif)
Catch dex As DocumentException
'Handle document exception
Catch ioex As IOException
'Handle IO exception
Catch ex As Exception
'Handle Other Exception
Finally
'Close document
doc.Close()
End Try
End Sub
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.text.xml
Imports System.Text
Imports System.IO
'Download the iTextSharp DLL in add as reference
Public Sub create_pdf()
Dim rct As New Rectangle(850, 1100)
'Create Document class obejct and set its size to letter and give space left, right, Top, Bottom Margin
'file_name_pdf variable name of the pdf set as per necessity, rct is size of pdf
Dim doc As New Document(rct, 3, 3, 3, 3)
Try
If file_name_pdf <> "" Then
Dim file As System.IO.FileInfo = New FileInfo(file_name_pdf)
Dim wri As PdfWriter = PdfWriter.GetInstance(doc, New FileStream(file.DirectoryName & "\" & file.Name & ".pdf", FileMode.Create))
Else
Dim wri As PdfWriter = PdfWriter.GetInstance(doc, New FileStream("c:\Graph.pdf", FileMode.Create))
End If
'Open Document to write
doc.Open()
'Write some content
Dim paragraph As New Paragraph("Paragraph.")
Dim pharse As New Phrase("Pharse.")
Dim chunk As New Chunk(" Chunk.")
' Dim img As iTextSharp.text.Image = Nothing
' Dim underContent As iTextSharp.text.pdf.PdfContentByte = Nothing
' Dim rect As iTextSharp.text.Rectangle = Nothing
doc.Add(paragraph)
doc.Add(pharse)
doc.Add(chunk)
Dim gif As Image
'file_name_pdf variable name of the pdf set as per necessity
If file_name_pdf <> "" Then
'MessageBox.Show(file_name_pdf)
gif = Image.GetInstance(file_name_pdf + ".jpg")
Else
gif = Image.GetInstance("c:\" + "Graph.jpg")
End If
'Adding a gif file
doc.Add(gif)
Catch dex As DocumentException
'Handle document exception
Catch ioex As IOException
'Handle IO exception
Catch ex As Exception
'Handle Other Exception
Finally
'Close document
doc.Close()
End Try
End Sub
Tuesday, July 7, 2009
Convert date and time in the desired format in vb,net
dd/MM/yyyy
String.Format("{0:dd/MM/yyyy}", DateTime.Now)
MM/dd/yyyy
String.Format("{0:MM/dd/yyyy}", DateTime.Now)
dd/MM/yy
String.Format("{0:dd/MM/yy}", DateTime.Now)
time
String.Format("{0:t}", DateTime.Now)
With Day, month
String.Format("{0:F}", DateTime.Now)
i.eFriday, December 19, 2008 10:48:46 AM
String.Format("{0:dd/MM/yyyy}", DateTime.Now)
MM/dd/yyyy
String.Format("{0:MM/dd/yyyy}", DateTime.Now)
dd/MM/yy
String.Format("{0:dd/MM/yy}", DateTime.Now)
time
String.Format("{0:t}", DateTime.Now)
With Day, month
String.Format("{0:F}", DateTime.Now)
i.eFriday, December 19, 2008 10:48:46 AM
Monday, July 6, 2009
Add a Control array at run time using vb.net e.g picturebox
Public PRINT_GRAPH_NOS As Integer = 12
Public PB(14) As System.Windows.Forms.PictureBox
Public Sub create_graph_image()
PB = New System.Windows.Forms.PictureBox(14) {}
For i As Integer = 0 To PRINT_GRAPH_NOS - 1
Me.Controls.Add(PB(i))
PB(i) = New PictureBox
With PB(i)
.Size = New Size(5, 5)
.BackColor = Color.Red
.Visible = True
.BringToFront()
.Show()
PB(i).Tag = "filename"
AddHandler PB(i).Paint, AddressOf PictureboxAdd
End With
Next
end sub
Public Sub PictureboxAdd(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
Dim p As Windows.Forms.PictureBox = DirectCast(sender, Windows.Forms.PictureBox)
Dim fnt As New Font("Times New Roman", 10, FontStyle.Regular)
e.Graphics.DrawString(p.Tag, fnt, Brushes.Black, 20, 20)
End Sub
Public PB(14) As System.Windows.Forms.PictureBox
Public Sub create_graph_image()
PB = New System.Windows.Forms.PictureBox(14) {}
For i As Integer = 0 To PRINT_GRAPH_NOS - 1
Me.Controls.Add(PB(i))
PB(i) = New PictureBox
With PB(i)
.Size = New Size(5, 5)
.BackColor = Color.Red
.Visible = True
.BringToFront()
.Show()
PB(i).Tag = "filename"
AddHandler PB(i).Paint, AddressOf PictureboxAdd
End With
Next
end sub
Public Sub PictureboxAdd(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
Dim p As Windows.Forms.PictureBox = DirectCast(sender, Windows.Forms.PictureBox)
Dim fnt As New Font("Times New Roman", 10, FontStyle.Regular)
e.Graphics.DrawString(p.Tag, fnt, Brushes.Black, 20, 20)
End Sub
Add a Control at run time using vb.net e.g picturebox
'Declare a picturebox
Public PictureBox2 As New Windows.Forms.PictureBox
'e.g Adding a zed graph as image in that picturebox
Public Sub create_graph_image()
With PictureBox2
.Height = 100
.Width = 100
.BackColor = Color.BlanchedAlmond
.Visible = True
.BorderStyle = BorderStyle.Fixed3D
PictureBox2.Tag = "filename"
AddHandler PictureBox2.Paint, AddressOf PictureboxAdd
End With
Me.Controls.Add(PictureBox2)
' Dim g As Graphics
' g = CType(PictureBox2, PictureBox).CreateGraphics
PictureBox2.Image = Me.ZedGraphControlB.GetImage()
' PictureBox2.Visible = True
End Sub
Public Sub PictureboxAdd(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
Dim p As Windows.Forms.PictureBox = DirectCast(sender, Windows.Forms.PictureBox)
Dim fnt As New Font("Times New Roman", 10, FontStyle.Regular)
e.Graphics.DrawString(p.Tag, fnt, Brushes.Black, 20, 20)
End Sub
Public PictureBox2 As New Windows.Forms.PictureBox
'e.g Adding a zed graph as image in that picturebox
Public Sub create_graph_image()
With PictureBox2
.Height = 100
.Width = 100
.BackColor = Color.BlanchedAlmond
.Visible = True
.BorderStyle = BorderStyle.Fixed3D
PictureBox2.Tag = "filename"
AddHandler PictureBox2.Paint, AddressOf PictureboxAdd
End With
Me.Controls.Add(PictureBox2)
' Dim g As Graphics
' g = CType(PictureBox2, PictureBox).CreateGraphics
PictureBox2.Image = Me.ZedGraphControlB.GetImage()
' PictureBox2.Visible = True
End Sub
Public Sub PictureboxAdd(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
Dim p As Windows.Forms.PictureBox = DirectCast(sender, Windows.Forms.PictureBox)
Dim fnt As New Font("Times New Roman", 10, FontStyle.Regular)
e.Graphics.DrawString(p.Tag, fnt, Brushes.Black, 20, 20)
End Sub
Saturday, July 4, 2009
Create a Password Textbox in vb.net
This can be easily done by setting the PasswordChar Property of Textbox
Set that propety to a PASSWORD char to be displayed
OR
write this code, after this textbox will show that particular char
Friday, July 3, 2009
Downloading, Installing and Configuring Apache and php on Windows
1) Downloading
Apache
http://httpd.apache.org/download.cgi
Download -- Win32 Binary including OpenSSL 0.9.8i (MSI Installer)
Php
http://in2.php.net/get/php-5.2.8-win32-installer.msi/from/a/mirror
Download -- in.php.net
2) Installing
Apache
Double click on msi installer and follow the instruction.
Give your machines hostname and domain name when asked.
Finish it.
Php
Double click on php installer and follow the instruction.
Select the apache server when asked form the server list.
Finish it.
3)Configuring
Apache
Write "localhost" in browser - It shows like "It Works"
Now configure the Apache for php Add the lines in httpd.conf (in conf dir)
#Add this line where other LoadModule line are, this is for apache2.2, this dll comes when u installed php, in php folder, check the path as well
LoadModule php5_module "c:/Program Files/php/php5apache2_2.dll"
#DocumentRoot where you php files must be placed
#by default is, and can be changed to desired folder
DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
#Add this line where other AddType statements are
AddType application/x-httpd-php .php
#AT the end of file add this, check php path
PHPIniDir "c:/Program Files/php"
Now restart the apache server, double click on
ApacheMonitor.exe
in bin folder of Apache dir, if already start, Maximise it from the Task bars icons
Restart the apache to make changes effective.
make a file php file eg v.php
write in it
phpinfo();
save file in C:/Program Files/Apache Software Foundation/Apache2.2/htdocs, which is default php folder
Now type in browser to get result....
localhost/v.php
Apache
http://httpd.apache.org/download.cgi
Download -- Win32 Binary including OpenSSL 0.9.8i (MSI Installer)
Php
http://in2.php.net/get/php-5.2.8-win32-installer.msi/from/a/mirror
Download -- in.php.net
2) Installing
Apache
Double click on msi installer and follow the instruction.
Give your machines hostname and domain name when asked.
Finish it.
Php
Double click on php installer and follow the instruction.
Select the apache server when asked form the server list.
Finish it.
3)Configuring
Apache
Write "localhost" in browser - It shows like "It Works"
Now configure the Apache for php Add the lines in httpd.conf (in conf dir)
#Add this line where other LoadModule line are, this is for apache2.2, this dll comes when u installed php, in php folder, check the path as well
LoadModule php5_module "c:/Program Files/php/php5apache2_2.dll"
#DocumentRoot where you php files must be placed
#by default is, and can be changed to desired folder
DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
#Add this line where other AddType statements are
AddType application/x-httpd-php .php
#AT the end of file add this, check php path
PHPIniDir "c:/Program Files/php"
Now restart the apache server, double click on
ApacheMonitor.exe
in bin folder of Apache dir, if already start, Maximise it from the Task bars icons
Restart the apache to make changes effective.
make a file php file eg v.php
write in it
phpinfo();
save file in C:/Program Files/Apache Software Foundation/Apache2.2/htdocs, which is default php folder
Now type in browser to get result....
localhost/v.php
Thursday, July 2, 2009
Does C, C++ support unsigned float?
No, because there is no equivalent machine code operations for the CPU to execute.
Comment?
Comment?
Subscribe to:
Comments (Atom)












