Nerseus
*Experts*-
Posts
2607 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by Nerseus
-
Why not use try/catch in your validating event and simply set e.Cancel to true? There's almost never a reason to NOT handle an exception and take a more appropriate action, especially in code where you're likely to get an exception (such as calling a webservice or taking user input). -Nerseus
-
The Bitmap class is derived from Image, which is one of the constructors. You can even use a Bitmap without casting, as in: Bitmap b = new Bitmap(@"c:\mybitmap.bmp"); Bitmap b2 = new [b]Bitmap(b, 100, 100);[/b] b2.Save(@"c:\mynewsmallerbitmap.bmp", System.Drawing.Imaging.ImageFormat.Bmp); Note the last param to Save. This is where you define the type of picture. Even though you may save the file as "image.BMP", if you don't specify the ImageFormat, you'll get a PNG formatted image. -Nerseus
-
Use bmpNewImage.Format. As for finding help, sometimes it's useful to type your object and the "." then just scroll through the list of members to see what's available. Also, try the object class followed by a period to see the static methods. So, try: bmpNewImage. (see instance members) Bitmap. (see static members) -Nerseus
-
I'm not sure about Access, but with SQL Server, if you use the exact same connection string you get a shared connection on SQL Server. This might cause a problem. Also, there's no reason to make two separate calls. You can easily perform an INSERT followed by a SELECT and save a little traffic to/from the database. -Nerseus
-
What code is using the unc path (loading a file, an image, a database, etc.)? Have you tried having the person that is haiving problems type that path in the "Start->Run" box? It should come up with explorer. If it prompts you for a username/password, then they're not authenticated. -Nerseus
-
Search for color and ListViewSubItem (I think) - this has been discussed a couple of times before. I can't recall offhand if you can or cannot change the color of subitems - the search should help. -Ners
-
There's a good chance it's your string, "My_VB.net_Notes.imgButton.bmp" but I'm not sure what it should be without seeing your project. As for the efficiency of storing the bitmaps in the XML file (the resource file specific to a form) or as an embedded resource (through Add Existing Item), they are exactly the same. The one in the form only looks odd because XML must be a string so some encoding is necessary to get it in that format. divil is right in assuming that the file type is preserved as well (a gif is a gif, a jpg is a jpg) - no conversion is occurring, just encoding. There might be a difference in how the two images are loaded, since one loads from the form's resource and, I assume, is loaded in memory with the form since the constructor calls InitializeComponent which loads the embedded image. The other embedded resource (in your assembly) won't get loaded until you explicitly load it. Although there are two methods to loading resources (the one the form uses and the code divil gave), I would imagine they're both wrappers and eventually call the same code to load a chunk of data from a resource and then cast it to the appropriate type (a Bitmap or Image object). Just more (mostly useless) information :) -Nerseus
-
First, I'm not sure what's happening. If you set a breakpoint on the "Throw New Excpeption()" line, you can check the call stack (Debug->Windows->Call Stack" to see what's going on. There are a bunch of different calls made so it's hard to see what's different. But, the more important point might be to ask why you throw an exception during validation? Normally, that's a bad idea. The point of validation *should* be to check whether the data in the control is valid and set the CancelEventArgs.Cancel to true if it's not. If you really need a message to be displayed, I'd use a MessageBox or something else, but not an exception. -Nerseus
-
Take a look in the help for the DataGridBoolColumn object. If you do some research and can't figure out how to get it working, let us know. Don't forget to show us what you tried so we can give you pointers on what to fix or how to use it properly. -Nerseus
-
A DataList? Isn't that a web control? If the point is to allow them to modify fields, one record at a time, you could also use bound controls (textboxes, comboboxes, etc.) using a CurrencyManager to MoveNext, MovePrev, etc. Just another idea. For the record, when you get into real world applications where tables have thousands or millions of rows, you almost never show a grid/table with all of the rows at once. Generally, a table with so many records can be filtered somehow. For instance, you would never show a table full of customer addresses where the user is free to edit all of them at once. You'd most likely be showing a customer's data and a grid of their addresses, so you'll only be showing 1-5 addresses, give or take. The only time I've shown a grid of an entire table is for the maintenance pieces of the application, usually for lookup tables or simple 1-row tables. Maybe you need to spend some time thinking about the overall design, such as how the user gets to what they want quickly, and worry about the specific controls once you have a better feel for what's needed. -ner
-
To get around the null reference exception, you want to create an instance of FileInfo before you use it. You could, for example, do this: private void buttonSetFile_Click(object sender, System.EventArgs e) { switch (openFileDialog1.ShowDialog()) { case DialogResult.OK: // this line throws null exception [b]dbInfo = new FileInfo();[/b] dbInfo.PathName = openFileDialog1.FileName; labelDatabaseName.Text = dbInfo.FileName; buttonTable.Enabled = true; break; case DialogResult.Cancel: break; } } This only creates the object when you need it - after they've chosen a file through the dialog. The other option has been discussed *many* times on this forum. The main problem is that in .NET, you no longer have a built-in reference to a form as you did in VB6. In VB6 it was standard practice to put public properties on a form and access those properties anywhere else in code, including other forms. In .NET, it's cleaner to pass in data through the constructor. Let's say your popup form is called formPopup (the class name that is). Here's how you might create it: public class formPopup : Form { private string filename = string.empty; public formPopup(string filename) { this.filename = filename; } } This defines the formPopup class to have only one constructor which takes a string. It then saves the filename in a private variable in case you need it later. Now in your formMain, you need to pass the filename to the popup form. Here's how you might do this: private void buttonSetFile_Click(object sender, System.EventArgs e) { switch (openFileDialog1.ShowDialog()) { case DialogResult.OK: // this line throws null exception labelDatabaseName.Text = openFileDialog1.FileName; buttonTable.Enabled = true; formPopup frm = new formPopup(openFileDialog1.FileName); frm.ShowDialog(); break; case DialogResult.Cancel: break; } } Obviously I don't know what you really need, but that shows how you could create a new formPopup and pass in the filename that was selected. With this scenario, you don't want your FileInfo dbInfo variable at all. If formMain really needs the filename outside of the button click event, I'd store it in a string. -Nerseus
-
Another idea would be to pass the path information to the new form through the new form's constructor. You can certainly make the variable static, though it's not as "clean" since the popup form now has to know about the other form to get to the exposed static field/property. The reason null didn't work for you is probably because you didn't set it to "new ...()" in your buttonSetFile_Click event. You can declare the variable with new, as it sounds like you did, but then you'll always have this instance even if you've never set the properties. Again, it might be "cleaner" to set it to new only when you need it, if you really do need it. I'd stick with using the constructor idea mentioned above though. Better to learn how to use it now as you'll need to learn it sooner or later (plus it's the better way to code). -Nerseus
-
Why ALT key does not function well in program written using VS .NET?
Nerseus replied to xiaoDD's topic in Windows Forms
You'll notice a number of MS programs follow the same non-standard menus. For instance, Visual Studio itself always shows the underlines (on my machine anyway), as does Outlook, Outlook Express, and Word. Most other programs, including IE, do not show the underlines until Alt is held (assuming you have this option turned on, which is the OS's default). I hear this questions ALL the time from my QA team. They never believe since so many of MS products ALWAYS show the underline... -Nerseus -
The DataGrid is always in a bound mode in one fashion or another. It may not be a DataSet or a DataSet connected (bad term there, too) to a database, but it's bound to something. But, binding the DataGrid to a DataSet is perfect for what you want... with one exception. You mention you want an Excel-like interface. To me, that means almost unlimited columns and rows. Assuming you'll bind to a DataSet, that means being able to dynamically add rows and columns to your DataTable as the user moves around, OR starting with a DataTable with 1000 rows and 1000 columns (or some similar large number). Unfortunately, the DataSet is not a sparse type of storage. Meaning, if you say you want 1000 rows and 1000 columns, you'll get 1000x1000 = 1,000,000 objects in memory. Not too good if the user only edits 3 cells. There are a number of controls that you can buy that DO work like Excel. I haven't used them in .NET so I can't say how they work. Also, since this sounds like a test project, you probably don't have $300+ to spend on a 3rd party control. I don't know of any unbound controls that work like Excel other than 3rd party controls. Knowing all that, I'd suggest abandoning the Excel interface for now and just use a DataSet/DataGrid. Make sure you check out this FAQ for help with the built-in DataGrid. -Ner
-
I didn't see a question in your original post - what seems to be the problem/issue/question? Maybe you forgot the word Sub in your constructor, as in: Public [b]Sub[/b] New(ByVal lngEquipmentID As Long) 'instead of Public New(ByVal lngEquipmentID As Long) -Nerseus
-
Check your project properties. See what the Startup Object is set to. If you're creating a Windows Application you'll need a Sub Main or a startup form. If you create a new project you can see what Sub Main should look like. You can then cut and paste that function to your real project and change the form that's referenced there. If you still can't get this to work, upload a zip of your project and we'll get you going. -ner
-
Can you set the button's Image property (and ImageAlign)? Seems easier, unless you need something fancy like more exact placement or something else. Here's a oneliner to load and resize an image for a button: Button1.Image = New Bitmap(New Bitmap("C:\anyjpg.jpg"), 32, 40) I'm not sure where you put your code, but if it were in Form_Load or similar, it won't work. You'd have to override the button's paint event or maybe use the Form's paint event. I'm not real familiar with trying either since I've always been able to use the Image property of the button. -Nerseus
-
Animation uses up memory like crazy!
Nerseus replied to aewarnick's topic in Graphics and Multimedia
You can do whatever you want, based on your needs. By calling Invalidate, you're forcing a refresh of the whole form - hence a flicker occurs. When you call paint yourself, you're not really painting the form, just adding a little extra painting (looks like you're drawing an image). Honestly, if that's all you plan on doing, why not use an Image control or a Picturebox? If you're painting a picture on a button, there are better ways - but I'd ask that question instead of painting. My answers thus far have related more to moving pictures, such as an image that represents a "sprite" - a non-rectangular 2D region that may or may not be animated - used in games. Maybe you could tell us more about what you want, then we can offer clearer suggestions maybe even real code snippets. -Ners -
Animation uses up memory like crazy!
Nerseus replied to aewarnick's topic in Graphics and Multimedia
Ideally, you only want to paint what's changed. If you're doing something with "sprites" in windowed mode (everything except DirectDraw will be in a window) and you want the best speed, you may need or want to keep track of the position of each drawn sprite so that you can only redraw a small portion of the screen each time. There are lots of techniques, but the simplist (somewhat) is to redraw the background of where your sprite used to be, then draw it in the new location. To make it more efficient, you can event use IntersectRect to see if the old and new positions overlap (they often do) and then you might be able to save more time by not erasing the previous image if the new image is going to overwrite it anyway. This may be overkill for what you want/need. The best bet is to find the slowest machine that you'll want someone to play your game on and make sure it works well enough on that machine. Having said that, I wouldn't worry about optimizing anything right now other than obvious flaws that are noticable now - which might indicate bad design or more general optimizations that are specific to game programming (such as the aforementioned "erase last position" logic). -Nerseus -
I think you have to use the Rtf property, not the Text property. -Nerseus
-
Why are you guys using Opera? Are you using something other than a Windows-based OS? I remember trying Opera a few years ago for testing some web-based apps, but I found horrible compared to IE and (gasp) even Netscape. Maybe it's changed, but I couldn't imagine why anyone would use it on Windows... I'm just asking for my own curiosity. -Nerseus
-
I use the Object browser's Search button. Press Ctrl-Alt-J for the object browser (or reassign to F2 like it was in VB6 :)), then press the little binocular button. I've found that between that and scouring the built-in MSDN help, I find a ton of useful stuff. Plus, working in a team that's been using .NET for almost a year (in production, more if you count playing around), we share a lot of useful tidbits. -Nerseus
-
Animation uses up memory like crazy!
Nerseus replied to aewarnick's topic in Graphics and Multimedia
I wouldn't call the Paint method yourself either, bad practice. There's almost surely a better way. If nothing else, move out your code from the Paint event into a function and call that function from both the Paint event and your timer. Having said that, do not pass a reference to "this.CreateGraphics()" ANYWHERE. Any graphics object you create MUST be disposed of or it will NOT go away. Do this instead: Graphics g = this.CreateGraphics(); // Use g - in a call to PreachForm_Paint or whatever g.Dispose(); -Nerseus -
If you're saying that one textbox is only used for searching and the other 3 are only to display fields from the grid, then you should only have to add the DataBindings to the three textboxes one time, preferrably when the form loads (after you've created your DataSet/DataTable). If you really need to rebind the textboxes after each search, then you'll have to call Textbox.DataBindings.Clear() before adding the binding back in as you can't bind the same property more than once. You should ONLY have to do this if: A. Your textboxes will switch between bound and unbound mode - maybe if they're in "enter params and search" mode and then they're in bound mode after the search. B. Your DataSet variable changes to be a new DataSet. In that case, your textboxes will be bound to the "old" DataSet while the DataSet variable points to a new DataSet. I can't think of why you'd want to re-set your DataSet variable to a new instance of a DataSet, but who knows. -Nerseus
-
If it's not there, that's 0 matches. For example. Say you might have this: ...Dan.Jones or .Dan.Jones or Dan.Jones To get the first name, you could use: "^[\S\W]*[\w]+[\S\W]+..." So, find 0 or more non-whitespace non-alpha non-digit chars, followed by a word character. You want 0 or more because you don't know if the string starts with a non word or a word character (and it might be more than one non-word character). -ner