OnResize sub is not fully working in VB.net - vb.net

I am trying to resize a red rectangle (via a class who inherit PictureBox) in a PictureBox containing an Image, but I have few issues with the method OnResize.
I can resize this frame only with the corner bottom-right, which keep the ratio of the frame to 1.5 (landscape). But, when I am resizing the red rectangle, the resizing action should stop when it touch the right or bottom side, but it is working only partially: stop on the right side, but carry on on the bottom side (see pictures).
Below is the code of the OnResize method, but to fully understand the problem, you can follow this Google Drive Link which will give you a short version/application of what I am doing with the issue.
Any ideas are obviously welcome, as there is something I don't understand.
Thanks,
JLuc
Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
Try
' Minimum limits
If Me.Width < 40 Then Me.Width = CInt(40 * Form1.dRatioImageWH)
If Me.Height < 40 Then Me.Height = CInt(40 / Form1.dRatioImageWH)
' Keeping the ratio Width/Height = 1.5 (Landscape)
If Form1.dRatioImageWH > 1 Then Me.Height = CInt(Me.Width / Form1.dRatioImageWH)
' Effect on Resize event
If Me.Width > Form1.PictureBox1.Width - Me.Location.X Then Me.Width = Form1.PictureBox1.Width - Me.Location.X
If Me.Height > Form1.PictureBox1.Height - Me.Location.Y Then Me.Height = Form1.PictureBox1.Height - Me.Location.Y
' Control to be redrawn
Me.Invalidate()
' Raise the Resize event
MyBase.OnResize(e)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

I remember having similar issues with OnResize until I realized that there also exists OnResizeEnd, which fires every time.

I found a way to achieve what I wanted. But, it sounds a bit complicated, then if you find something better, do not hesitate to tell me.
The idea is to find out where the left-up corner of my moving/resizing red rectangle is in the PictureBox rectangle ABCD. Is it in the rectangle ABC (impacting on the right side) or in the rectangle ADC (impacting on the bottom side). Then, adjust the right coding depending of the situation.
Follow this LINK for more explanation on the math's side.
Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
' To redraw the whole image based on Glass window
Try
' Minimum limits of Glass window
If Me.Width < 40 Then Me.Width = CInt(40 * Form1.dRatioImageWH)
If Me.Height < 40 Then Me.Height = CInt(40 / Form1.dRatioImageWH)
' ------------------------------------------------------------
' Adjust the right coding after checking if the Point P is within the appropriate triangle
' How do I check whether a given point lies inside a triangle whose coordinates are given?
' If Area of ABC == Area of (PAB + PBC + PAC), then Point P is inside the triangle ABC
' ------------------------------------------------------------
Dim A As New Point
A.X = 0
A.Y = 0
Dim B As New Point
B.X = 400
B.Y = 0
Dim C As New Point
C.X = 400
C.Y = 266
Dim P As New Point
P.X = Me.Location.X
P.Y = Me.Location.Y
' Area of Triangle ABC (upper half of the PictureBox)
Dim areaABC As Integer
areaABC = (A.X * (B.Y - C.Y) + B.X * (C.Y - A.Y) + C.X * (A.Y - B.Y)) / 2
' Area of 3 Triangles inside the Triangle ABC based on Point P
Dim areaPAB As Integer
areaPAB = (P.X * (A.Y - B.Y) + A.X * (B.Y - P.Y) + B.X * (P.Y - A.Y)) / 2
Dim areaPBC As Integer
areaPBC = (P.X * (B.Y - C.Y) + B.X * (C.Y - P.Y) + C.X * (P.Y - B.Y)) / 2
Dim areaPAC As Integer
areaPAC = (P.X * (A.Y - C.Y) + A.X * (C.Y - P.Y) + C.X * (P.Y - A.Y)) / 2
' Target: keep the ratio Width/Height when resizing
If (areaABC > areaPAB + areaPBC + areaPAC) = True Then
' Point P in Triangle ABC (upper half of the PictureBox)
If Me.Height > Form1.PictureBox1.Height - Me.Location.Y Then
Me.Height = Form1.PictureBox1.Height - Me.Location.Y
Else
Me.Height = CInt(Me.Width / Form1.dRatioImageWH)
End If
Else
' Point P in Triangle ADC (lower half of the PictureBox)
If Me.Width > Form1.PictureBox1.Width - Me.Location.X Then
Me.Width = Form1.PictureBox1.Width - Me.Location.X
Else
Me.Width = CInt(Me.Height * Form1.dRatioImageWH)
End If
End If
' Control to be redrawn
Me.Invalidate()
' Raise the Resize event
MyBase.OnResize(e)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Related

