Image array help in Silverlight - silverlight-4.0

I'm Back! And having more Silverlight issues (yay!)
I am trying to create an image array in Silverlight but the images are not appearing on the page. Here is my code:
Public imgImages(50) As Image
Public Sub Create_Image_Array()
Dim I As Integer
For I = 0 To 50
imgImages(I) = New Image
imgImages(I).SetValue(Canvas.LeftProperty, System.Convert.ToDouble(0))
imgImages(I).SetValue(Canvas.TopProperty, System.Convert.ToDouble(0))
imgImages(I).Name = "imgImages" & I
imgImages(I).Width = System.Convert.ToDouble(18)
imgImages(I).Height = System.Convert.ToDouble(18)
imgImages(I).Source = New BitmapImage(New Uri("/Resources/yellow2.png", UriKind.Relative))
imgImages(I).Visibility = Windows.Visibility.Visible
AddHandler imgImages(I).MouseLeftButtonUp, AddressOf ImageClickEventProc
Next I
End Sub
Public Sub Draw_Images()
For I = 1 To secObject.intNumberOfImages
imgImages(I).SetValue(Canvas.LeftProperty, System.Convert.ToDouble(secObject.Images(I).intPosX))
imgImages(I).SetValue(Canvas.TopProperty, System.Convert.ToDouble(secObject.Images(I).intPosY))
imgImages(I).Visibility = Windows.Visibility.Visible
Next I
End Sub
The image array is created when the page is navigated to and then the page requests location information from a server and once it has that information it sets the X and Y coordinates of the images. All that part works fine - that was apparently the easy part - All the coordinate information is received and stored in secObject, the data is there. The URI for the resource of the image is there and it is valid, I tested it with another image control on the page.
The problem is that the little images are not displaying. I have tried numerous ways of getting them to display. I have found code on Google that does almost the exact same thing that I am trying to do and it is written in a similar way just for non-arrayed images.
I also tried another suggestion, to use TranslateTransform to set the positions of the images. This did nothing.
Dim tt As New TranslateTransform
tt.X = secObject.Images(I).intPosX
tt.Y = secObject.Images(I).intPosY
imgImages(I).RenderTransform = tt
I also removed the background image on the screen thinking that maybe the images were rendering below the background, and that is not the case.
Am I missing something? I admit to being a Silverlight n00b...
Thanks
-RW

OK I finally figured it out... I needed to create add the controls to the canvas:
LayoutRoot.Children.Add(imgImages(I))

Related

MigraDoc Rotate Image (vb.net)

I am trying to create a PDF using MigraDoc Library. I can add an image, but unable to rotate images. I am creating a MigraDoc.DocumentObjectModel.Shapes.Image object to add the image to a section. Is it possible to rotate the image or do I have to add the image another way?
Public Sub AddImageToPDFFile(sec As Section)
Dim image As Image
Dim strImagePath = "image.jpg"
image = sec.AddImage(strImagePath)
image.Height = "10cm"
image.LockAspectRatio = True
image.RelativeVertical = RelativeVertical.Line
image.RelativeHorizontal = RelativeHorizontal.Margin
image.Top = ShapePosition.Top
image.Left = ShapePosition.Left
image.WrapFormat.Style = WrapStyle.Through
End Sub
I'm afraid MigraDoc cannot rotate the image.
Maybe rotate the image with code before adding it to MigraDoc.
It might also be possible, depending on your requirements, to add the image later using PDFsharp. MigraDoc uses PDFsharp to create the PDF and thus you can use PDFsharp for modifications without adding an additional tool to the process.

CefSharp SetZoomLevel not working

I am using in a WinForm an object of type:
CefSharp.WinForms.ChromiumWebBrowser
Everything is working fine but I am having an issue when I try to change the ZoomLevel with SetZoomLevel method:
If oBrowser.IsBrowserInitialized Then
oBrowser.SetZoomLevel(-2.0)
Dim frame As CefSharp.IFrame = oBrowser.GetMainFrame
Dim request As CefSharp.IRequest = frame.CreateRequest()
request.Url = url
request.Method = "POST"
request.InitializePostData()
Dim element = request.PostData.CreatePostDataElement()
element.Bytes = postDataBytes
request.PostData.AddElement(element)
request.Headers = headers
frame.LoadRequest(request)
End If
The first time I open the WinForm the Zoom level doesn't change, while it works correctly from the 2nd refresh.
Am I missing some initialization and/or method call... Or do I have to call this method in another position?
Note: the CEFSharp DLL version is 63.0.3.0.
The .NET Framework is 4.5.2
EDITED 01.06.2018: I've found a solution (see below) but now there's another problem: the zoom change is made when the browser is already visible, so it's not nice for the final user to see the page size changing during the form load.
Has anyone a suggestion to freeze the layout during zoom change? Please note that .SuspendLayout() and .ResumeLayout() are not working.
I've found a way to answer my own question. I post it here as it could be useful to other users.
You must add a LoadingStateChanged handler to the ChromiumWebBrowser object:
AddHandler oBrowser.LoadingStateChanged, AddressOf WebBrowserOnLoadingStateChanged
The method would be then something like:
Private Sub WebBrowserOnLoadingStateChanged(ByVal sender As Object, ByVal loadingStateChangedEventArgs As LoadingStateChangedEventArgs)
Dim oBrowser As WinForms.ChromiumWebBrowser = CType(sender, WinForms.ChromiumWebBrowser)
If Not oBrowser.IsLoading Then
oBrowser.SetZoomLevel(-2.0)
End If
End Sub
This solution works good in my environment but now there's another problem: the zoom change is made when the browser is already visible, so it's not nice for the final user to see the Zoom Level changing during the form load.

