VB.NET Form Icon Error - vb.net

Everytime I set the form icon, I get the following error :
Value of type 'System.Drawing.Icon' cannot be converted to 'String'
I have tried both external icon file and resources method, but none worked.
Dim X as new System.Drawing.Icon("icon.ico")
Me.Icon = X
and
Me.Icon = My.Resources.Icon
Same thing if I create a new project.
Any help is appreciated, and thanks in advance!

If you are developing a WinForms application, your first attempt should work:
Me.Icon = New System.Drawing.Icon("path/to/.ico/file")
If you are writing your UI with WPF, then the .Icon property expects an ImageSource object:
Dim iconUri As New Uri("pack://application:,,,/WPFIcon2.ico", UriKind.RelativeOrAbsolute)
Me.Icon = BitmapFrame.Create(iconUri)
The second example is directly taken from the MSDN.

Related

Display a files icon in a PictureBox

I know there is a lot of these noob questions already.
I wrote a small code for display the Icon from a file in a PictureBox and its not working :|
Button6.BackgroundImage = Bitmap.FromHicon(
New Icon(OpenFileDialog1.FileName, New Size(48, 48)).Handle
)
The error says:
Argument 'picture' must be a picture that can be used as a Icon
If anyone know whats the problem, please write it down.
This error means that the file you are trying to open is not an icon. An icon file has extension .ico. Also you need to open the OpenFileDialog1 before geting the selected file name:
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
Button1.BackgroundImage = Bitmap.FromHicon(New Icon(OpenFileDialog1.FileName, New Size(48, 48)).Handle)
End If

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.

using Class TextToolStripSeparator

Hi Imm trying to use the Class TextToolStripSeparator, as provided here.
How to add informative text to menu strip separator in vb.net or C#
I am having dificulty implementing the solution. I have placed the classes in and have created a separator but I can't seem to figure out how to place the text. I am using a dynamicaly created ContextMenuStrip in a datagridview from a right click.
Dim menu As ContextMenuStrip = New ContextMenuStrip
Dim NewSep1 As New TextToolStripSeparator
menu.Items.Add(NewSep1)
menu.Show(Me, pt.X, pt.Y)
when I tryto add text like menu.Items.Add(NewSep1("-test-")) I get an error:
Error 1 Class 'myprog.TextToolStripSeparator' cannot be indexed because it has no default property.
What am I doing wrong?
It looks like you need to set the seperator's .Text property.
Dim NewSep1 As New TextToolStripSeparator
NewSep1.Text = "-test-"
menu.Items.Add(NewSep1)

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

creating table at runtime in vb.net, image control doesnt have imageurl proerty

i am creating a table in vb.net code (htmltable) with htmltablerows and htmltablecell. I gave on image control but thatr control cant have the .imageurl property, which i need cause i have a handler image.ashx which brings image from the database.
heres' the code -
TD = New HtmlTableCell
Dim img As New HtmlImage()
img.ID = "image_" & rd("ID")
img.Style.Add("width", "100px")
img.Style.Add("height", "100px")
img.ImageUrl = "Image.ashx?id=" & rd("ID")
on the last line, "img.ImageUrl" i get this error -
'ImageUrl' is not a member of 'System.Web.UI.HtmlControls.HtmlImage'
how do i fix this?
ImageUrl is a member of the System.UI.WebControls.Image control. By contrast, you are using the direct HtmlImage control which is rendered exactly as an img tag would be. You should use the Src property of the HtmlImage control instead.