In order to color the tabs of the tabcontrol in vb.net
just drop a tab control on a form with DrawMode = OwnerDrawFixed and put a couple of tab pages in it
1.
Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem
2.
3.
'Firstly we'll define some parameters.
4.
Dim CurrentTab As TabPage = TabControl1.TabPages(e.Index)
5.
Dim ItemRect As Rectangle = TabControl1.GetTabRect(e.Index)
6.
Dim FillBrush As New SolidBrush(Color.Red)
7.
Dim TextBrush As New SolidBrush(Color.White)
8.
Dim sf As New StringFormat
9.
sf.Alignment = StringAlignment.Center
10.
sf.LineAlignment = StringAlignment.Center
11.
12.
'If we are currently painting the Selected TabItem we'll
13.
'change the brush colors and inflate the rectangle.
14.
If CBool(e.State And DrawItemState.Selected) Then
15.
FillBrush.Color = Color.White
16.
TextBrush.Color = Color.Red
17.
ItemRect.Inflate(2, 2)
18.
End If
19.
20.
'Set up rotation for left and right aligned tabs
21.
If TabControl1.Alignment = TabAlignment.Left Or TabControl1.Alignment = TabAlignment.Right Then
22.
Dim RotateAngle As Single = 90
23.
If TabControl1.Alignment = TabAlignment.Left Then RotateAngle = 270
24.
Dim cp As New PointF(ItemRect.Left + (ItemRect.Width \ 2), ItemRect.Top + (ItemRect.Height \ 2))
25.
e.Graphics.TranslateTransform(cp.X, cp.Y)
26.
e.Graphics.RotateTransform(RotateAngle)
27.
ItemRect = New Rectangle(-(ItemRect.Height \ 2), -(ItemRect.Width \ 2), ItemRect.Height, ItemRect.Width)
28.
End If
29.
30.
'Next we'll paint the TabItem with our Fill Brush
31.
e.Graphics.FillRectangle(FillBrush, ItemRect)
32.
33.
'Now draw the text.
34.
e.Graphics.DrawString(CurrentTab.Text, e.Font, TextBrush, RectangleF.op_Implicit(ItemRect), sf)
35.
36.
'Reset any Graphics rotation
37.
e.Graphics.ResetTransform()
38.
39.
'Finally, we should Dispose of our brushes.
40.
FillBrush.Dispose()
41.
TextBrush.Dispose()
42.
End Sub
Search Results:
Wednesday, November 25, 2009
Monday, November 16, 2009
Copy rows from one grid view to another grid view.
I haven't tried this code on my own but my friend used this code to bring this functionality, I just wanted to share so that someone might get benifitted from this code
The code is in VB.NET
If (e.Control And e.KeyCode = Keys.V) Then
Dim s As String = Clipboard.GetText()
Dim lines As String()
lines = System.Text.RegularExpressions.Regex.Split(s, Environment.NewLine)
'Dim row As Integer = dgv.CurrentCell.RowIndex
'Dim col As Integer = dgv.CurrentCell.ColumnIndex
Dim row, col As Integer
For intRow As Integer = 0 To dgv.RowCount - 1
For intCol As Integer = 0 To dgv.ColumnCount - 1
If dgv.Rows(intRow).Cells(intCol).Selected = True Then
row = intRow
col = intCol
Exit For
End If
Next
If Not (row = 0 And col = 0) Then
Exit For
End If
Next
For intNextLine As Integer = 0 To (lines.Length - 1)
If (row < dgv.RowCount And lines(intNextLine).Length > 0) Then
Dim cells As String() = System.Text.RegularExpressions.Regex.Split(lines(intNextLine), "\t")
For i As Integer = 0 To cells.Length - 1
If (col + i < dgv.ColumnCount) Then
dgv.Rows(row).Cells(col + i).Value = cells(i)
End If
Next
row = row + 1
End If
Next
End If
The code is in VB.NET
If (e.Control And e.KeyCode = Keys.V) Then
Dim s As String = Clipboard.GetText()
Dim lines As String()
lines = System.Text.RegularExpressions.Regex.Split(s, Environment.NewLine)
'Dim row As Integer = dgv.CurrentCell.RowIndex
'Dim col As Integer = dgv.CurrentCell.ColumnIndex
Dim row, col As Integer
For intRow As Integer = 0 To dgv.RowCount - 1
For intCol As Integer = 0 To dgv.ColumnCount - 1
If dgv.Rows(intRow).Cells(intCol).Selected = True Then
row = intRow
col = intCol
Exit For
End If
Next
If Not (row = 0 And col = 0) Then
Exit For
End If
Next
For intNextLine As Integer = 0 To (lines.Length - 1)
If (row < dgv.RowCount And lines(intNextLine).Length > 0) Then
Dim cells As String() = System.Text.RegularExpressions.Regex.Split(lines(intNextLine), "\t")
For i As Integer = 0 To cells.Length - 1
If (col + i < dgv.ColumnCount) Then
dgv.Rows(row).Cells(col + i).Value = cells(i)
End If
Next
row = row + 1
End If
Next
End If
Wednesday, November 4, 2009
Code Sample to Combine two PDF files
How To: Combine PDFs Using InsertPages
Issue
How do I combine multiple PDFs into one PDF using Visual Basic?
Solution
This record contains VisualBasic code to demonstrate AcroExch.PDDoc InsertPages.
As far as InsertPages is concerned, the tricky part is to remember that the page number you will be inserting after is -1; in other words, you want to insert these pages before page 0, which is the first page of the document.
Private Sub Command1_Click()
Dim b As Boolean
Dim AcroPDDoc As CAcroPDDoc
Dim PDDoc As CAcroPDDoc
Set AcroPDDoc = CreateObject("AcroExch.PDDoc")
Set PDDoc = CreateObject("AcroExch.PDDoc")
b = PDDoc.Open("c:\testinsertpages.pdf")
b = AcroPDDoc.Open("c:\Tips.pdf")
b = AcroPDDoc.InsertPages(0, PDDoc, 0, 1, False)
b = AcroPDDoc.Save(1, "c:\Tips.pdf")
End Sub
Issue
How do I combine multiple PDFs into one PDF using Visual Basic?
Solution
This record contains VisualBasic code to demonstrate AcroExch.PDDoc InsertPages.
As far as InsertPages is concerned, the tricky part is to remember that the page number you will be inserting after is -1; in other words, you want to insert these pages before page 0, which is the first page of the document.
Private Sub Command1_Click()
Dim b As Boolean
Dim AcroPDDoc As CAcroPDDoc
Dim PDDoc As CAcroPDDoc
Set AcroPDDoc = CreateObject("AcroExch.PDDoc")
Set PDDoc = CreateObject("AcroExch.PDDoc")
b = PDDoc.Open("c:\testinsertpages.pdf")
b = AcroPDDoc.Open("c:\Tips.pdf")
b = AcroPDDoc.InsertPages(0, PDDoc, 0, 1, False)
b = AcroPDDoc.Save(1, "c:\Tips.pdf")
End Sub
Monday, November 2, 2009
Combine 2 PDF's Using vb.net
How To: Combine PDFs Using InsertPages
Issue
How do I combine multiple PDFs into one PDF using Visual Basic?
Solution
This record contains VisualBasic code to demonstrate AcroExch.PDDoc InsertPages.
As far as InsertPages is concerned, the tricky part is to remember that the page number you will be inserting after is -1; in other words, you want to insert these pages before page 0, which is the first page of the document.
Private Sub Command1_Click()
Dim b As Boolean
Dim AcroPDDoc As CAcroPDDoc
Dim PDDoc As CAcroPDDoc
Set AcroPDDoc = CreateObject("AcroExch.PDDoc")
Set PDDoc = CreateObject("AcroExch.PDDoc")
b = PDDoc.Open("c:\testinsertpages.pdf")
b = AcroPDDoc.Open("c:\Tips.pdf")
b = AcroPDDoc.InsertPages(0, PDDoc, 0, 1, False)
b = AcroPDDoc.Save(1, "c:\Tips.pdf")
End Sub
Issue
How do I combine multiple PDFs into one PDF using Visual Basic?
Solution
This record contains VisualBasic code to demonstrate AcroExch.PDDoc InsertPages.
As far as InsertPages is concerned, the tricky part is to remember that the page number you will be inserting after is -1; in other words, you want to insert these pages before page 0, which is the first page of the document.
Private Sub Command1_Click()
Dim b As Boolean
Dim AcroPDDoc As CAcroPDDoc
Dim PDDoc As CAcroPDDoc
Set AcroPDDoc = CreateObject("AcroExch.PDDoc")
Set PDDoc = CreateObject("AcroExch.PDDoc")
b = PDDoc.Open("c:\testinsertpages.pdf")
b = AcroPDDoc.Open("c:\Tips.pdf")
b = AcroPDDoc.InsertPages(0, PDDoc, 0, 1, False)
b = AcroPDDoc.Save(1, "c:\Tips.pdf")
End Sub
Subscribe to:
Posts (Atom)