I have a problem with the function IntersectWith
I have used this function with VBA and it has a option Intersect.None
But when I call the function from VB.NET this option does not exist.
I try to use the available options but all detect an incorrect intersection
yourCADObjectII.IntersectWith(myText, Intersect.ExtendBoth, points, New IntPtr(0), New IntPtr(0))
yourCADObjectII.IntersectWith(myText, Intersect.OnBothOperands, points, IntPtr.Zero, IntPtr.Zero)
yourCADObjectII.IntersectWith(myText, Intersect.ExtendArgument, points, IntPtr.Zero, IntPtr.Zero)
yourCADObjectII.IntersectWith(myText, Intersect.ExtendThis, points, IntPtr.Zero, IntPtr.Zero)
I don't know how to use IntersectWith in VB.NET as I used in VBA with the Intersect.None option.
I tried to detect a text string vs. a closed polyline, the text is inside of a polyline, I want to detect if the text intersects with the LWPolyline.
The text has different rotations and the polyline has different geometry.
As far as know, the COM/ActiveX IntersectWith method does not have any Intersect.None option. It has a acExtendNone option whose .NET equivalent is Intersect.OnBothOperands.
COM .NET
acExtendNone Intersect.OnBothOperands Does not extend either object.
acExtendThisEntity Intersect.ExtendThis Extends the base object.
acExtendOtherEntity Intersect.ExtendArgument Extends the object passed as an argument.
acExtendBoth Intersect.ExtendBoth Extends both objects.
I think you are implementing IntersectWith correctly and your problem is not with what you mentioned. From memory, when you try to use intersectwith for DBText with any other object, it doesn't actually calculate the intersection with the text itself but rather with its bounding box. And that bounding box doesn't always fit the text exactly. It sometimes is bigger than the text (depending on rotation). Or sometimes it is smaller than the text especially when using letters like (y, j, q,g, etc...)
So your best bet is to try and find the bounding box that fits your rotated text by finding the bounding box that fits the same text with no rotation then rotate that box (using a closed polyline to capture all 4 corners)
Now your problem becomes intersection of two polylines instead of text and polyline. And then you can use intersectWith to get intersection points
Related
I am making a board game and want to store information about each square of a 10x10 grid inside a structure, and I need to get the entire array rects from the record structure squares and use it in e.Graphics.FillRectangles(). Everything apart from the declarations are inside a paint event.
Public Structure squares
Dim rects As Rectangle
End Structure
Dim s(99) As squares
'assigning values to each instance of rects
e.Graphics.FillRectangles(b1, s.rects)
e.Graphics.DrawRectangles(p1, s.rects)
but this gives the error 'rects' is not a member of 'Form1.squares()'. s().rects does not work either. Note that I am not trying to get a specific index, as FillRectangles does not accept it as an argument.
I previously had rects on its own and that worked without any issues.
Dim rects(99) as Rectangle
'assigning values to each instance of rects
e.Graphics.FillRectangles(b1, rects)
e.Graphics.DrawRectangles(p1, rects)
I could use a loop that draws each rectangle individually, but I found that this method is much slower and not what i'm looking for.
Is there any way to make this work or should I have it as an array on its own and only store other information inside the structure? Should I even use a structure at all or would using parallel arrays be a better idea?
You cannot call s.rects. There is not an index to extract rects. That must be s(indexHere).rects.
However the code below return all rects from your array:
Dim s(99) As squares
'Do not forget to set rects before calling those two
e.Graphics.FillRectangles(Brushes.Red, s.Select(Function(x) x.rects).ToArray)
e.Graphics.DrawRectangles(Pens.Black, s.Select(Function(x) x.rects).ToArray)
I am creating a custom bar chart using VB.NET, I am wondering if there is a way to program the distance between intervals in the y axis. For example if I wanted the distance between points 1 and 2 in the axis to be of a certain length e.g 2cm long and the next interval to be of a certain length e.g 5cm long, is there a way to achieve this. Any help would be appreciated.
You can set the ChartArea to be a specific size and then configure the Axis.Interval property
No (at least, not easily). The Axis.Interval property sets all intervals to be the same size. You would need to subclass Chart and override the OnPaint method to draw the ticks (and/or grid lines) with different spacings. Not sure offhand if there are ways to have it paint parts of the chart as it normally would, while doing custom painting on other parts...
ETA: It may become slightly easier if you only have 2 intervals to worry about (e.g., the axis line itself, then one line 2 cm up, then another line 5 cm up from that, and no more lines after that). You could probably use the Axis.Interval and Axis.MinorGrid.Interval properties in that case.
ETA again, since it didn't show up nice in the comments: One thing you could try is to hide all of the ticks and grid lines, and then handle the OnPaint event (not override) to just draw lines on top of the chart where needed. Something like this psuedocode
private void ChartPaint(object sender, Args e) {
e.Graphics.DrawLine(figure_out_2cm_above_axis, Color.Black, etc);
e.Graphics.DrawLine(figure_out_5cm_above_line, Color.Black, etc);
}
is there any way to make this work faster?
Here is my sample code in vb.net. This adds a point on a chart at mouse position but it is quite slow.
Private Sub Chart2_MouseMove(sender As Object, e As MouseEventArgs) Handles Chart2.MouseMove
Dim coord() As Double = GetAxisValuesFromMouse(e.X, e.Y)
Dim test As Series
Try
Chart2.Series.RemoveAt(1)
Catch ex As Exception
End Try
Dim pt As New DataPoint
pt.XValue = coord(0)
pt.YValues(0) = coord(1)
test = New Series
Chart2.Series.Add(test)
Chart2.Series(test.Name).ChartType = SeriesChartType.Point
Chart2.Series(test.Name).Points.Add(pt)
End Sub
Function returns the coordinates of x and y axis at mouse position.
Private Function GetAxisValuesFromMouse(x As Integer, y As Integer) As Double()
Dim coord(1) As Double
Dim chartArea = Chart2.ChartAreas(0)
coord(0) = chartArea.AxisX.PixelPositionToValue(x)
coord(1) = chartArea.AxisY.PixelPositionToValue(y)
Return coord
End Function
Result:
In your Chart2 window, there's got to be a way to perform an Invalidate with a clipping rectangle.
Another method I use is not to paint directly to the window, but instead paint to a memory bitmap, which I then BLT to the visible window. That can actually be faster because in painting to the bitmap it's not having to slow down to do clipping. This also gives a (fake) impression of speed because I can't see the green lines being redrawn (even though they are).
Yet another method is, when painting the dot where the mouse is, XOR it to the screen.
Then when I move it, XOR it in the old location (to erase it), and then XOR it in the new location. That way, I'm not repainting all those little green lines that haven't moved.
Still another method is: if there are thousands of little lines in the graph, some of them have to be of length zero pixels. They take time to draw even though they contribute nothing to the image, so they could be omitted.
Use Flexcell Grid control
it is superb control it provide all those feature which provide by datagrid control and more
FlexCell is a flexible and easy to use grid control. ... It provides comprehensive functions such as Print, Print Preview, Chart, ... Using FlexCell Grid Control, you can create the professional user interfaces and report form in your application. ... your applications coded in Visual Basic, Visual FoxPro, Visual C++, VB.net, C#, etc.
i want to know if what is the thing that calculate when i call "object.LEFT" in visual basic express 2010, same thing as right bottom and .top..
thankz in advance! ^^
object.left is a property of a control that specifies its relative distance (in pixels) from the control's parent container.
For example: if you have object.left set to 50, then it will push the control in 50 pixels from the left side of the container (i.e. a Form in WinForms development or Page in ASP.NET development).
Yes, I could be more specific if you provided more specific detail about the specific object, and what your purpose was.
In VB there are .Left, .Top, .Width and .Height properties that are usually measured in screen pixels to define the position and size of a Control (ListBox, CheckBox, TextBox, etc) on a Form. Footnote: VBForms can be set to use twips, points, centimeters and inches as their basic measurement.
In Office (Word, PowerPoint, Excel) there are controls that are similar but NOT the same exactly as those in VB UI. They can be placed on a UserForm using these same properties. To place them on a Word document however, you need the .GetPoint method that allows you to specify a .Range object on your document and this function will fill-in the placement information
myWorkingDoc.Windows.Item(1).GetPoint ScPixLeft, ScPixTop, ScPixWidth, ScPixHeight, _
TblControl.Rows.Item(4).Cells.Item(1).Range.OMaths.Item(1).Range
The above line defines 4 Long integers: ScPixLeft, ScPixTop, ScPixWidth, ScPixHeight and a Range object in a word document, in the above case a Word Table named TblControl, the 4th row, 2nd (cell) column. WIthin a Word document window object the .GetPoint method gives one the relative placement, in pixels, within the document window. I use ScPixWidth and ScPixHeight to give me the size of the math equation (OMath object) so I can size an InlineShape to contain it.
Hi I have a button which will add a string in to a label. (this can be done multiple times.) As the user can add multiple strings with each one been a different length, is there anyway I can get it to find the length of the label and those around it so that it spaces out correctly?
Thanks
Label.Width will return the current width of the label control, but it sounds like you already know this. Since the label can be narrower than the text it is trying to display, you would need to measure the full text using the graphics object. This method will return the width of the text in a label:
Private Function getFullTextWidth(lbl As Label)
Using g As Graphics = Label1.CreateGraphics()
Return g.MeasureText(Label1.Text, Label1.Font).Width
End Using
End Function
Alternatively, you could just set the label's AutoSize property to true, and then just check the label's Width property after you set the Text.