MediaPlayer.MediaPlayer: How do I use the Volume property? - vb.net

The Volume property from MediaPlayer.MediaPlayer is really confusing me. I googled the definition and found this which I think is the right class. It says the Volume property is a Double that excepts any number between 0 and 1, and it's default is 0.5. However, when I set it to 0.5 or any other number within 0 and 1, it says it does not fall within the expected range.
Here is how it is defined and how I tried to adjust the volume. I have the event as MouseUp because I could not get ValueChanged or Scroll to work properly. Any tips on that would be greatly appreciated.
Dim Player1 As MediaPlayer.MediaPlayer = New MediaPlayer.MediaPlayer
Private Sub SndMasterSlider_MouseUp(sender As Object, e As EventArgs) Handles SndMasterSlider.MouseUp
Player1.Volume = SndMasterSlider.Value / 100
Debug.Print(Player1.Volume)
End Sub

Related

how do I make a picture box go down in vb

I've updated the code and now it says that index was outside of the bounds of the array and also I'm in cs1 in high school, and accidentally made this account using my school google account.
I have included the code specific to moving the bricks down (by just a little), the code for the array, and the code for the entire timer block which as you can see is very organized with regions
Dim newbrickx, newbricky As Integer
newbrickx = bricks(i).Location.X
newbricky = bricks(i).Location.Y + 10
'left wall
If (lblball.Location.X >= Me.ClientSize.Width - lblball.Width) Then
bricks(i).Location = New Point(newbrickx, newbricky)
End If
'right wall
If (lblball.Location.X = 0) Then
bricks(i).Location = New Point(newbrickx, newbricky)
End If
the array (in the form load event)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
bricks = New PictureBox() {PictureBox1, PictureBox2, PictureBox3, PictureBox4, PictureBox5, PictureBox6, PictureBox7, PictureBox8}
End Sub
I don't have the reputation to write comments yet, so I do it this way.
I assume bricks is an array containing your pictureboxes. So, inside the conditional block you can assign the new position like this:
bricks(i).Location = New Point(newbrickx, newbricky)
And as commented before you should probably also check for the y coordinates to make sure it is not out of bounds.

How to do subtract from two textbox on textchanged event in VB.Net

I am new in vb.net. I have two text box. txtCash, txtCreditAmt.
look at the code sample. it is working but the problem i am facing problem when i am going to type decimal number. when i tried to type 14 is okay but when i tried to type 14.98 it is typing 1498. very surprisingly point(.) not accepting at all. in vb6 same type of code are working fine. How i can solve this issue?
Private Sub txtCash_TextChanged(sender As Object, e As EventArgs) Handles txtCash.TextChanged
txtCreditAmt.Text = Val(lblTotalAmt.Text) - Val(txtCash.Text)
txtCashTenered.Text = Val(txtCash.Text) + Val(txtCreditAmt.Text)
SendKeys.Send("{End}")
End Sub
You need to be careful of the CultureInfo as in some regions numbers are written:
123,456,789.00
But in other regions:
123,456,789 00
For more information you can use either the CurrentCulture or the InvariantCulture
Thus I would propose something like this:
Private Sub txtCash_TextChanged(sender As Object, e As EventArgs) Handles txtCash.TextChanged
Dim WantedCulture As Globalization.CultureInfo = Globalization.CultureInfo.InvariantCulture
txtCreditAmt.Text = Decimal.Parse(lblTotalAmt.Text, WantedCulture) - Decimal.Parse(txtCash.Text, WantedCulture)
txtCashTenered.Text = Decimal.Parse(txtCash.Text, WantedCulture) + Decimal.Parse(txtCreditAmt.Text, WantedCulture)
SendKeys.Send("{End}")
End Sub
CultureInfo MSDN
You can use globalization namespace, https://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.numberdecimalseparator(v=vs.110).aspx. But for some reason, sometimes i usually solve this by using Replace(txtCash.Text, ".", ",") or Replace(txtCash.Text, ",", ".") depending on how is configured your regional settings.

VB.NET Cartesian Coordinate System