How to solve ArgumentException : The parameter is not valid for drawing Arcs

I'm making a custom winforms button in VB.Net with rounded edges and other features. I create a path using various inputs defined by the user and draw and fill it using pens and brushes.
When I call e.Graphics.FillEllipse(Brush1, Rect1) and e.Graphics.DrawEllips(Pen1, Rect1) it just works fine without any problems, but when I try e.Graphics.FillPath(Brush1, OuterPath) and e.Graphics.DrawPath(Pen1, OuterPath) it doesn't work at all. I get this error:
ArgumentException: The parameter is not valid
I tried giving the right types of each variable used in the process and not letting the compiler decide, creating more variables to calculate and manage the inputs individually to not make all the calculations in the inputs of each function, which makes my work easier honestly, and even using the CType function in the inputs of each function to make sure that the function understands what I want as inputs. But everything failed and I don't know what to do next to fix the issue.
Here is the code:
Private Sub MetaniumButton_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim PathWidth As Integer = Width - BorderSize / 2
Dim PathHeight As Integer = Height - BorderSize / 2
_Roundnes = RoundnesMemory
If PathHeight < Roundenes.Height Then
_Roundnes.Height = PathHeight - 1
End If
If PathWidth < Roundenes.Width Then
_Roundnes.Width = PathWidth - 1
End If
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
Dim OuterPath As New GraphicsPath
Dim Rec1 As Rectangle = New Rectangle(CType(BorderSize / 2, Int32), CType(BorderSize / 2, Int32), CType(_Roundnes.Width, Int32), CType(_Roundnes.Height, Int32))
Dim Rec2 As Rectangle = New Rectangle(PathWidth - _Roundnes.Width, BorderSize / 2, _Roundnes.Width, _Roundnes.Height)
Dim Rec3 As Rectangle = New Rectangle(PathWidth - _Roundnes.Width, PathHeight - _Roundnes.Height, _Roundnes.Width, _Roundnes.Height)
Dim Rec4 As Rectangle = New Rectangle(BorderSize / 2, PathHeight - _Roundnes.Height, _Roundnes.Width, _Roundnes.Height)
OuterPath.StartFigure()
OuterPath.AddLine(CInt(_Roundnes.Width / 2 + BorderSize / 2), CInt(BorderSize / 2), CInt(PathWidth - _Roundnes.Width / 2), CInt(BorderSize / 2))
OuterPath.AddArc(Rec1, 180.0, 90.0) ' Here is the problem and it could probably in any AddArc Function i used
OuterPath.AddLine(PathWidth, CInt(_Roundnes.Height / 2 + BorderSize / 2), PathWidth, CInt(PathHeight - _Roundnes.Height / 2))
OuterPath.AddArc(Rec2, -90, 90)
OuterPath.AddLine(CInt(_Roundnes.Width / 2 + BorderSize / 2), PathHeight, CInt(PathWidth - _Roundnes.Width / 2), PathHeight)
OuterPath.AddArc(Rec3, 0, 90)
OuterPath.AddLine(CInt(BorderSize / 2), CInt(_Roundnes.Height / 2), CInt(BorderSize / 2), CInt(PathHeight - _Roundnes.Height / 2))
OuterPath.AddArc(Rec4, 90, 90)
OuterPath.CloseFigure()
e.Graphics.FillPath(Brush1, OuterPath)
e.Graphics.DrawPath(Pen1, OuterPath)
Dim LabelCount As Integer = 0
For Each l As Label In Controls
LabelCount += 1
Next
Dim TextPlace As New Label With {.Name = "TextLabel",
.Text = Text,
.AutoEllipsis = True,
.Size = New Size(Width -
Margin.Left + Margin.Right + 2 * _Roundnes.Width) / 2, Height - (Margin.Top + Margin.Bottom + 2 * _Roundnes.Height) / 2),
.TextAlign = _TextAlign,
.ForeColor = _FontColor,
.BackColor = _MetaniumBackColor,
.Location = New Point((Width - .Width) / 2, (Height - .Height) / 2)}
AddHandler TextPlace.TextChanged, AddressOf MetaniumButton_TextChanged
AddHandler Me.TextChanged, AddressOf MetaniumButton_TextChanged
Controls.Add(TextPlace)
T += 1
If LabelCount <= 0 Then
0: For Each l As Label In Controls
If l.Name = "TextLabel" Then
l.Text = Text
l.AutoEllipsis = True
l.Size = New Size(Width - (Margin.Left + Margin.Right + 2 * _Roundnes.Width) / 2, Height - (Margin.Top + Margin.Bottom + 2 * _Roundnes.Height) / 2)
l.TextAlign = _TextAlign
l.ForeColor = _FontColor
l.BackColor = _MetaniumBackColor
l.Location = New Point((Width - l.Width) / 2, (Height - l.Height) / 2)
End If
Next
ElseIf LabelCount = 1 Then
For Each l As Label In Controls
If l.Name <> "TextLabel" Then
Controls.Remove(l)
Else
GoTo 1
End If
1: GoTo 0
Next
Else
End If
End Sub
When I track down the bug it seems the problem is in the AddArc() function, and I really don't know why it doesn't work. Any help appreciated.
BTW, I use VB.Net Express 2010 with .Net Framework 4.8.
PS: you can post an answer using either VB.Net or C# I can translate the code from both of them.
I solved My problem, and the answer was to initialize the value or Roundnes to (1,1) at least because my code creates the arcs of the edges using Roundnes to know how wide and long the curving edge
so the solution is to add this line of code before the code responsible for creating the arc.
If _Roundnes = New Size(0, 0) Then _Roundnes = New Size(1, 1)
And that's pretty much it! Thank you for helping me out!

