Jump to content
Xtreme .Net Talk

snarfblam

Leaders
  • Posts

    2156
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by snarfblam

  1. The code you have above is sure to run into problems. It's entirely possible for the windows folder to have any arbitrary name, on any drive. If the user installed windows to "F:\LesFenetres", you would never find it that way. Most of the time, you can get the path to special folders (desktop, system, application data, etc.) using the Environment.GetFolderPath function. For some reason, they didn't include the windows directory in the list of special folders, but there is another way we can get special folder paths. You had the right idea with %SYSTEMROOT%. There is also %WINDIR%. They both seems to return the path to the windows folder. I'm not sure if the two variables serve different purposes, but I think you'll be fine with either one. We can get the value for any of these environment variables with the handy Environment.GetEnvironmentVariable function. Dim WinPath As String = Environment.GetEnvironmentVariable("SYSTEMROOT") That should get you what you need.
  2. I'm not clear on exactly what you are trying to do, but if you're looking to encrypt files, you'll want to check out the System.Security.Cryptography namespace. There are plenty of tutorials and articles on encryption, for example, http://www.codeproject.com/KB/security/EncryptFile.aspx. I suggest you check out the tutorials and documentation that already exist, and if you get stuck or have a more specific question, we'll be glad to try to help.
  3. Hi Saloni, and welcome to the forum! If you haven't done so already, I ask that you look over the Posting Guidelines. As to your question, if you haven't got the vaguest idea as to how to start or approach a project like this, I would take it as a sign that you might be setting your sights too high. I don't know where your skill level lies, but it sounds like you should work with some more practical projects before moving on to something advanced like this. Also, even though your intent may be good, this sort of tool could be construed as malicious. A tool that hooks into a user's browser can be user for all sorts of nefarious purposes. We tend to avoid helping with this sort of project.
  4. Well... you need to know what size you want the image to be. Other than that, it only takes one line of code, as shown above. I don't think you can ask for anything easier.
  5. Not sure what you mean by "get the zoomed image." Do you want to create a scaled-up copy of the bitmap? If so, the Bitmap class has a constructor that creates a scaled copy. For instance, to create a 2x scaled bitmap, you could do this: // C# System.Drawing.Bitmap scaledImage = new System.Drawing.Bitmap(originalImage, new Size(originalImage.Width * 2, originalImage.Height * 2)); ' VB Dim scaledImage As New System.Drawing.Bitmap(originalImage, New Size(originalImage.Width * 2, originalImage.Height * 2)) But unless you're looking to save the scaled image to a file, it may not make much sense to create it in the first place. If you are using it for drawing, the Graphics.DrawImage method has overloads that allow you to draw an image scaled on the fly, without creating new copies of the image.
  6. You might want to check out http://support.microsoft.com/kb/304662. Basically, most Microsoft Office documents are ActiveX documents, which can be shown in a WebBrowser control.
  7. It looks like your code listing is incomplete. The issue is probably "scope". Most likely, your are declare the button and label variables as locals (i.e. they belong to a sub or function), when what you really want are fields (they belong to the class). Class Form1 Inherits Form Sub New() Dim Label1 as New Label Dim Button1 as New Button Me.Controls.Add(Label1) Me.Controls.Add(Button1) AddHandler Label1.MouseEnter, AddressOf MousyEnter End Sub Private Sub MousyEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Button1.Text = "What's up!" ' [color="Red"]ERROR: MousyEnter does not know what Button1 is.[/color] End Sub End Class In this case, the variables Button1 and Label1 belong to Sub New. This is the scope of the variables. They have local scope (local to Sub New) and are referred to as "locals." They can only be accessed from Sub New. You can change it like so: Class Form1 Inherits Form [color="Blue"] Dim Label1 as New Label Dim Button1 as New Button [/color] Sub New() Me.Controls.Add(Label1) Me.Controls.Add(Button1) AddHandler Label1.MouseEnter, AddressOf MousyEnter End Sub Private Sub MousyEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Button1.Text= "What's up!" End Sub End Class Now Button1 and Label1 are declared outside Sub New, so they belong to the whole class. The variables have class scope. You can access them anywhere inside Form1. You can also access controls without using variables at all, but you must give the control a name. Class Form1 Inherits Form Dim Label1 as New Label Dim Button1 as New Button Sub New() [color="Green"] ' Button1 would probably be a more appropriate name, but it can be anything you want [/color] [color="Blue"] Button1.Name = "LeButton"[/color] Me.Controls.Add(Label1) Me.Controls.Add(Button1) AddHandler Label1.MouseEnter, AddressOf MousyEnter End Sub Private Sub MousyEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) [color="Blue"] Controls("LeButton").Text= "What's up!" [/color] End Sub End Class
  8. In your example, Textbox1.Text.Length, the Textbox1.Text property returns string, which provides it's own properties, such as Length. You would have to do the same thing. You would need a Note class (or struct) that the property returns. Public Structure Note Dim _Value As Integer Public Sub Note(value As Integer) _Value = value End Sub Public Readonly Property Value() As Integer Get Return _Value End Get End Property Public ReadOnly Property Name() As String Get Throw New NotImplementedException("Put some code here") End Get End Property Public ReadOnly Property MidiNumber() As Integer Get Throw New NotImplementedException("Put some code here") End Get End Property End Structure Now you can create the Note property in your Music class. Dim _Note As Note Public Property Note() As Note Get Return _Note End Get Set(ByVal value As Note) _Note = value End Set End Property Then, you could access it like so. Music.Note = New Note(32) MessageBox.Show(Music.Note.MidiNumber.ToString()) MessageBox.Show(Music.Note.Name) Notice that all the properties are declared "Readonly." When working with structures, it's a good idea to make them immutable (meaning the Note objects can't be changed, but you can assign a new Note object to the Music.Note property.) If your curious, here is an explanation of why structures should be immutable. Or, just make Note a class instead of a structure.
  9. If you're going to be using these exactly like controls, why would you create them as forms? It's no extra effort to use a UserControl instead. All you are doing is opening yourself up to the possibility of quirky or problematic unexpected behavior.
  10. One thing worth noting is that when you have declarations with initializers (such as Public FormMain as frmMain = frmMain), even though you don't write the code in the Sub New (i.e. the class constructor or type initializer), when the program is compiled, that is where it ends up, so an error on a field initializer can result in a type initializer exception. What you really need to do is catch the exception right off the bat. For some reason, the originating exception is not being caught, and you're getting the resulting type initializer exception. If nothing else works out, you should be able to see the original exception in the InnerException property of the type initiailizer exception, which should include a stack trace. It would help to set VS to break when any exception is thrown. If you go to "Exceptions" under the "Debug" menu, in the dialog that appears there are two columns of checkboxes. By default only "User-unhandled" is checked. Try checking the "Thrown" box as well. (You can probably leave "Managed Debugging Assistants" alone). Hopefully that will get VS to show you the root cause of the problem.
  11. Hi, and welcome to the forum! You'll probably find you get the best answers if you provide as much relevant information as possible. I don't know how you are managing/showing/hiding/closing these forms, but I'll try to give the best answer I can. It sounds like the first form is a splash screen, so I'm going to go on that assumption. The best answer depends on how you are showing the splash screen to begin with. If you are using the "application framework" feature, Microsoft offers an explanation of how you should manage your splash screen. If you are not using the application framework, you'll want to modify your program's Sub Main to get the behavior you want. Ideally, you should be closing the splash screen as soon as you are done with it, not just hiding it. However, this would cause an issue if the splash screen is your "Startup Object" because VB would think that the splash screen is your main form, and the program would end when the splash screen is closed. To fix this, you would want to make the following change to your sub main: [color="SeaGreen"]' change [/color] Application.Run(New [i]splashScreenForm[/i]()) [color="SeaGreen"]' to [/color] Application.Run() Dim splash As New [i]splashScreenForm[/i]() splash.Show() Or, if you don't have a sub main, you can add a new module to your project and add a sub main. Sub Main() Application.EnableVisualStyles() Application.Run() Dim splash As New [i]splashScreenForm[/i]() splash.Show() End Sub You'll also want to make sure your "Startup Object" is set to "Sub Main" in the project properties. These changes result in your program not having a main form. A program usually ends when the main form is closed, but when no form is the main form, you simply have to tell the program when to end explicitly by calling Application.Exit (you'll probably want to call this in the Form.Closed event of one of your forms). Hopefully, that helps you solve your problem.
  12. If you look under the "Compile" tab in the project properties, there is an "Advanced Compile Options..." button. In the window that comes up, there is a check box marked "Define DEBUG constant". As long as this is checked, I don't see why things shouldn't work as expected.
  13. I think your best bet is a TabControl replacement. There are plenty of free ones out there, available in various styles (OS, FireFox, Visual Studio, etc.), and they generally come with many more features than the standard WinForms tab control. For example, I easily found this FireFox-style tab control on CodeProject.
  14. havens1515, I edited your post to remove the link. It's best to link to a copy of your project rather than to an executable. That way we're safe from viruses and the like, and we can help you better if we can see the code. Anyways, the root of the problem is that when you move the card up 30 pixels, it causes the mouse to be outside the picture box, raising the MouseLeave event. This causes you to move the PictureBox back, which causes the mouse to re-enter the PictureBox, ad infinitum. The ideal solution would be to do away with the picture boxes and do all the drawing and mouse processing yourself, but that's, like, work. A solution that would involve less work would probably involve a different, more complicated way of detecting that the mouse has moved away from the card. For example, instead of using the MouseEnter and MouseLeave events of the picture box, you could handle the MouseMove event of all the cards, as well as the form. In any MouseMove handler, you would check to see if the mouse has moved outside the normal (unraised) bounds of the currently raised card, and if so, lower it.
  15. Have you tried my other suggestion (setting a breakpoint and running the program)? This should show you anywhere the size is being set programatically. Knowing virtually nothing about the project, I can't really make any kind of educated guess, but I'm trying to help you narrow it down. Does the problem go away if you remove the scrollbar? Is it even a scrollbar control, or an automatic scrollbar from an auto-scrolling control? Do you have any third-party components on the form? Are you sure the changes you are making are being saved? (Maybe the designer-generated file has been set to read-only somehow.) Try creating a new project and re-adding all the files from the old project, and see if the problem persists. Try working with the project on another computer (i.e. a different installation of VS). I don't know what you've tried, other than changing AutoScaleMode, and I don't know what your best course of action is since I'm not going on much here, but try to eliminate some variables, and if you can't figure it out, let us know what you've tried. Don't forget the details.
  16. I don't think this is the problem, but try setting the AutoScaleMode property to None. That's the only thing I can come up with off the top of my head. It's hard to say whether the problem is related to the designer, code generation, or your own code. What I might do is add an event handler for the SizeChanged event and set a breakpoint within. Run the program, and when the breakpoint is triggered, look through the call stack and see where the property is being set.
  17. What do you need to capture this information for? This sort of functionality can be used for questionable purposes (i.e. spyware). Even if your intent is good, we don't generally help with code that can be used maliciously.
  18. Unfortunately, WinForms has some very annoying issues that are hard to work around, especially when it comes to MDI. The title bars flicker or animate when you have an MDI child maximized and you activate another MDI child or open a new MDI child. Is this the problem you are having? If so, there are a couple of partial solutions on CodeProject. They fix the flicker issue when switching between child forms, but not when opening a new child form. Workaround for flicker/flashing when programmatically activating MDI child forms is the solution I used. There is also A flicker issue in MDI applications which uses a different approach but has the same effect.
  19. ambika, sorry, but you've given us virtually nothing to go on. Is this a run-time error? An error in the designer, or elsewhere in the IDE? It might help if you explain the exact steps that lead up to the error, when specifically the error occurs, and what message, if any, it gives you, as well as details.
  20. I'm very sorry. For two things actually. I couldn't approve your post yesterday because I was having trouble accessing the site (like-wise, I got your PM by e-mail but could not respond for the same reason). The other thing is that I haven't really been as helpful as I intended. I'd recommend you forget about Char.IsLetter (Char.IsDigit should work just fine, if you want to use it). The code I gave you also contained an error. I think this should pretty much do what you need. Dim BlnTestresult As Boolean = True Dim IntTeller As Integer = 0 [color="Green"]' Require 8 characters[/color] If Len(StrPostcode) = 8 Then [color="Green"] ' Require two letters[/color] For IntTeller = [color="Red"]0[/color] To [color="Red"]1[/color] If StrPostcode(IntTeller) < "A"[color="Red"]c[/color] Or StrPostcode(IntTeller) > "Z"[color="Red"]c[/color] Then BlnTestresult = False End If Next [color="Green"]' Require one space[/color] [color="Red"]If StrPostcode(2) <> " "c Then BlnTestresult = False End If[/color] [color="Green"]' Require five digits[/color] For IntTeller = [color="Red"]3[/color] To [color="Red"]7[/color] If [color="Red"]Not [/color]Char.IsDigit(StrPostcode(IntTeller)) Then BlnTestresult = False End If Next Else BlnTestresult = False End If ControlPostcode = BlnTestresult Note that the character indexes start at 0 (letters are chars #0 and #1, space is char #2, digits are chars #3-7). The reason I didn't use Char.IsLetter is because we only want Latin letters, whereas Char.IsLetter accepts letters from any script (Latin, Greek, Cyrillic, Hebrew, etc.). Note the "Not" used with Char.IsDigit. We want to set BltTestresult to false if the character is not a digit. Hope this helps.
  21. You would use it exactly the same way I used Char.IsDigit in my previous post. Just use Char.IsLetter for the characters you need to be a letter, and Char.IsDigit for the characters you need to be a digit (but read on). Well... you tell me. For IntTeller = 1 To 3 If StrTelephone[intTeller] < "0" Or StrTelephone[intTeller] > "9" Then BlnTestresult = False End If Next or For IntTeller = 1 To 3 If Char.IsDigit(StrTelephone[intTeller]) Then BlnTestresult = False End If Next Which one do you like better? They should both work, as far as I can tell, so it's really a matter of taste. Testing for letters is more complicated. If you use Char.IsLetter, the user will be allowed to enter things like "Њθ 90210". Char.IsLetter returns true for letters in any script, not just Latin letters. So it might actually be a better idea to manually check if the letters are in the range A-Z. You also have to consider whether you want to accept upper-case, lower-case, or both, and test accordingly. You might have been on the right track the first time. If I'm making this confusing, it's not intentional.
  22. First I want to give you a few tips. When dealing with characters, you should place the letter "c" after a literal value. For example, the digit zero would be written as "0"c. The reason I recommend this is (A) it makes it clear to others (and yourself later on) that you are working with characters, and (B) there are some differences in the way VB deals with string values and character values. In this case I don't see a problem, but if your code more accurately conveys what you want to do, you have a smaller chance of running into a problem. Another tip is rather than typing out "Microsoft.VisualBasic.Mid" you can just use the "Substring" method of the string objects. I think this makes things easier to read. It's also more "standard". Microsoft.VisualBasic.Mid(StrTelephone, IntTeller, 1) ' becomes StrTelephone.Substring(IntTeller, 1) But since we're dealing with single characters, there's an even better way to access the string. You can treat it like an array of characters. To get the third character in the string, you could type "StrTelephone(2)". Also, you can use the handy functions of the Char class to check the characters. For example, Char.IsDigit would come in handy here. For IntTeller = 1 To 3 If Microsoft.VisualBasic.Mid(StrTelephone, IntTeller, 1) < "0" Or Microsoft.VisualBasic.Mid _ (StrTelephone, IntTeller, 1) > "9" Then BlnTestresult = False End If Next ' becomes For IntTeller = 1 To 3 If Char.IsDigit(StrTelephone(IntTeller)) Then BlnTestresult = False End If Next Now, on to your question of how to validate the post codes. It looks like there is an error in your code. You're checking if a character is between "A" and "9", when you probably mean to check if it's between "A" and "Z". An even better way to check the character would be to use the Char.IsLetter function.
  23. See http://msdn.microsoft.com/en-us/library/ms142127.aspx. Simply pass the stream and the desired size to the constructor.
  24. I understand the sentiment, but there is a reason that this is discouraged. The idea that an exception is supposed to convey is "an error condition that you aren't expecting and probably can't handle", such as running out of memory. What you really want is to prevent the conditions that produce an exception. Make sure a file exists before you try to read from it. Sometimes you can't prevent an exception, but you know you can recover from it. For example, I wouldn't expect you to verify an image file is completely valid before creating an Image object from the file, but if the image file is invalid, it would make sense to capture the exception, and probably show the user a message such as "The image file is invalid." As long as you avoid causing exceptions, and handle the ones you can reasonably expect, any other exceptions represent a situation that you aren't prepared for and probably can't recover from. When you handle an exception, you are saying, "I can fix this," and if you blindly handle all exceptions, you're going to cause more harm than good. That's why so many recommend that your program "fail fast" when an error occurs; something is wrong, and the program doesn't know what it is. If you insist on handling the error, at least inform the user that an error occurred, and the program may be in an inconsistent state (i.e. all bets are off).
×
×
  • Create New...