I wonder if its possible to use a custom font for my form labels without installing it on the users machine? I would like to display a text using a font I have rights to, but its not installed on the potencial user machine.
Are there any solutions for this?
Here is the extract (using PrivateFontCollection):
Dim pfc As New PrivateFontCollection()
pfc.AddFontFile("C:\Path To\PALETX3.ttf")
label1.Font = New Font(pfc.Families(0), 16, FontStyle.Regular)
Converted from here: Load And Use Custom Font Without Installing It.
Also check this: Embedding/deploying custom font in .NET app
Add this code in Top of your Code
Imports System.Drawing.Text
Add this code on Form1_Load() to change the Lablel1.Font
Dim customfont As PrivateFontCollection = New PrivateFontCollection
customfont.AddFontFile("C:\maven.ttf")
Label1.Font = New Font(customfont.Families(0), 10)
Tested on Visual Basic 2010 Enterprises Edition
Related
I am working on a VB.NET project in Visual Studio Community 2019, using Windows forms. I want to populate a DataGridView with data from a DataSet. But I get an error upon creating the DataSet, saying that "System.Web.Services could not be added to the project". The DataSet is then created, but I cannot chose it as a DataSource for the DataGridView. Maybe it is worthwhile to mention that my project is not intended to deal with anything online, so I wonder why should I need any Web Service stuff. How I can get rid of the error, or at least populate the DataGridView with my DataSet?
I am noticing -thanks Jon!- the following in the VB code (some 600 auto-generated lines) belonging to the DataSet:
Me.DataSetName = "DataSet1"
Me.Prefix = ""
Me.Namespace = "http://tempuri.org/DataSet1.xsd"
and further down:
Dim any1 As Global.System.Xml.Schema.XmlSchemaAny = New Global.System.Xml.Schema.XmlSchemaAny()
any1.Namespace = "http://www.w3.org/2001/XMLSchema"
I do not know how to bind the data to the grid view by hand, I was trying to use the GUI for doing it, which is not offering me the DateSet as source.
For the DataGrid view, I dragged it in from the toolbox where it can be found under "All Windows Forms"->"DataGridView".
worked now around the GUI way of creating a DataSet by
creating an xml which I can load as DataSet
<NewDataSet>
<Table0><col0>entry0row0</col0><col1>entry1row0</col1></Table0>
<Table0><col0>entry0row1</col0><col1>entry1row1</col1></Table0>
</NewDataSet>
reading in the xml by:
Imports System.xml
ds = New DataSet
Using xmlFile As XmlReader = XmlReader.Create(filename, New XmlReaderSettings())
ds.ReadXml(xmlFile)
End Using
DataGridView1.DataSource = ds.Table(0)
I have decades of experience writing VB6 apps but today I tried to write a simple VB.net app using Microsoft Visual Studio 2019. I fell at the first hurdle. I'm sure I'm doing something really simple wrong so forgive the naive question.
Using the toolbox, I added an OpenFileDialog object to my main (one and only) form. Unlike VB6, this didn't appear on the form but in a sort of bar along the bottom of the window, but it was definitely there and I was able to set some properties.
I then added a button and wrote my first line of code:
With OpenFileDialog1
Wrong! I get errpr BC30451: 'OpenFileDialog1' is not declared. It may be inaccessible due to its protection level.
But I can see it sitting there in the design view, I have spelt its name correctly and the above code is
exactly copied from the example. I tried changing OpenFileDialog1's Modifiers property from Friend to Public - makes no difference.
What novice mistake have I made? How do I access an OpenFileDialog object that I have definitely added to my form?
The FolderBrowserDialog which can be dragged onto the form using the toolbox, is out of date and offers (from today's perspective) too few options. Do yourself a favor and use the Nuget Package Manager to download the modern OpenFileDialog.
Imports Microsoft.WindowsAPICodePack.Dialogs
in your Private Sub Button1_Click:
Dim Pfad As String
Using OFD1 As New CommonOpenFileDialog
OFD1.Title = "Datei auswählen"
OFD1.Filters.Add(New CommonFileDialogFilter("JPG", ".jpg"))
OFD1.Filters.Add(New CommonFileDialogFilter("JPEG", ".jpeg"))
OFD1.Filters.Add(New CommonFileDialogFilter("Bitmap", ".bmp"))
OFD1.Filters.Add(New CommonFileDialogFilter("PNG", ".png"))
OFD1.IsFolderPicker = False 'true to make it an FolderBrowserDialog ;-)
OFD1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
If OFD1.ShowDialog = CommonFileDialogResult.Ok Then
Pfad = OFD1.FileName
Else
Return
End If
End Using
for Multiselect (with Bildpfade1 as a New List(of String) ):
Using OFD As New CommonOpenFileDialog
OFD.Title = "Bilder auswählen"
OFD.Filters.Add(New CommonFileDialogFilter("JPG", ".jpg;jpeg"))
OFD.Multiselect = True
OFD.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
If OFD.ShowDialog() = CommonFileDialogResult.Ok Then
For Each file As String In OFD.FileNames
Bildpfade1.Add(file)
Next
End If
End Using
I think I have found the answer but it looks, to me, like a bug in Visual Studio. I saved the project and closed Visual Studio. Restarted and reloaded the project. All the controls I had added to my form had vanished!
I rebuilt the now-empty project then started adding controls - lo and behold, I can now access all my controls from code whereas, previously, I couldn't access any of them. It looks like, prior to the initial build, none of the controls I thought I'd added had actually been added. Certainly they didn't survive save project, restart Visual Studio.
Seems to work now. Many thanks to those who contributed suggestions.
' Download the thumbnail for a note; then display it on this app's form.
Dim thumbnail As Byte() = ENSession.SharedSession.DownloadThumbnailForNote(myResultsList(0).NoteRef, 120)
Try
Dim ms As New MemoryStream(thumbnail, 0, thumbnail.Length)
ms.Position = 0
Dim image1 As System.Drawing.Image = System.Drawing.Image.FromStream(ms, False, False)
PictureBoxThumbnail.Image = image1
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
' Display a note's content as HTML in a WebBrowser control.
Dim myContent = myDownloadedNote.HtmlContent
WebBrowser1.DocumentText = myContent
End If
with these 2 blocks of code from the included "Sampleapp"
i am getting the following errors....
Error 1 'PictureBoxThumbnail' is not declared. It may be
inaccessible due to its protection level.
H:\Michael-Documents\Visual Studio
2013\Projects\WindowsApplication1\WindowsApplication1\Form1.vb 84
17 WindowsApplication1
Error 2 'WebBrowser1' is not declared. It may be inaccessible
due to its protection level. H:\Michael-Documents\Visual Studio
2013\Projects\WindowsApplication1\WindowsApplication1\Form1.vb 91
13 WindowsApplication1
could anyone give me a helping hand, as to what is wrong. Sometimes the Head does not want to think. :-)
This sample app from the Evernote Windows SDK consists of a form with two controls on it named PictureBoxThumbnail and WebBrowser1. I checked the relevant code on Github and confirmed that they are there in the VB.NET SDK sample.
It sounds like somehow in the copy of the app you have in your Visual Studio, the names of these controls have been altered, or the controls may not be on the form at all.
Double-click on the form ("Form1") in the VS Solution Explorer window so as to open it in the VS Designer. There should be one PictureBox control on the left-hand side, named PictureBoxThumbnail, and one larger WebBrowser control on the right-hand side named WebBrowser1. If you don't have either or both of these controls on your form, add them; or if they are not named PictureBoxThumbnail and WebBrowser1, respectively, then rename them to those names. Then the app should run properly.
I have some task to select files in VB6 with the control "CommonDialog1".When the project is migrated this control is converted to openfile dialog.When some of the properties are not converted it is showing as commented.
This line was commented
'CommonDialog1.Flags = CommonDialog1.Flags Or &H80000 ' Dont ALLOWMULTISELECT
I want to know do we have any propery in VB.NET for Open File Dialog Control?
Just make a quick search, or use the help of IntelliSense if you're using Visual Studio.
Dim myOpenFile as New OpenFileDialog()
myOpenfile.Multiselect = False
Documentation
I have looked almost everywhere on the internet and I cannot find a way to download a file from the internet into a specific folder that works with VB.NET 2010. I would like to download a file called, for instance, example.txt, and download it into, for example, %HOMEDRIVE%%HOMEPATH%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup so that it will run automatically at system startup. All help is appreciated
Guessing something based on...
Using webClient = New WebClient()
Dim bytes = webClient.DownloadData("http://www.google.com")
File.WriteAllBytes(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MyFileName.ext"), bytes)
End Using
As for the startup, VB.NET has a pretty ease way to add Registry keys...
My.Computer.Registry.SetValue
To set something like HKEY_CURRENT_USER\Software\Microsoft\CurrentVersion\Run
UPDATE
How to: Create a Registry Key and Set Its Values in Visual Basic
http://msdn.microsoft.com/en-us/library/cy6azwf7(v=VS.100).aspx
I would suggest using WebClient.DownloadFile. Use Environment.SpecialFolder.Startup to get the path to save the file.
Sub Main()
Using wc As New WebClient()
Dim startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup)
wc.DownloadFile("http://MyDomain.com/MyFile.txt", Path.Combine(startupPath, "test.txt"))
End Using
End Sub