Windows 8 App - Programmatically Added Path Disappears - vb.net

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)

Related

How to avoid image overlap of label.image when new image is created at regular intervals in vb .net

Ive created a label that is truly transparent using the below codes. By truly transparent I mean, even if the background of the label changes, the label remains transparent. Something that cannot be achieved using the conventional method i.e. using transparency key.
Dim Source_point As Point = New Point(Me.Left + 128, Me.Top + 57)
Dim g As Graphics = Graphics.FromImage(ScreenGrab)
g.CopyFromScreen(Source_point, Point.Empty, ScreenGrab.Size)
LabelBatteryLevel.Image = ScreenGrab
The above codes are within a timer.Tick sub. Ive used timer so as to update the image of the label when the background changes. Now the problem is, after every interval of the timer, the item(image) of LabelBatteryLevel.Image gets recreated and overlaps the the image created at the previous interval. This looks shabby at runtime. How do I remove the image created at previous interval before a new image gets created in the next interval?
You can use the Graphics.Clear Method before drawing another image.
Dim g As Graphics = Graphics.FromImage(ScreenGrab)
g.Clear(transparencyKeyColor)
g.CopyFromScreen(Source_point, Point.Empty, ScreenGrab.Size)

How to change the background color of a windows context menu using the winapi

I am currently trying to customize a context menu in Outlook. For the regulars I have had a series of issues which can be seen in this question and with this question.
I would like to adjust the background color a little.
Dim hBrush As IntPtr = NativeMethodsEX.CreateSolidBrush(ColorTranslator.ToWin32(System.Drawing.Color.Red))
Dim mi As New NativeMethodsEX.MenuInfo
With mi
.cbSize = Marshal.SizeOf(mi)
.fMask = NativeMethodsEX.MIM_STYLE Or NativeMethodsEX.MIM_BACKGROUND Or NativeMethodsEX.MIM_APPLYTOSUBMENUS
.dwStyle = NativeMethodsEX.MNS_NOCHECK
.hbrBack = hBrush
End With
NativeMethodsEX.SetMenuInfo(aHwnd, mi)
This code however produces this;.
How can I also change the background of the left hand side or what even is the class name of that part of the window. Also it has a border as well. What is its class name or how can I either remove it or change it?

How to set a background color of a control in windows 8 store application

I am designing an application and had to instantiate controls via code. The problem is that I am unable to change the background color. I tried to look all over the internet, but no succes. I have contacted the Microsoft support service, but no succes either.
I read that you normally change a color by using System.Color or System.ColorHelper. Both are not accesible in the application.
So how to solve the following problem:
TextBox^ txtID = ref new TextBox();
txtID->Background = ?;
I have the solution, first make a brush object and set the color and assign that color to your controls background. I used the following:
SolidColorBrush^ myBrush = ref new SolidColorBrush(Windows::UI::Colors::Red);
TextBox^ txtID = ref new TextBox();
txtID->Background = myBrush;

Image array help in Silverlight

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))

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.