My Math Seems Fine, but My Drawlines Look Weird. [Hexagon Grid]

I think I just need a fresh set of eyes to look at this. Or perhaps it's an issue with my numbers not being specific enough. I'm a beginner at programming and my only hunch is recursion.
Essentially, my hexagons are incorrectly positioned in some rows, but not others and I want them to all be smooth.
Public Class Form1
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
'Side Length
Dim side As Integer = 25
'Grid Width
Dim width As Integer = 10
'Grid Height
Dim height As Integer = 10
'Starting X
Dim startX As Integer = 100
'Starting Y
Dim startY As Integer = 100
'Hexagon Border
Dim borderPen As New Pen(Brushes.Gray, 1)
For i = 1 To width Step 1
For j = 1 To height Step 1
Dim apothem As Integer = (Math.Sqrt(3) * side / 2)
Dim half As Integer = (side / 2)
Dim centerX As Integer = (startX + (side * i * 1.5))
Dim centerY As Integer = (startY + (apothem * j * 2))
If i Mod 2 = 0 Then
centerY += apothem
End If
e.Graphics.DrawLine(borderPen, (centerX - half), (centerY + apothem), (centerX + half), (centerY + apothem))
e.Graphics.DrawLine(borderPen, (centerX + half), (centerY + apothem), (centerX + side), (centerY))
e.Graphics.DrawLine(borderPen, (centerX + side), (centerY), (centerX + half), (centerY - apothem))
e.Graphics.DrawLine(borderPen, (centerX + half), (centerY - apothem), (centerX - half), (centerY - apothem))
e.Graphics.DrawLine(borderPen, (centerX - half), (centerY - apothem), (centerX - side), (centerY))
e.Graphics.DrawLine(borderPen, (centerX - side), (centerY), (centerX - half), (centerY + apothem))
Next
Next
End Sub
End Class
I've tinkered with the suggestions you guys commented and fixed the bug I was having. I wasn't using correct data types. Also, I utilized e.Graphics.Drawlines and the StockObject tip for pens and disposing of them. Thanks, again!
https://imgur.com/B37MDwB
If there's any other improvements I can make to my code feel free to comment them.
Option Strict On
Imports System.Drawing.Drawing2D
Public Class Form1
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles
Me.Paint
'Side Length
Dim side As Single = 30
'Grid Width
Dim width As Single = 10
'Grid Height
Dim height As Single = 5
'Starting X
Dim startX As Single = 0
'Starting Y
Dim startY As Single = 0
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
e.Graphics.PixelOffsetMode = PixelOffsetMode.Half
Dim apothem As Single = CSng(Math.Sqrt(3) * side / 2.0F)
Dim half As Single = (side / 2)
For i = 1 To width Step 1
For j = 1 To height Step 1
Dim centerX As Single = (startX + (side * i * 1.5F))
Dim centerY As Single = (startY + (apothem * j * 2))
If i Mod 2 = 0 Then
centerY += apothem
End If
Dim points As New List(Of PointF)
points.Add(New PointF((centerX - half), (centerY + apothem)))
points.Add(New PointF((centerX + half), (centerY + apothem)))
points.Add(New PointF((centerX + side), (centerY)))
points.Add(New PointF((centerX + half), (centerY - apothem)))
points.Add(New PointF((centerX - half), (centerY - apothem)))
points.Add(New PointF((centerX - side), (centerY)))
points.Add(New PointF((centerX - half), (centerY + apothem)))
e.Graphics.DrawLines(Pens.Gray, points.ToArray())
Next
Next
End Sub
End Class