I'd like to make a Cartesian Coordinate System in a Windows form and be able to plot (x,y) coordinates in it.
How do i do this? I already did my research but unfortunately i only land on "charts" and not the Cartesian plane.
Any links regarding my problem will help ... thanks ...
In WinForms, you can use a PictureBox control and then draw on it using primitives such as DrawLine, DrawEllipse, etc. The following SO question contains an example:
how to draw drawings in picture box
In WPF, you can use a Canvas control similarly:
WPF canvas drawing with Graphics
If you want automatic axes and labeling, Charts are indeed the way to go. For your use case, a point chart seems like the right solution:
Point Chart (Chart Controls)
You should create a custom UserControl and use the Paint even to draw on the surface of the control. The Paint event provides you with a Graphics object which you can use to draw the graph. The big thing to know, however, is that you will need to swap your Y axis. In windows, the top-left of the screen is 0,0 rather than the bottom-left.
So, for instance, the following code will draw the x and y axis of a graph on a contorl:
Public Class CartesianGraph
Public Property BottomLeftExtent() As Point
Get
Return _bottomLeftExtent
End Get
Set(ByVal value As Point)
_bottomLeftExtent = value
End Set
End Property
Private _bottomLeftExtent As Point = New Point(-100, -100)
Public Property TopRightExtent() As Point
Get
Return _topRightExtent
End Get
Set(ByVal value As Point)
_topRightExtent = value
End Set
End Property
Private _topRightExtent As Point = New Point(100, 100)
Private Sub CartesianGraph_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim extentHeight As Integer = _topRightExtent.Y - _bottomLeftExtent.Y
Dim extentWidth As Integer = _topRightExtent.X - _bottomLeftExtent.X
If (extentHeight <> 0) And (extentWidth <> 0) Then
If (_bottomLeftExtent.Y <= 0) And (_topRightExtent.Y >= 0) Then
Dim xAxis As Integer = e.ClipRectangle.Height - (_bottomLeftExtent.Y * -1 * e.ClipRectangle.Height \ extentHeight)
e.Graphics.DrawLine(New Pen(ForeColor), 0, xAxis, e.ClipRectangle.Width, xAxis)
End If
If (_bottomLeftExtent.X <= 0) And (_topRightExtent.X >= 0) Then
Dim yAxis As Integer = e.ClipRectangle.Width * _bottomLeftExtent.X * -1 \ extentWidth
e.Graphics.DrawLine(New Pen(ForeColor), yAxis, 0, yAxis, e.ClipRectangle.Height)
End If
End If
End Sub
End Class
.NET has a charting library, but there are a few open source projects that do this sort of thing quite well. If you want to plot coordinates Zedgraph makes this relatively easy and is quite flexible.
this ZedGraph Example gives a great introduction
Dynamic Data Display is also worth looking at, but it is WPF, not Windows Forms

Getting Data from WinForms ListView Control

I need to retrieve my data from a ListView control set up in Details mode with 5 columns.
I tried using this code:
MessageBox.Show(ManageList.SelectedItems(0).Text)
And it works, but only for the first selected item (item 0). If I try this:
MessageBox.Show(ManageList.SelectedItems(2).Text)
I get this error:
InvalidArgument=Value of '2' is not valid for 'index'. Parameter name: index
I have no clue how I can fix this, any help?
Edit: Sorry, should have said, I'm using Windows.Forms :)
Right, from what I've tested:
Private Sub Button1Click(ByVal sender As Object, ByVal e As EventArgs)
For index As Integer = 0 To Me.listView1.SelectedItems.Count - 1
MessageBox.Show(Me.listView1.SelectedItems(index).Text)
Next
End Sub
(items added like this:)
For i As Integer = 0 To 99
Me.listView1.Items.Add(String.Format("test{0}", i))
Next
It just works.
So are you sure you have selected more than 1 item?
Could you please show us more code? :)

Data grid view header Grid color

This is a VB .NET application where we are showing the output of a SQL statement in a Datagrid view. I'm using .NET 2005.
We need to get the separators of the headers on the grid control to be the same colors as the GridColor on the form.
We've tried looking through all of the properties of the DataGridView control, and found some interesting things that looked promising such as the DataGridViewAdvancedHeaderStyle, and DataGridViewHeaderBorderStyle, but none of it seems to allow you to change the colors on it.
Does anyone know how to do this without remaking the entire thing with a GDI+ control?
Well, I never did find a property for this, so I ended up creating a custom component, and overloading the OnPaint event handler to draw a line over the existing one.
Here is the code for it if anyone else ever comes across this post looking for a solution:
Private Sub CustomDataGridView_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim g As Graphics = e.Graphics
Dim pen As New Pen(Me.GridColor)
Dim TWidth As Integer = 2
Dim HeaderWidth As Integer = 0
If Me.RowHeadersVisible Then
HeaderWidth = Me.RowHeadersWidth
End If
For Each column As DataGridViewColumn In Me.Columns
Dim x As Integer = HeaderWidth + TWidth - 1
TWidth += column.Width
Dim top As Integer = column.HeaderCell.ContentBounds.Top
Dim bottom As Integer = column.HeaderCell.ContentBounds.Bottom + 1
pen.Width = 2
g.DrawLine(pen, x, top, x, bottom)
Next column
End Sub
To change the backcolor of the Column Headers in a datagridview, choose False for EnableHeadersVisualStyles. Then open ColumnHeadersDefaultCellStyle and choose the background color.
I can't see the picture but what about playing with these?
DataGridView.ColumnBordersHeaderStyle
DataGridView.RowBordersHeaderStyle