I'm trying to get a number of frames from video using windows media player control. It was placed on Panel control.
Public Class Form1
Private b As New System.Drawing.Bitmap(160, 120)
Private rct As New Rectangle(0, 0, 160, 120)
Private pb As PictureBox
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
wm.URL = TextBox1.Text
wm.Ctlcontrols.play()
End Sub
Private Sub wm_OpenStateChange(sender As Object, e As AxWMPLib._WMPOCXEvents_OpenStateChangeEvent) Handles wm.OpenStateChange
If e.newState = 13 And wm.playState = 3 Then
Dim g As Graphics = Graphics.FromImage(b)
g.CopyFromScreen(PointToScreen(Panel1.Location), New Drawing.Point(0, 0), b.Size, CopyPixelOperation.SourceCopy)
pb = New PictureBox With {.Width = 160, .Height = 120, .Image = b}
FlowLayoutPanel1.Controls.Add(pb)
Try
While True
wm.Ctlcontrols.currentPosition += 20
Application.DoEvents()
If wm.Ctlcontrols.currentPosition > wm.currentMedia.duration - 20 Then
Exit Sub
End If
b = New Bitmap(160, 120)
g = Graphics.FromImage(b)
g.CopyFromScreen(PointToScreen(Panel1.Location), New Drawing.Point(0, 0), b.Size, CopyPixelOperation.SourceCopy)
pb = New PictureBox With {.Width = 160, .Height = 120, .Image = b}
FlowLayoutPanel1.Controls.Add(pb)
End While
Catch ex As Exception
End Try
End If
End Sub
End Class
As a result I want to get a number of frames in FlowLayoutPanel Control. But there are some 'Black Boxes' (repeated first frame). Any ideas?.. How can I make WMP to Update it's position and layout? My imagine is over.
Related
When I minimize the form, I lose all the contents drawn on the picture box. I want it to be retain on the picture box. Please help me in this regard.
The code can be seen below..
Private Sub ButtonDraw_Click(sender As Object, e As EventArgs) Handles ButtonDraw.Click
Dim g As Graphics = PictureBox1.CreateGraphics
Dim MyPen As New Pen(Color.Red)
MyPen.Width = 2
MyPen.DashStyle = DashStyle.Solid
g.TranslateTransform(PictureBox1.Width / 2, PictureBox1.Height / 2)
g.DrawEllipse(MyPen, New Rectangle(-150, -150, 300, 300))
End Sub
Example code, using e.Graphics in the Paint() event, as suggested by Jimi:
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
Dim g As Graphics = e.Graphics
Using MyPen As New Pen(Color.Red)
MyPen.Width = 2
MyPen.DashStyle = DashStyle.Solid
g.TranslateTransform(PictureBox1.Width / 2, PictureBox1.Height / 2)
g.DrawEllipse(MyPen, New Rectangle(-150, -150, 300, 300))
End Using
End Sub
I am writing a piece of code that when a button is pressed, it creates a picture box, but when you hold down the same key, that picture box needs to grow.
At first my code repeated the creation of the box, but now I have tried the code below and instead it creates it once, but at the end of the code. Does anyone know how some code to execute part of a key down code on the first instance that it is held down, and only once?
Private Class Form1
Dim KeyHolding As Boolean = False
Private Sub Btn_1_KeyDown(sender As Object, e As KeyEventArgs) Handles Btn_1.KeyDown
If Not KeyHolding Then 'the events which are activated once only when the key is pressed
KeyHolding = True
Dim PB As New PictureBox With {.Width = Btn_1.Width - 2, .Height = 10, .Top = Btn_1.Top + 20, .Left = Btn_1.Left + 1, .BackColor = Color.Cyan}
PB.Name = "PB_1"
TestPanel.Controls.Add(PB)
Else 'the events which are constantly done when the key is held
End If
End Sub
Private Sub Btn_1_KeyUp(sender As Object, e As KeyEventArgs) Handles Btn_1.KeyUp
Btn_1.BackColor = SystemColors.Control
KeyHolding = False
End Sub
Try this
Dim KeyHolding As Boolean = False
Dim PB As PictureBox
Private Sub Btn_1_KeyDown(sender As Object, e As KeyEventArgs) Handles Btn_1.KeyDown
If Not KeyHolding Then 'the events which are activated once only when the key is pressed
KeyHolding = True
PB = New PictureBox With {.Width = Btn_1.Width - 2, .Height = 10, .Top = Btn_1.Top + 20, .Left = Btn_1.Left + 1, .BackColor = Color.Cyan}
PB.Name = "PB_1"
TestPanel.Controls.Add(PB)
Else 'the events which are constantly done when the key is held
PB.Width += 10
PB.Height += 10
End If
End Sub
Private Sub Btn_1_KeyUp(sender As Object, e As KeyEventArgs) Handles Btn_1.KeyUp
Btn_1.BackColor = SystemColors.Control
End Sub
I am not sure how to create picture boxes on multiple rows in vb 2010. At the moment, I am only able to create them on
one row and one picture box on the second row. (Eventually I would like to add in 5 rows with 10 pictureboxes on each row) I have used the follow code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim xPosition As Integer = 20
Dim yPosition As Integer = 40
For i As Integer = 1 To 20
Dim pb As New PictureBox
With pb
If i < 20 Then
.Name = "PictureBox" & i.ToString
.SizeMode = PictureBoxSizeMode.Zoom
.Size = New Size(60, 60)
.Location = New Point(xPosition, yPosition)
.Image = My.Resources.Seating_No_Person
Me.Controls.Add(pb)
AddHandler pb.Click, AddressOf PictureBox_Click
xPosition += 70
ElseIf i > 10 Then
.Name = "PictureBox" & i.ToString
.SizeMode = PictureBoxSizeMode.Zoom
.Size = New Size(60, 60)
.Location = New Point(20, 120)
.Image = My.Resources.Seating_No_Person
Me.Controls.Add(pb)
AddHandler pb.Click, AddressOf PictureBox_Click
xPosition += 70
End If
Dim thisSeating As New Seating
With thisSeating
.SeatNumber = i
.PB = pb
.Occupied = False
End With
seatingList.Add(thisSeating)
End With
Next
End Sub
If anyone would be willing to help me or direct me to the correct path, I would be very grateful :)
Thanks in advance
Is this what you're looking for?
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim xPosition As Integer = 20
Dim yPosition As Integer = 40
For i As Integer = 1 To 5
For j As Integer = 1 To 10
Dim pb As New PictureBox
With pb
.Name = "PictureBox" & i.ToString
.SizeMode = PictureBoxSizeMode.Zoom
.Size = New Size(60, 60)
.Location = New Point(xPosition + (j * 70), yPosition + (i * 100))
.Image = My.Resources.Seating_No_Person
Me.Controls.Add(pb)
AddHandler pb.Click, AddressOf PictureBox_Click
Dim thisSeating As New Seating
With thisSeating
.SeatNumber = i
.PB = pb
.Occupied = False
End With
seatingList.Add(thisSeating)
End With
Next
Next
End Sub
I have used the following code in a program that I am designing to book seats. Each picturebox is a seat, and when each picturebox is clicked, the image should change from Seating_No_Person to Seating_With_Person to show that the seat has been selected. I am currently getting a problem with the changing image, as when clicked, none of the pictureboxes swap images. Anyone got any suggestions?
Thanks
Public Class Form1
Public Class Seating
Public SeatRow As Integer = 0
Public SeatColumn As Integer = 0
Public PB As PictureBox = Nothing
Public Occupied As Boolean = False
End Class
Private seatingList As New List(Of Seating)
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim xPosition As Integer = -50
Dim yPosition As Integer = -25
For i As Integer = 1 To 5
'Number of rows
For j As Integer = 1 To 10
Dim pb As New PictureBox
With pb
.Name = "PictureBox" & i.ToString & j.ToString
'Name of Picture box i.e. if i = 1 (row 1), j = 3 (column 3), name is PictureBox13
.SizeMode = PictureBoxSizeMode.Zoom
.Size = New Size(60, 60)
'Size of seat is 60 by 60
.Location = New Point(xPosition + (j * 70), yPosition + (i * 70))
'Location of picture box is: -50 + (columnnumber * 70), -25 + (rownumber * 70)
.Image = My.Resources.Seating_No_Person
Me.Controls.Add(pb)
AddHandler pb.Click, AddressOf PictureBox_Click
Dim thisSeating As New Seating
With thisSeating
.SeatRow = i
.SeatColumn = j
.PB = pb
.Occupied = True
End With
seatingList.Add(thisSeating)
End With
Next
Next
End Sub
Private Sub PictureBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim pb As PictureBox = DirectCast(sender, PictureBox)
Dim seatRowNum As Integer = CInt(pb.Name.Replace("PictureBox", ""))
Dim seatColumnNum As Integer = CInt(pb.Name.Replace("PictureBox", ""))
Dim qry = From seat As Seating In seatingList Where seat.SeatRow = seatRowNum And seat.SeatColumn = SeatColumnNum
If qry.Count = 1 Then
If qry.First.Occupied = True Then
pb.Image = My.Resources.Seating_No_Person
qry.First.Occupied = False
Else
pb.Image = My.Resources.Seating_With_Person
qry.First.Occupied = True
End If
End If
End Sub
End Class
I would suggest setting a breakpoint and debugging to see where you're going wrong. If you just call DirectCast(sender, PictureBox).Image = My.Resources.Seating_With_Person inside Private Sub PictureBox_Click it works, which suggests that there is problem with the logic inside your If block.
I'm converting from VB5 and am trying to get the equivalent of printer.NewPage in VB.NET.
My code is given below, but it simply prints the two lines on a single page.
The program prints two pages of calculated results (arrays etc), it is not reading and printing a file.
How do I get a second page?
Private Sub PrintGeneralReport()
Dim PrintPreviewSelected As Boolean = True
'Set the doc to print
Dim pDoc As New PrintDocument
pDoc.PrintController = New StandardPrintController 'turns off the printing page x of y dialog
'Get the printer to use
If Me.PrintDialog1.ShowDialog() = DialogResult.OK Then
pDoc.PrinterSettings.PrinterName = Me.PrintDialog1.PrinterSettings.PrinterName
'pDoc.DefaultPageSettings.Margins = New Margins(75, 50, 50, 50)
pDoc.DefaultPageSettings.Margins = New Margins(40, 10, 10, 10)
pDoc.OriginAtMargins = True
Else
pDoc = Nothing
Exit Sub
End If
' Install the PrintPage event handler.
AddHandler pDoc.PrintPage, AddressOf PrintGenReport
If PrintPreviewSelected Then
''print preview
PrintPreviewDialog1.Document = pDoc
PrintPreviewDialog1.UseAntiAlias = True
PrintPreviewDialog1.WindowState = FormWindowState.Maximized
PrintPreviewDialog1.ShowDialog()
Else
'just print
pDoc.Print()
End If
RemoveHandler pDoc.PrintPage, AddressOf PrintGenReport
End Sub
Private Sub PrintGenReport(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim fnt10 As Font = New Font("Courier New", 10, FontStyle.Regular)
e.Graphics.DrawString("Page 1", fnt10, Brushes.Black, 20, 100)
'ROARK1.Print_GeneralReportRK(Me, e)
e.HasMorePages = True
e.Graphics.DrawString("Page 2", fnt10, Brushes.Black, 20, 200)
'ROARK1.Print_MemberActions(e)
e.HasMorePages = False
End Sub
Try this:
Private PageNum As Integer = 1
Private Sub PrintGenReport(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim fnt10 As Font = New Font("Courier New", 10, FontStyle.Regular)
e.Graphics.DrawString("Page " & PageNum.ToString(), fnt10, Brushes.Black, 20, 100 * PageNum)
e.HasMorePages = (PageNum < 2)
PageNum += 1
End Sub
Note the PageNum variable is defined at the class level. You should also add a line to the PrintGeneralReport() method to set it back to 1 at the beginning of each print job.