Drawing bitmaps via BitmapBrush onto SlimDX Geometry (VB.NET )

I have a program where I am attempting to render an image in Direct2D onto a quadrilateral using SlimDX and VB.net.
The program gets an array of 4 points from a server, which are a quadrilateral, where the image should be rendered onto.
The points (For example) are:
points(0) = 20,10 <--Top left, where the geometry starts from
points(1) = 40,10 <-- Top right
points(2) = 40,40 <-- Bottom right
points(3) = 20,40 <-- Bottom left
...A BitmapBrush is constructed when loading and the Bitmap can be rendered fine, but when trying to render onto the quadrilateral, I only get (it seems...) some part the bottom right corner.
For reference: Here is the image I'm trying to draw:
http://i.imgur.com/Dt3iHQ3.png
And here is the code that I'm trying to use (for drawing the image).
R is the point list (see above) and RenderBrush is a BitmapBrush created from a 20x30 version of that image.
Private Sub DrawPoly(R() As PointF, ByRef RenderBrush As SlimDX.Direct2D.BitmapBrush)
'Create the geometry
Dim Path As PathGeometry
Path = New PathGeometry(factoryD2D)
Console.Clear()
'Get a handle to the Geometry
Dim Geometry = Path.Open()
'Set UP Geometry
Geometry.BeginFigure(R(0), FigureBegin.Filled)
Geometry.AddLines(R)
Geometry.EndFigure(FigureEnd.Closed)
Geometry.Close()
'Render
D2DRenderTarget.FillGeometry(Path, RenderBrush)
'and GC
Geometry.Dispose()
Path.Dispose()
End Sub
Thanks in advance for your help!
I figured it out. To get it to draw onto the geometry, you need to set up a transformation matrix like so:
Matrix3x2.Multiply(Matrix3x2.Translation(Point_To_Move_To), Matrix3x2.Rotation(Rotation, Point_To_Rotate_Around))

Windows 8 App - Programmatically Added Path Disappears

Any help with this would be much appreciated.
I am trying to build an app in Windows 8 using xaml and vb.
To test the process of adding a path dynamically to the UI I have created a class that draws a circle using a path (code below). The code fires when a button is tapped/clicked.
The circle then appears briefly near the centre of the screen but then disappears.
If I then count the children on the grid, the circle is counted. Its just not visible.
I'd like to understand what is happening and stop the circle from disappearing.
Dim path As New Windows.UI.Xaml.Shapes.Path
Dim rectG As New EllipseGeometry
rectG.Center = New Point(500, 500)
rectG.RadiusX = 100
rectG.RadiusY = 100
path.Data = rectG
path.Stroke = New SolidColorBrush(Windows.UI.Colors.LightGreen)
path.StrokeThickness = 1
path.Fill = New SolidColorBrush(Windows.UI.Colors.LightGreen)
path.Name = "TestName"
_TargetGrid.Children.Add(path)
Finally figured it out. I needed to set the column and row span property.
On the test I did it using the code although in a proper app it would probably make sense to use some kind of predetermined styling.
However, here is the code I added:
path.SetValue(Grid.ColumnSpanProperty, 5)
path.SetValue(Grid.RowSpanProperty, 5)

How to Draw above a picture in VB.NET

I am building a 2D game where the user is a circle(:P) and the enemies are rectangles coming at him. However, my problem is that when I placed a very nice picture of space I found on the internet, the screen draws whatever it has to underneath this image. Everything works,I can still see my lives going down when something collides into me - except the fact it is all covered up by this picture.
In a nutshell, my question is: How Do I Draw everything ON Top of this - (I tried using the 'Send To Back' Command)
EDIT: The form draws everything through a timer, and the user controls his character through keys. This probably won't help - but if it does it's here.
Sorry folks didn't think you'd need the code. Here it is:
In the mybase.load procedure:
PicBackGround.Dock = DockStyle.Fill
PicBackGround is the picture box with the image.
In the paint procedure:
e.Graphics.Clear(Color.Black)
e.Graphics.FillEllipse(Brushes.Orange, Player)
'Projectiles
Dim i As Integer = 0
Do
If Current_Projectile(i).IsEmpty = False Then e.Graphics.FillRectangle(Brushes.Red, Current_Projectile(i))
i += 1
Loop Until i = UBound(Current_Projectile)
'Objects
i = 0
Do
If Objects(i).IsEmpty = False Then e.Graphics.FillRectangle(Brushes.Blue, Objects(i))
i += 1
Loop Until i = UBound(Objects)
Okay: Player is a rectangle declared right at the top, Dim Player As New Rectangle(0, 0, 50, 50);
There is then the array Objects, which stores all the data about the enemies coming at the player, Current_Projectiles is simply an array to store data about rectangles(bullets) that the player fires.
Anything else you want to know just let me know.
Yes, a control overlaps anything you draw on the form. A simple solution is to use the form's BackgroundImage property instead. Or draw the image yourself.