fit controls to screen vba

i'm trying to fit the user form to screen on diifernet screens.
the userform was first managed in my work screen and i fit it to my screen but when i'm trying the userform on other screens part of it vanished.
i can't put the whole code in here but i will put just the sub that suppose to fit to screen:
Private Sub UserForm_Initialize()
Dim w As Long, h As Long
Application.Visible = False
With Me
rMaxHeight = Application.Height
rMaxWidth = Application.Width
If .Height > Application.Height - 10 Then
rNormalHeight = rMaxHeight * 0.85
Else
rNormalHeight = Me.Height
End If
If .Width > Application.Width - 10 Then
rNormalWidth = rMaxWidth * 0.85
Else
rNormalWidth = Me.Width
End If
.StartUpPosition = 1
.Left = 0
.Top = 0
FitSize
...
Private Sub FitSize()
Dim h, w
Dim c As Control
Dim PHeight, PWidth As Double
PHeight = rNormalHeight / Me.Height
PWidth = rNormalWidth / Me.Width
h = 0: w = 0
If PHeight = 1 And PWidth = 1 Then Exit Sub
For Each c In Me.Controls
If c.Visible Then
If c.Top + c.Height > h Then h = (c.Top + c.Height) ' * PHeight
If c.Left + c.Width > w Then w = (c.Left + c.Width) ' * PWidth
If Not TypeName(c) = "Image" Or TypeName(c) = "ListBox" Then c.FontSize = c.FontSize * ((PHeight + PWidth) / 2)
End If
Next c
If h > 0 And w > 0 Then
With Me
.Width = w + 40
.Height = h + 40
End With
End If
End Sub
hope you could help me with that
Thank you all
sefi
You can either Re-position every single control in the UserForm with VBA or simply enable ScrollBars for the UserForm object so they can access all the elements with a bit of scrolling.
Change the ScrollBars property of the UserForm to like 3 - fmScrollBarsBoth as the default is 0 - fmScrollBarsNone
Then you need to figure out how tall and wide it needs to be:
ScrollHeight
ScrollWidth
Hello and thank for everyone that tried to help me.
I found the solution to this problem by fitting the controls to the proportion of the screen copared with the original form.
At first step you need to calculate the proportion:
Dim PHeight, PWidth As Double
'define form size compared with the original size of the form
rMaxHeight = Application.Height
rMaxWidth = Application.Width
If Me.Height > Application.Height Then
rNormalHeight = rMaxHeight * 0.85
Else
rNormalHeight = Me.Height
End If
If Me.Width > Application.Width Then
rNormalWidth = rMaxWidth * 0.85
Else
rNormalWidth = Me.Width
End If
'normal is the size needed in normal mode before the form get to maximize mode
'we want to calculate the needed divided to the orignal
PHeight = rNormalHeight / Me.Height
PWidth = rNormalWidth / Me.Width
now we call fitsize()
Private Sub FitSize()
Dim h, w
Dim c As Control
h = 0: w = 0
If PHeight = 1 And PWidth = 1 Then Exit Sub ' if the it is the original size of the form- don't bother...
'loop on the form controls
For Each c In Me.Controls
If c.Visible Then ' just visible controls
c.Top = c.Top * PHeight ' fit to proportion of the screen compared with the original form
c.Height = c.Height * PHeight
If c.Top + c.Height > h Then h = c.Top + c.Height ' collect the height needed from the controls
c.Left = c.Left * PWidth ' fit to proportion of the screen compared with the original form
c.Width = c.Width * PWidth
If c.Left + c.Width > w Then w = c.Left + c.Width ' collect the height needed from the controls
'fit the font for the text controls
If Not TypeName(c) = "Image" Or TypeName(c) = "ListBox" Then c.FontSize = c.FontSize * ((PHeight + PWidth) / 2)
End If
Next c
'define the size needed form the specific screen
If h > 0 And w > 0 Then
With Me
.Width = w + 40
.Height = h + 40
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
End With
End If
End Sub
this code will define the size needed in each screen by the proportion that calculated in the needed value divded to the original value.
Try it and tell me if it works.
thank you all
sefi

