|
Below is sample code, with sample values. Uses a Form with a Chart object ("Chart1") X-Axis is the date and there are 2 Y values. If the mouse passes over the line(s) I want to display which series, the value and the date, several show as "Unknown" because the value passed to the Function is slightly off the actual value. I'd rather NOT use the function I created anyway, I would rather get it direct from the HitTest results or some other method if that is possible.
<pre> Option Strict On
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form1
Private TheDate As New List(Of Date)
Private Series1 As New List(Of Integer)
Private Series2 As New List(Of Integer)
Private Function DateFromOtherData(SName As String, Data As Integer) As String
Dim DataIndex As Integer = -1
If SName = "Series1" Then
DataIndex = Series1.IndexOf(Data)
Else
DataIndex = Series2.IndexOf(Data)
End If
If DataIndex > -1 Then
Return TheDate(DataIndex).ToShortDateString
Else
Return "Unknown"
End If
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim Temp As New List(Of String)
Temp.Add("2020-03-07")
Series1.Add(428)
Series2.Add(19)
Temp.Add("2020-03-31")
Series1.Add(188461)
Series2.Add(4304)
Temp.Add("2020-04-24")
Series1.Add(909853)
Series2.Add(51360)
Temp.Add("2020-05-18")
Series1.Add(1515593)
Series2.Add(90414)
Temp.Add("2020-06-11")
Series1.Add(2036500)
Series2.Add(113980)
Temp.Add("2020-07-05")
Series1.Add(2910782)
Series2.Add(129941)
Temp.Add("2020-07-29")
Series1.Add(4433633)
Series2.Add(151172)
Temp.Add("2020-09-15")
Series1.Add(6614318)
Series2.Add(195689)
Temp.Add("2020-10-09")
Series1.Add(7719211)
Series2.Add(213595)
Temp.Add("2020-11-02")
Series1.Add(9377208)
Series2.Add(231480)
Temp.Add("2020-11-26")
Series1.Add(12954294)
Series2.Add(263339)
Temp.Add("2020-12-20")
Series1.Add(17880478)
Series2.Add(317810)
Temp.Add("2021-01-13")
Series1.Add(23135194)
Series2.Add(384824)
Temp.Add("2021-02-06")
Series1.Add(26958807)
Series2.Add(462052)
Temp.Add("2021-03-02")
Series1.Add(28738501)
Series2.Add(515710)
Temp.Add("2021-03-26")
Series1.Add(30172762)
Series2.Add(547621)
Temp.Add("2021-04-19")
Series1.Add(31754642)
Series2.Add(567314)
Temp.Add("2021-05-13")
Series1.Add(32868084)
Series2.Add(583991)
Temp.Add("2021-06-06")
Series1.Add(33329413)
Series2.Add(596803)
Temp.Add("2021-06-30")
Series1.Add(33639764)
Series2.Add(604446)
Temp.Add("2021-07-24")
Series1.Add(34469200)
Series2.Add(610400)
Temp.Add("2021-08-17")
Series1.Add(37133674)
Series2.Add(623237)
Temp.Add("2021-09-10")
Series1.Add(40914456)
Series2.Add(658865)
Temp.Add("2021-10-04")
Series1.Add(43826566)
Series2.Add(703362)
Temp.Add("2021-10-28")
Series1.Add(45797078)
Series2.Add(743050)
Temp.Add("2021-11-21")
Series1.Add(47692614)
Series2.Add(771871)
Temp.Add("2021-12-15")
Series1.Add(50346987)
Series2.Add(801037)
For Each S As String In Temp
TheDate.Add(CDate(S))
Next
End Sub
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
Chart1.Series.Clear()
Chart1.Series.Add("Series1")
Chart1.Series.Add("Series2")
Chart1.Series(0).YAxisType = AxisType.Primary
Chart1.Series(1).YAxisType = AxisType.Secondary
Chart1.ChartAreas(0).AxisY.MajorGrid.LineWidth = 0
Chart1.ChartAreas(0).AxisY2.MajorGrid.LineWidth = 0
Chart1.ChartAreas(0).AxisX.MajorGrid.LineWidth = 0
Chart1.ChartAreas(0).AxisX2.MajorGrid.LineWidth = 0
Chart1.ChartAreas(0).AxisX.Interval = 21
Chart1.ChartAreas(0).AxisX2.Interval = 21
Chart1.ChartAreas(0).AxisY.LabelStyle.ForeColor = Color.Blue
Chart1.ChartAreas(0).AxisY.LabelStyle.Font = New Font("Arial", 12, FontStyle.Bold)
Chart1.ChartAreas(0).AxisY2.LabelStyle.ForeColor = Color.Red
Chart1.ChartAreas(0).AxisY2.LabelStyle.Font = New Font("Arial", 12, FontStyle.Bold)
Chart1.Series(0).Name = "Series1"
Chart1.Series(0).Points.DataBindXY(TheDate.ToArray, Series1.ToArray)
Chart1.Titles.Clear()
Chart1.Series(1).Name = "Series2"
Chart1.Series(1).Points.DataBindXY(TheDate.ToArray, Series2.ToArray)
Chart1.Series(0).ChartType = SeriesChartType.Line
Chart1.Series(0).BorderWidth = 5
Chart1.Series(1).ChartType = SeriesChartType.Line
Chart1.Series(1).BorderWidth = 2
Chart1.Series(0).Color = Color.Blue
Chart1.Series(1).Color = Color.Red
Chart1.Visible = True
End Sub
Private Sub Chart1_MouseMove(sender As Object, e As MouseEventArgs) Handles Chart1.MouseMove
Dim result As HitTestResult = Chart1.HitTest(e.X, e.Y)
Dim Ndx As Integer
Dim thisPt As New PointF
Dim ta As New CalloutAnnotation
Dim TheText As String = ""
Chart1.Annotations.Clear()
If result.ChartElementType = ChartElementType.DataPoint Then
Dim SName As String = result.Series.Name
If SName = "Series1" Then
Ndx = 0
Else
Ndx = 1
End If
thisPt = New PointF(CSng(Chart1.Series(Ndx).Points(result.PointIndex).XValue),
CSng(Chart1.Series(Ndx).Points(result.PointIndex).YValues(0)))
ta.CalloutStyle = CalloutStyle.Rectangle
ta.AnchorDataPoint = Chart1.Series(Ndx).Points(result.PointIndex)
ta.Alignment = ContentAlignment.MiddleLeft
ta.TextStyle = TextStyle.Default
ta.Font = New Font("Arial", 10, FontStyle.Bold)
TheText &= SName & ": " & vbLf &
"Value: " & thisPt.Y.ToString("F0") & vbLf &
"Date: " & DateFromOtherData(SName, CInt(thisPt.Y))
ta.Text = TheText
Chart1.Annotations.Add(ta)
Chart1.Invalidate()
Me.Text = "ThisPt.X = " & thisPt.X.ToString
End If
End Sub
End Class
|
|
|
|
|
Hello every one
simple code as follow
Dim MyInt As Int16 = 12
Dim result As Byte() =BitConverter.GetBytes(MyInt)
Console.WriteLine(BitConverter.ToString(result).Length)
Console.WriteLine(BitConverter.ToString(result))
this will return as follow
5
0C-00
Just I want to get
2
0C
(length 2 only) and return (0C) only
I try to change "MyInt" Declare type from Int16 to all available types but did not work,
also i dont need to subtract result as string, i need result as byte() type
any advise please ?
I am using VS2019
thanks in advance
|
|
|
|
|
It really depends on what you are trying to do, and why you need to convert a number to a hexadecimal string. You could just use the 'X' format string to print the value, which would give you the correct answer.
|
|
|
|
|
I solved like follows:-
Dim MyInt As Int16 = 12
Dim result (0) As Byte
result (0) = Convert.ToByte(MyInt)
Console.WriteLine(BitConverter.ToString(result))
thanks everyone again
|
|
|
|
|
An int16 (or 'short') is a two-byte value. Intel processors are "little-endian", meaning the last byte (least significant) is stored first and the first byte (most significant) is stored last.
In your example, your two byte value, (12) 0x000C, is stored in memory like this: 0x0C, 0x00. So that's why you're getting the bytes in the order you are. BitConverter is returning the bytes in the order they appear in memory.
If you were running the exact same code on a processor that is big-endian, the bytes would show up in the array in the order opposite of what you're seeing now.
Now, having said all that, if you're looking for just getting a string for the hexadecimal representation of your value, all you have to do is this:
Dim myInt As Int16 = 12
result = String.Format("X", myInt)
If you're dealing with values that will never be greater than 255, why are you using an Int16? Why not just use Byte instead?
|
|
|
|
|
How to solve error 50003 in vb6 in win 10
|
|
|
|
|
Have you tried entering 'vb6 error 50003' in a browser search engine?
|
|
|
|
|
By fixing the secret error in your secret code, obviously.
Seriously, if you want someone to help you fix an error in your code, you need to provide the relevant parts of your code, and the full details of the error.
If you don't have the code, then contact the person who wrote it to get the problem fixed.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
im making insert update and delete with database for my activity and the teacher give task to add print and im trying to make on my own but its diffucult for me i hope you can help me out with these.
im beginner at visual basic.
im using printdocument and printpreviewdialog
Here my code
Print button
Private Sub btnprint_Click(sender As Object, e As EventArgs) Handles btnprint.Click
Dim PrintPreview As New PrintPreviewDialog
PrintPreview.Document = PrintDocument1
PrintPreview.ShowDialog()
End Sub
Print Document Print Page
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim H As Integer = 0
H = 50
e.Graphics.DrawString("PRINT", New Drawing.Font("Times New Roman", 10), Brushes.Black, 50, H)
For Each Itm As ListViewItem In ListView1.Items
e.Graphics.DrawString(Itm.Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 50, H)
e.Graphics.DrawString(Itm.SubItems(0).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(1).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(2).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(3).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(4).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(5).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(6).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(7).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(8).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
e.Graphics.DrawString(Itm.SubItems(9).Text, New Drawing.Font("Times New Roman", 10), Brushes.Black, 150, H)
H += 20
Next
End Sub
here's my ouput
Output
|
|
|
|
|
You are drawing every sub-item starting at the same horizontal coordinate. Unsurprisingly, this results in the text of every sub-item overlapping.
You need to increase the horizontal coordinate for each sub-item. You can either use the MeasureString method[^] to measure how much space your string will take up, or used fixed coordinates and use the DrawString overload[^] which limits the size of the output to prevent the text from overlapping.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
You are drawing all 10 subitems at the same location on the page. You need to change the X location for each item. The code could be simplified by creating a loop and using a single Font element:
Dim TnrFont as Drawing.Font = New Drawing.Font("Times New Roman", 10)
e.Graphics.DrawString("PRINT", TnrFont, Brushes.Black, 50, H)
For Each Itm As ListViewItem In ListView1.Items
e.Graphics.DrawString(Itm.Text, TnrFont, Brushes.Black, 50, H)
Dim Left as Integer = 150
For subindex as Integer = 0 To 9
e.Graphics.DrawString(Itm.SubItems(subindex).Text, TnrFont, Brushes.Black, Left, H)
Left += 100
Next
H += 20
Next
|
|
|
|
|
Pls can visual basic 2010 do face identification and recognition. if yes how can i design it, am new in visual basic...Thanks.
|
|
|
|
|
You need to research what libraries are available that provide such a feature. And to be honest, this is quite an advanced subject for someone who, as you say, is new to VB.
|
|
|
|
|
Heavy stuff for someone new to VB!
It's not a case of can VB "do face identification" but "can I write code in VB.net that calls a library that does facial identification"
This article discusses some of the models that are available Introduction to Face Identification[^] N.B. The code is in python, I'm only including the article for the links to the models and the general discussion.
This article specifically discusses the EMgu tool - again it uses C# rather than VB but the principles are all there Image Recognition with C# and Emgu Libraries[^]
Most of the tools from the links in the articles will have resources to show you how to use them e.g. Code Gallery - Emgu CV: OpenCV in .NET (C#, VB, C++ and more)[^]
|
|
|
|
|
HOW TO CODE A REFRESH BUTTON IN VB.NET FORM PLEASE GUIDE
|
|
|
|
|
Depends on what you want to refresh. No one knows what you are talking about.
|
|
|
|
|
...and STOP YELLING at people. Typing everything in all caps is the equivalent to screaming at people on the internet.
|
|
|
|
|
in the onclick event of the button you write the code to refresh the magic thing you need refreshing.
I hope like hell you are not the accounting firm in London asking such a badly formed question.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Maybe it's the manager who decided to fire their only programmer because he read on a magazine that VB.NET is so easy anyone can write code in it?
GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X
|
|
|
|
|
Mycroft Holmes wrote: I hope like hell you are not the accounting firm in London asking such a badly formed question. Wait for your coming colonscopy, and see the device running W98. Imagine a dependency on vbrun300.dll.
Have fun
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hello;
I have image on PictureBox, Cinverted to Base64String string and saved in Database as following:
Dim ms As MemoryStream = New MemoryStream
Dim bmp As Bitmap = New Bitmap(PictureBox1.Image)
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.jpg)
Dim My_Photo_Str As String = Convert.ToBase64String(ms.ToArray)
myqry = "update MYTABLE set COLUMN1=" & "'" & My_Photo_Str & "'" & "where COLUMN2=" & 50
mycmd = New OleDbCommand(myqry, conn)
mycmd.CommandTimeout = 0
mydr = mycmd.ExecuteReader
Now that image need to retrieve it or shows on PictureBox, So I used the following:-
myqry = "select * from MYTABLE where COLUMN2=" & 50
mycmd = New OleDbCommand(myqry, conn)
mycmd.CommandTimeout = 0
mydr = mycmd.ExecuteReader
mydr.Read()
Dim PIC As Byte()
PIC = mydr("COLUMN1")
Dim My_Photo = New MemoryStream(PIC)
PictureBox1.Image = Bitmap.FromStream(My_Photo) <<<<<-----HERE GOT ERROR
the error on last line while try to set image to PictureBox, and error said that cannot convert Byte() to image, If any help will so appreciated
thanks
|
|
|
|
|
|
Why are you converting the image to a Base64 string? You don't have to do that to save it it in the database.
Databases support blobs (Binary Large Objects) natively, so conversion to Base64 is not necessary.
You can't directly use the Base64 string to create a Bitmap object from it. You have to convert the Base64 string back into an array of bytes, then create the Bitmap from that array.
|
|
|
|
|
|
ffmpeg.exe will not save file names with a number since the first "output.avi" and exists but a new one that has "output(1).avi" will not be accepted. What can I do here.
|
|
|
|
|