Jump to content
Xtreme .Net Talk

snarfblam

Leaders
  • Posts

    2156
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by snarfblam

  1. If that weren't the case, the System.Convert class could also be used.
  2. If you don't remember which class has a specific function in it, you can search for that function name. If you want to know if there are any classes or functions that can do an MD5 hash, you could search for "MD5." If you want to ensure that your indentifier is unique, sure, you could do a search first to make sure. If you forget which file you put some code in, you can do a search for a function or class that you know to be in that code. There is no one specific reason to search for symbols.
  3. One thing that alot of people say helps is to disable "Dynamic Help." It just seems to get in the way anyways.
  4. Seems to me that "Find in Files" is the basic search, which searches multiple files and gives you a report of the findings. "Quick Find" is "quick" in that there are no intermediate dialogs or reports (yes it searches multiple files, but that is not the feature's highlight). You are taken directly to the results. "Find Symbols" finds programmatic "symbols" (not in code files, but rather in program libraries). Think of "symbol" as a synonym for "identifier."
  5. You might want to consider drawing the image to a bitmap and setting that bitmap as the picture box's image. If you are using .Net 2.0, and you are drawing to the control in the Paint event you can also draw the control to a bitmap using the DrawToBitmap method of the control, but this will also draw the borders of the picture box if there are any, and is kind of a round-a-bout way of doing things anyways.
  6. Is that all the code? Which line does the exception occur on? The "Ctr += 1" line? Or the "Next"? Or something else? Does the error occur if you comment out "cmboDefaultPharmacy.SelectedIndex = Ctr"?
  7. One thing that I like about Visual Basic is that you can import (C#'s using statement) not only namespaces but also static members of classes into scope so that the code could look the same either way. Unfortunately, for some reason, we can't do this in C#. My take on this situation is that if you were to inherit a utility class to save yourself some typing, you are abusing inheritance. That is, you are using it for something very different from what it is meant to do. Inheritance is obviously not there to bring functions into scope without qualifying them, and the reason that this may be a concern is confusion as to whether a function is static or instance and how it may play into the inheritance between DataAccess and CustomerDataAccess (PlausiblyDamp makes a good case for this). I don't think that it is a big deal either way (it only takes a second to check the function definition), but it may lead to mild confusion if you use inheritance, or any feature for that matter, for one thing when it is meant for another. On the other hand, if the DataAccess provides a number of abstract members and unifies some of the funtionality of your DataAccess classes, then DataAccess simply becomes a convinient place to put all your general data access functions (not that one should create some abstract members purely for the sake of justifying inheritance of that class). For example, perhaps it would make more sense to have an abstract SaveItem in the DataAccess class and override it in the CustomerDataAccess class, provided that doing so would have some practical benefit.
  8. You might want to take a quick look at the System.Version class. After you convert the data to a string, you can create a Version object to easily compare parts of the version number.
  9. It basically passes CPU control around all the threads to let them do what they need to do.
  10. Have you tried throwing in a call to Application.DoEvents after you update the label?
  11. Just a note, if you know which control will contain the control you are looking for (for instance, if it is always in the same TabPage) you can simply search the known container, and skip the recursion. Also, in .Net 2.0, you can actually retrieve controls from a control collection by their name... Me.Controls["btnThingamajigger"].Text = "Thing-a-ma-jigger"; The problem, again, with that is that it only works on "top-level" controls unless you whip up a recursive function.
  12. My bad. I guess I should pay attention when I read a post. I thought you said that you were forcing garbage collections. But have you tried calling Application.DoEvents to let other threads finish what they are doing before accessing the clipboard? I don't see why it should be necessary, but who knows?
  13. The biggest problem is that certain .Net controls, generally the more complicated ones, like the TextBox, are simple wrappers for the Win32 common controls and are only extensible (beyond relatively simple enhancements) with Win32 style subclassing: intercepting messages, modifying flags, and stuff like that. Fun stuff, especially when you aren't familiar with that sort of thing. .Net 2.0 adds extensibility to some controls (ListView, TreeView), but that doesn't get you anywhere on textboxes. BUT... luckily for you, I went to tremendous lengths to find this. I haven't really looked at it too closely, and I don't know how good it is, but it is a start.
  14. This same question was asked here not too long ago. All I can tell you is that no one could come up with an answer and that I for one can't decipher that raw binary data from the stack trace (which is a private field anyways).
  15. Yes, swapping the class name in a using statement could essentially transform your CustomerList from one class to another. It is kind of like an intentionally handicapped macro so you don't shoot yourself in the foot (maybe the term typedef is more accurate, I don't know what the word means in terms of C++). It simply defines an alias for another class. Combined with generics it becomes particularly handy.
  16. The operating system overrides the BIOS's key repeat rate settings, and I, for one, would not depend on the keyboard repeat rate. Yes, most users probably will remain at the default, but that one out of twenty (could be more, could be less, not the point) people who went on an expedition exploring vast depths of the control panel could have altered the repeat rate, and will be very frustrated when the game doesn't work right not matter how he changes the settings. And if you're of the opinion that it serves him right, well, I'm offended because I'm one of the people who likes to explore things like the Control Panel. Also consider, for example, the poor little kid who is playing on Grandma's computer, which has the repeat rate set at something lower than what she considers insane. And the fact that some utility programs might change settings like this without asking the user (it's happened to me). The biggest problem of all, I would think, is that there is a pause between the initial key press and the automatic repeat. A very simple solution I have used in the past with programs that run on timers is to simply keep track of which keys are pressed by setting boolean variables in the KeyDown and KeyUp events, for example: Dim UpKey As Boolean Private Sub Form_KeyDown(sender As Object, e As EventArgs) Handles MyBase.KeyDown If e.KeyCode = Keys.Up Then UpKey = True End Sub Private Sub Form_KeyUp(sender As Object, e As EventArgs) Handles MyBase.KeyDown If e.KeyCode = Keys.Up Then UpKey = False End Sub The only problem with that is that it may be vulnerable to keyboard confusion when the player mashes the keyboard (a keyboard can only transmit three or so keys, depending on which keys, to the PC at a time and things get erratic when lots of keys are pressed). I'm not sure if this is the case, and it could be tested, but I'm lazy. I'd say that PlausiblyDamp's solution would probably be the best though.
  17. This begs the question: why are you calling the garbage collector. As long as you know that this is supposed to be automated and understand the implications of explicitly invoking a garbage collection (under most circumstances it will actually cause the garbage collector to perform less efficiently), or in other words, if you really know what you are doing, then do what you will, but I'd recommend you avoid calling the garbage collector explicitly. If you must call the garbage collector, I don't know the finer details but it could be that something relating to the ClipBoard class is pinned or being moved or something. I don't know if code is allowed to be executed during a collection. If that is the case, you might want to try to do an Application.DoEvents after the call to GC.Collect to allow the GC thread to finish up. Otherwise, I don't know what to tell you.
  18. That's the poopy thing about compiled programming languages. The variable names you used when writing the program disappear at runtime so you can't access variables with their programatic name on the fly. You could skip the looping and cheat a little if you felt like learning about reflection, but that is hardly worth the trouble just to change the color of a label. In the mean time, if you want something quick and easy, you could always make a function that will do the looping for you... 'Overload to save us some typing Public Function GetControl(Name As String) As Control Return GetControl(Me, Name) End Function 'Mmmmmmmmm... recursive Public Function GetControl(Container As Control, Name As String) As Control For Each C As Control In Container.Controls ' If this is the control, return it If C.Name = Name Then Return C ' If not, search child controls and return the control if we find it Dim Result As Control = GetControl(C, Name) If Not Result Is Nothing Then Return Result 'We could also try out the IsNot operator, but that isn't kosher with VB7 Next Return Nothing 'if we find nothing End Function 'Use it like this: GetControl("lblSeat42").BackColor = Colors.SmurfBlue Another nifty thing new to .Net 2.0 is the fact that alot of things are organized by indecies and keys. You can write code like this without writing any of your own helper functions: Me.Controls("lblSeat22").BackColor = Colors.HotPink The only problem is that this won't work for nested controls (such as a control within a group box), and it is only available on VB 8/C# 2.
  19. If a textbox is set to accept tabs as text input then it will not allow you to tab to the next control because the tab is processed as a character being typed into the box. You will probably also see this with RichTextBoxes and maybe other text-based controls.
  20. Questions regarding on-the-fly control creation are not uncommon. Even when people figure out how to create controls, there is often difficulty and confusion with event handling and referencing controls. This tutorial explores the basics of dynamic control creation and addresses some common issues. Example code is provided in both C# and VB for .NET versions 1.0-2.0, and a Visual Studio 8 demo project is included for both languages. Tutorial C# Demo VB Demo Suggestions and comments welcome.
  21. The sender argument passes the object that raises an event as type Object. You can cast to a control and check it's name property, or compare it against a known variable... If Sender Is PictureBox1 Then PictureBox1.Image = LoadSomeBitmap() End If You could store an index or key in the Tag property... Dim Index As Integer = Integer.Parse(DirectCast(Sender, Control).Tag.ToString()) There are lots of ways.
  22. That is exactly what the problem is. Because you are getting it from the Controls collection, all that the compiler knows is that it is a control, i.e. it has a text property, a position, a parent, etc. but not that it has an Rtf property, a Find method, etc. because for all the compiler knows, Controls[1] could be a button or a group box. So, yes, you need to cast.
  23. If you wanted to hack something out real quick, you could probably reference the RichTextBox by the tab's control collection and an index... tabControl1.TabPages[index].Controls[2].Text //if you know that the RTF box is control #2 If you want to take a neater, cleaner approach, you need to store the newly created objects in some sort of array or collection. You may need to wire/unwire events on the fly. I don't know J#, so you will probably have to research the syntax in MSDN, but here is the c# equvalent. List<RichTextBox> RTFs = new List<RichTextBox>(); //ArrayList could also be used // Should be initialized with any RTFs that were placed at design time // i.e. in contructor RTFs.Add(rtfDocument); where rtfDocument is // the name of the RichTextBox added at design time. // An example of duplicating a tab with an RTF void DuplicateRtf(){ // Create the new rich text box with copied text RichTextBox CurrentBox = RTFs[tabControl1.SelectedIndex]; RichTextBox NewBox = new RichTextBox(); NewBox.Rtf = CurrentBox.Rtf; // If you need to wire events: NewBox.LinkClicked += this.OnRtfLinkClicked(); // Create the new tab page and add the new Rtf box. // This can be accessed later via index in the TabControl.TabPages collection. TabPage NewPage = new TabPage; tabControl1.TabPages.Add(NewPage); NewPage.Controls.Add(NewBox); } // An example of how to access a specific text box, // in this case, the currently visible one. void DisplayRtfFromCurrentlyVisibleBoxJustAsAnExample(){ string RTF = Rtfs[tabControl1.SelectedIndex].Rtf; MessageBox.Show(RTF); } I haven't tested this either, but it should demonstrate the basic process.
  24. For situations like this in the past, I've written code like the following: Boolean ValidatingTextBox1 = False; Sub TextBox1_TextChanged(Sender As Object, e As EventArgs){ 'If we change the text in this sub the event code won't be 're-executed... If Not ValidatingTextBox1 Then 'because we set this to true while validating ValidatingTextBox1 = True; 'Perform Validation ValidatingTextBox1 = False; End If End Sub
×
×
  • Create New...