Graphic, zoom function

I am dealing with a zoom equation. Scope of work is to keep the mouse position as pivot when I zoom.
I mean, if a select a point in the picture, the world should become bigger all around the mouse position,
but the line, arc or what else exactly down the mouse, should remain in this position.
My be, what for me took a lot of time, for those that make graphic each day, is a kid game.
This is my actual zoom function.
xo,yo are the coordinates of the point 0,0 of the shape.
Private Sub dlgSelectShape_MouseWheel(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel
Dim p As Point
p = e.Location
p = Me.PointToScreen(p)
p = PictureBox1.PointToClient(p)
If p.X > 0 And p.Y > 0 Then
If e.Delta > 0 Then
'lscale =scale factor
lscale = 0.01 * e.Delta * lscale
Else
'lscale =scale factor
lscale = -lscale / (0.01 * e.Delta)
End If
'xo = point of origin it is the coordinate of the point (0,0)
xo = xo + (-xo + p.X) * lscale / 2
yo = yo + (yo - p.Y) * lscale / 2
Draw()
End If
End Sub

Zooming in using Mouse Wheel

So I have a graph, sometimes this graph goes up to 1000 in terms of the Y values and its far too hard to see individual points/axes interceptions.
This will allow me to click and drag an area to zoom in, however this ruins the X and Y values/intervals and also adds scrollbars to the graph which I do not want!
Chart1.ChartAreas(0).CursorX.IsUserSelectionEnabled = True
Chart1.ChartAreas(0).CursorY.IsUserSelectionEnabled = True
Is there a way to implement this using the mouse wheel and click to drag rather than using scrollbars?
i found the answer in another question
Enabling mouse wheel zooming in a Microsoft Chart Control
but it is in c# .. i converted it to vb.net
Private Sub growthChart_MouseEnter(sender As Object, e As EventArgs) Handles growthChart.MouseEnter
growthChart.Focus()
End Sub
Private Sub growthChart_MouseWheel(sender As Object, e As MouseEventArgs) Handles growthChart.MouseWheel
Try
With growthChart
If (e.Delta < 0) Then
.ChartAreas(0).AxisX.ScaleView.ZoomReset()
.ChartAreas(0).AxisY.ScaleView.ZoomReset()
End If
If (e.Delta > 0) Then
Dim xMin As Double = .ChartAreas(0).AxisX.ScaleView.ViewMinimum
Dim xMax As Double = .ChartAreas(0).AxisX.ScaleView.ViewMaximum
Dim yMin As Double = .ChartAreas(0).AxisY.ScaleView.ViewMinimum
Dim yMax As Double = .ChartAreas(0).AxisY.ScaleView.ViewMaximum
Dim posXStart As Double = (.ChartAreas(0).AxisX.PixelPositionToValue(e.Location.X) _
- ((xMax - xMin) _
/ 4))
Dim posXFinish As Double = (.ChartAreas(0).AxisX.PixelPositionToValue(e.Location.X) _
+ ((xMax - xMin) _
/ 4))
Dim posYStart As Double = (.ChartAreas(0).AxisY.PixelPositionToValue(e.Location.Y) _
- ((yMax - yMin) _
/ 4))
Dim posYFinish As Double = (.ChartAreas(0).AxisY.PixelPositionToValue(e.Location.Y) _
+ ((yMax - yMin) _
/ 4))
.ChartAreas(0).AxisX.ScaleView.Zoom(posXStart, posXFinish)
.ChartAreas(0).AxisY.ScaleView.Zoom(posYStart, posYFinish)
End If
End With
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Sub
It worked well in zooming in but in zooming out it needs adjusting.
Found this code which improves on zoom in positioning with different scales.
I have further improved it and it now also zooms out effectively as well as zooms in.
https://www.vbforums.com/showthread.php?795865-RESOLVED-MSChart-Zoom-with-mouse-roller
Private Sub Chart1_MouseWheel(sender As Object, e As MouseEventArgs) Handles Chart1.MouseWheel
Try
With Chart1
Dim xMin As Double = Chart1.ChartAreas(0).AxisX.ScaleView.ViewMinimum
Dim xMax As Double = Chart1.ChartAreas(0).AxisX.ScaleView.ViewMaximum ' + Chart1.ChartAreas(0).AxisX.ScaleView.Position
Dim yMin As Double = Chart1.ChartAreas(0).AxisY.ScaleView.ViewMinimum
Dim yMax As Double = Chart1.ChartAreas(0).AxisY.ScaleView.ViewMaximum ' + Chart1.ChartAreas(0).AxisX.ScaleView.Position
Dim xValue As Double = Chart1.ChartAreas(0).AxisX.PixelPositionToValue(e.Location.X)
Dim yValue As Double = Chart1.ChartAreas(0).AxisY.PixelPositionToValue(e.Location.Y)
Dim posXFinish As Double
Dim posXStart As Double
Dim posYFinish As Double
Dim posYStart As Double
'this code checks to see if you are within a certain percentage of the starting point
' and if you are it will not zoom in
If e.Delta > 0 Then
'check zoom for x Start
If (xValue - (xValue - xMin) / scale) >= xValue Then
posXStart = xValue - (xValue - xMin)
Else
posXStart = xValue - (xValue - xMin) / scale
End If
'check zoom for x finish
If xValue >= (posXStart + (xMax - xMin) / scale) Then
posXFinish = posXStart + (xMax - xMin)
Else
posXFinish = posXStart + (xMax - xMin) / scale
End If
'check zoom for Y start
If (yValue - (yValue - yMin) / scale) >= yValue Then
posYStart = yValue - (yValue - yMin)
Else
posYStart = yValue - (yValue - yMin) / scale
End If
'check zoom for Y finish
If yValue >= (posYStart + (yMax - yMin) / scale) Then
posYFinish = posYStart + (yMax - yMin)
Else
posYFinish = posYStart + (yMax - yMin) / scale
End If
ElseIf e.Delta < 0 Then
'check zoom for x Start
If (xValue - (xValue - xMin) * scale) <= xValue Then
posXStart = xValue - (xValue - xMin)
Else
posXStart = xValue - (xValue - xMin) * scale
End If
'check zoom for x finish
If xValue <= (posXStart + (xMax - xMin) * scale) Then
posXFinish = posXStart + (xMax - xMin)
Else
posXFinish = posXStart + (xMax - xMin) * scale
End If
'check zoom for Y start
If (yValue - (yValue - yMin) * scale) >= yValue Then
posYStart = yValue - (yValue - yMin)
Else
posYStart = yValue - (yValue - yMin) * scale
End If
'check zoom for Y finish
If yValue >= (posYStart + (yMax - yMin) * scale) Then
posYFinish = posYStart + (yMax - yMin)
Else
posYFinish = posYStart + (yMax - yMin) * scale
End If
End If
Chart1.ChartAreas(0).AxisX.ScaleView.Zoom(posXStart, posXFinish)
Chart1.ChartAreas(0).AxisY.ScaleView.Zoom(posYStart, posYFinish)
End With
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Sub