|
Hi Richard,
Thank you for your reply.
I am clueless to what you mean. Sorry. Can you give an example of what way that would be done?
I am just learning so any help is appreciated.
Thank you.
|
|
|
|
|
You need to follow that link and read the documentation. You could also try searching the articles section for samples.
Veni, vidi, abiit domum
|
|
|
|
|
You cannot upload a file to the Resources folder. L:ook in the bin\Debug or bin\Release folder in your project in Windows Explorer, NOT in Solution Explorer. Notice there is no Resource folder in there.
Resources are files that are compiled into your resulting executable. You cannot add items to Resources are run-time.
You'll have to change this functionality to put user-uploaded files into a folder your application controls, like CommonApplicationData, and keep track of that filepath in your profile data structure.
|
|
|
|
|
Hi folks,
Thanks so much for the help so far.
I have tried the following, from what I can understand, but it says that
"Await is not Declared. It may be inaccessable due to its protection level"
and:
"CopyToAsync is not a member of System.IO.FileStream"
The code I have tried is:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim StartDirectory As String = "Resource\Start"
Dim EndDirectory As String = "Resource\end"
For Each filename As String In Directory.EnumerateFiles(StartDirectory)
Using SourceStream As FileStream = File.Open(filename, FileMode.Open)
Using DestinationStream As FileStream = File.Create(EndDirectory + filename.Substring(filename.LastIndexOf("Resource")))
Await(SourceStream.CopyToAsync(DestinationStream))
End Using
End Using
Next
End Sub
Thanks in advance for any guidance. As I said, I am totally new.
|
|
|
|
|
Uhhh... Await?? You're a beginner. Don't start trampling through multi-threading code. You're not there yet.
Also, unless you're using VS2012 or 2013 and your project is targeting the .NET Framework 4.0 or above, you don't have access to Await. Even with .NET 4.0, I think you needed to add the "Async Targeting Pack" to your project to get at it.
Now, again, you have a problem. The directory structure you see in Solution Explorer does NOT exist on disk in your compiled application! The Resources folder does NOT exist as far as your code is concerned. You cannot enumerate the files in it because it's a concept that only exists inside Visual Studio and only up to compile-time. Once your project is compiled, the Resources folder essentially does not exist.
|
|
|
|
|
Hi David,
Thank you.
Yes, I created a new folder inside Bin/Debug called Resource, which is the one being used now.
I have no clue about what code to use as I said at the start, which is why I posted here, hoping to get some guidance.
Thanks.
|
|
|
|
|
Hi guys,
The following seems to work a bit.
If (Not System.IO.Directory.Exists("Resource")) Then
System.IO.Directory.CreateDirectory("Resource")
End If
Dim OpenFileDialog1 As New OpenFileDialog
With OpenFileDialog1
.CheckFileExists = True
.ShowReadOnly = False
.Filter = "All Files|*.*|Bitmap Files (*)|*.bmp;*.gif;*.jpg"
.FilterIndex = 2
If .ShowDialog = DialogResult.OK Then
Dim FName() As String = OpenFileDialog1.FileName.Split("\\")
System.IO.File.Copy(OpenFileDialog1.FileName, "Resource\\" + FName(FName.Length - 1))
PictureBox1.Image = Image.FromFile(.FileName)
Profile.PictureBox1.Image = Image.FromFile(.FileName)
End If
End With
It saves the image to the /bin/debug/Resource folder and displays it in the PictureBoxs as shown in the code. But when I close the program and open it again the images are no longer displayed.
Any ideas?
Thank you.
|
|
|
|
|
There isn't enough code here to definitively say what's wrong. But, one problem I see is that you're using relative path names. You're ASSUMING that the "current directory" is always the same. That's just not true, especially when using the Open/SaveFile dialogs. They change the "current directory" as you navigate through them.
ALWAYS, ALWAYS, ALWAYS, build and use absolute paths using well-known roots, such as:
Dim appPath As String = Application.StartupPath
Dim resourcesFolderPath As String = Path.Combine(appPath, "Resources")
Dim imageFilePath As String = Path.Combine(resourcesFolderPath, someUserPickedFilename)
Also, use Path.Combine to build paths. What you're doing, first, contains double backslash characters, which don't apply in VB.NET, only in C/C++/C#. Using Path.Combine, you don't worry about the backslashes at all.
You don't have to slpit a filepath from an OpenFileDialog. It'll return the full path to the selected file. From there, you use the Path class and its methods to get the filename. You don't need to split the string on, again, double backslashes which don't work in VB.NET. In VB.NET, it's a single backslash.
Dim filename As String = Path.GetFileName(userSelectedPath)
|
|
|
|
|
Hi Dan,
I have read through your correspondence with the others and I do not disagree at all with what they have been telling you. However, I would like to propose an alternative method based on what you have said.
You want to allow the user to select image to display on your form and you also want this selection to persisted between program executions (i.e. a user setting). VB.Net provides you an easy mechanism to persist variables using the My.Settings feature. You can access and define these settings by double clicking "My Project" in the Solution Explorer window and then clicking on the Settings tab.
The only issue is that the VS designer will not allow you to select "System.Drawing.Image" as the setting Type. Don't worry about that, it is only a limitation in the code generation capability of the designer and not that you can not store an image. The big requirement is that that type that you wish to store provides a mechanism to serialize the class instance. If you look at the documentation for the Image Class[^], you will see that is defined:
'Declaration
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
<TypeConverterAttribute(GetType(ImageConverter))> _
Public MustInherit Class Image _
Inherits MarshalByRefObject _
Implements ISerializable, ICloneable, IDisposable That <SerializableAttribute> is key to making this work. You will just have to provide the code to add the setting yourself. VB.Net handles these settings as Properties of the MySettings Class in the My namespace. Add a new Class file to your project and replace the autogenerated code with the following snippet.
Namespace My
Partial Friend NotInheritable Class MySettings
' The trick here is to tell it serialize as binary
<Global.System.Configuration.SettingsSerializeAs(Configuration.SettingsSerializeAs.Binary)> _
<Global.System.Configuration.UserScopedSettingAttribute()> _
Public Property StoredImage() As System.Drawing.Image
Get
' the String in: Me("StoredImage") must be the name of the setting
Return DirectCast(Me("StoredImage"), System.Drawing.Image)
End Get
Set(ByVal value As System.Drawing.Image)
' the String in: Me("StoredImage") must be the name of the setting
Me("StoredImage") = value
End Set
End Property
''' <summary>Dictionary of Images keyed on username</summary>
<Global.System.Configuration.SettingsSerializeAs(Configuration.SettingsSerializeAs.Binary)> _
<Global.System.Configuration.UserScopedSettingAttribute()> _
Public Property UserImages() As Dictionary(Of String, System.Drawing.Image)
Get
' the String in: Me("UserImages") must be the name of the setting
If Me("UserImages") Is Nothing Then
Me("UserImages") = New Dictionary(Of String, System.Drawing.Image)
End If
Return DirectCast(Me("UserImages"), Dictionary(Of String, System.Drawing.Image))
End Get
Set(ByVal value As Dictionary(Of String, System.Drawing.Image))
' the String in: Me("UserImages") must be the name of the setting
Me("UserImages") = value
End Set
End Property
End Class
End Namespace I have defined two Properties (StoredImage and UserImages) because I was not completely clear if your application needed to store a single image or an image for each user of the application under the same installed account. The Dictionary property gives you the ability to store multiple images keyed to a String value.
Here is a sample usage based on a Form with two Buttons and two PictureBoxes. I think you can figure this code out, but feel free to ask questions.
************** Edit: The example usage code I thought that I included.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim imgdialog As New System.Windows.Forms.OpenFileDialog()
imgdialog.Filter = "Image Files (*.bmp, *.jpg)|*.bmp;*.jpg|All Files (*.*)|*.*"
If imgdialog.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim img As Image = Image.FromFile(imgdialog.FileName)
My.Settings.StoredImage = img
If My.Settings.UserImages.ContainsKey("username") Then
My.Settings.UserImages("username") = img
Else
My.Settings.UserImages.Add("username", img)
End If
My.Settings.Save()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
PictureBox1.Image = My.Settings.StoredImage
If My.Settings.UserImages.ContainsKey("username") Then
PictureBox2.Image = My.Settings.UserImages("username")
End If
End Sub
End Class ************* End Edit
Some reference material:
To find where the config file is stored see the response from Johan Stenberg[^]
My.Settings Object[^]
modified 5-Feb-14 16:50pm.
|
|
|
|
|
Hi TnTinMn,
Thank you so much for that explanation and detailed rundown. It is beginning to make sense now.
I placed that code into Class.VB though and get the following:
Any advice on that would be so appreciated.
Thanks again,
Dan
|
|
|
|
|
Hmm, you must of copied the code by hand and named both properties StoredImage.
The second property in the example is name UserImages (the Dictionary).
|
|
|
|
|
I just edited my post and included the sample usage code that I thought I put in there last night.
To verify that this code should work, I copied and pasted from my post into VS2010 Express and it all ran fine.
Like I said above, maybe you made a typo in your attempt.
|
|
|
|
|
A docking pane is set to AutoHidePortion and permitted docking is DockLeft with AllowEndUserDocking = False
The design width of the form is 200px and the initialisation command is .Show(dockPanel, DockState.DockLeftAutoHide)
Despite the fact that AutoHidePortion is > 1 the pane is showing at around 315px = 1/4 the form width.
I have just moved from DPS ver 2.5 to ver 2.8 and in ver 2.5 this behaviour is not apparent and the form (pane) displays at the required size. I an using VB 2010.
Does anyone have any further information on this, workarounds or fixes?
I can't seem to find anything specific on the web, or in Code Project.
Thanks.
modified 31-Jan-14 11:09am.
|
|
|
|
|
TheComputerMan wrote: I can't seem to find anything specific on the web, or in Code Project. That's probably because it is not part of the .NET Framework.
Are you referring to this[^] suite? If yes, then your question should go here[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
It is implemented in Visual Basic therefore the question is legitimate. I will ask in the suggested forum however although I have already searched that and found nothing specific.
|
|
|
|
|
TheComputerMan wrote: It is implemented in Visual Basic therefore the question is legitimate. I never said it wasn't.
TheComputerMan wrote: I will ask in the suggested forum however although I have already searched that and found nothing specific. I doubt that there'll be specific information readily available. The reason I pointed there is because a support forum dedicated to that suite will probably have more expertise than a general .NET forum.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
It's OK I understand what you were saying, but I was thinking that maybe people ding the job had come across the problem and fixed it or got a workaround.
Unfortunately there is nothing much about it on that site. The problem gets a mention. Apparently it appeared in 2.6 and has not been fixed satisfactorily as far as I can tell. The forum is a bit 'thin' to say the least.
In the end, because the code has to address .NET 4.0 I simply re-compiled version 2.5 to target the .NET 4.0 framework. Since the problem does not exist in 2.5 I am happy and I am not concerned about the additions in later versions that i will not have by using 2.5.
At least if someone else experiences the problem our discussion is here to give them a pointer. Thanks for your input.
|
|
|
|
|
TheComputerMan wrote: I simply re-compiled version 2.5 to target the .NET 4.0 framework. Since the problem does not exist in 2.5 I am happy Whehe, nice pragmatic approach
Well done
|
|
|
|
|
Hello,
I have built a custom control where I use a label to effectively work as a button on this control.
The problem is, when I place this control on my forms, I want the click event of that label to handle the click event of the user control. The label takes up the whole UserControl form.
Hope this makes sense, and any help would be appreciated!
Thanks
|
|
|
|
|
I really do not understand what you mean by " I want the click event of that label to handle the click event of the user control.". If you mean that you want to raise the usercontrol click event when the label is clicked, then this should do the trick.
Public Class UserControl1
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
OnClick(e)
End Sub
End Class
|
|
|
|
|
That's what I meant, and that's what I need!
Thanks you very much, this does the trick
|
|
|
|
|
If the Label takes up the entire surface of the UserControl, the UserControl will never fire the Click event. The click will land on the Label since the mouse cannot "see" the UserControl surface through the label.
Or is there something you're not describing in your post??
|
|
|
|
|
Yes the label taking up the entire surface was the issue, solved with Me.OnClick(EventArgs.Empty). Thank you for your reply sir
|
|
|
|
|
Hi Community,
i have designed a database model with entity designer in vs 2013 express. the project results in a database and the datacontext class.
every table has an id column, witch is the primary key. my problem is now, that i want to impelement an interface for each entity wich contains a property id -> is needed for the generic repository pattern. i have tried to extend the designer generated code of the datacontext, but every time the project is rebuild, the manually added code is lost.
there must be an better way to extend the designer code with the interface implementation or?
best regards from northern germany
|
|
|
|
|
You cannot modify the designer generated code, you need to add your code to a separate source file.
Veni, vidi, abiit domum
|
|
|
|