Jump to content
Xtreme .Net Talk

snarfblam

Leaders
  • Posts

    2156
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by snarfblam

  1. Is there some reason why you can't simply create a handler in your Form with the ProgressBar and attatch that handler to the OnProgress event? The only concern that comes to mind is that you need to ensure that the GUI is not updated from a separate thread, meaning (I think) that you need to use Control.Invoke or Control.BeginInvoke/Control.EndInvoke to ensure that the code is executed on the appropriate thread. class MyForm: Form { public MyForm() { InitializeComponents(); // Put this wherever appropriate DTS execute = new DTS(); // If OnProgress is an event of another object substitute it here. // C# 2.0 + DTS.OnProgress += MyHandler; // C# 1.0 + DTS.OnProgress += new WhateverDelegate(MyHandler); } void MyHandler(string EventSource, string ProgressDescription, int PercentComplete, int ProgressCountLow, int ProgressCountHigh) { //Do whatever } }
  2. Then you might want to consider simply adding a panel and setting its visible property to true/false to show/hide it.
  3. Quite possible. 'Constants to specify animation type and direction Enum AnimationConstants As Integer AW_HOR_POSITIVE = 1 AW_HOR_NEGATIVE = 2 AW_VER_POSITIVE = 4 AW_VER_NEGATIVE = 8 AW_CENTER = 16 AW_HIDE = 65536 AW_ACTIVATE = 131072 AW_SLIDE = 262144 AW_BLEND = 524288 End Enum 'Import from Windows API <System.Runtime.InteropServices.DllImport("user32.dll")> _ Shared Function AnimateWindow( _ ByVal hWnd As IntPtr, _ ByVal millseconds As Integer, _ ByVal lFlags As AnimationConstants) As Boolean End Function Sub Example() AnimateWindow(Me.Handle, 300, AnimationConstants.AW_VER_NEGATIVE) End Sub enum AnimationConstants{ AW_HOR_POSITIVE = 1, AW_HOR_NEGATIVE = 2, AW_VER_POSITIVE = 4 , AW_VER_NEGATIVE = 8, AW_CENTER = 16, AW_HIDE = 65536, AW_ACTIVATE = 131072, AW_SLIDE = 262144, AW_BLEND = 524288 } [system.Runtime.InteropServices.DllImport("user32.dll")] bool AnimateWindow(IntPtr hWnd, int millseconds, AnimationConstants Flags ); void Example(){ AnimateWindow(this.Handle, 300, AnimationConstants.AW_VER_NEGATIVE); }
  4. You are correct. CreateSubKey opens the key for write access if it already exists. And if you are only using managed code and you aren't multithreading then I don't see how this could be caused by you. Is this reproducable or has it only happened once?
  5. I'm such a nice guy.Intersection.vb.txt
  6. I was bored so I looked up the equation and coded it, then made a demo app for it. All you really need is the Line struct, which has an intersection function. I wrote this in C#, so I hope you are using C#. If you are using VB and don't know C#, I can translate the Line class for you.Intersection.txt
  7. You could do something like... Microsoft.Win32.RegistryKey MyKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Settings\\MyProg\\Grid\\Columns"); if(MyKey == null) { // Key does not exist. } else { // Key exists. MyKey.GetValue("Bork"); // Gets the "Bork" value on HKCU\Software\Settings\MyProg\Grid\Columns }
  8. Tabs are just a formatting tool. You can't treat them like cells in a table (if that is what you are trying to do). When the RTF box encounters a tab character, it advances the location of text output to the next tab. You are setting tab locations correctly, but to use them, you need to insert tab characters (i.e. in the string "Before Tab\tAfter Tab: the "\t" is interpreted as a tab character). If you want to move the cursor to the first tab in the first line of a RTF box, you could do this: char Tab = '\t'; int TabOffset = myRichTextBoxEx.Text.IndexOf(Tab); myRichTextBoxEx.SelectionStart = TabOffset;
  9. The problem is the parentheses. Where VB syntax can treat a property like a method or a field, C# syntax only allows them to be used like a field. In other words, no parenthases (indexed properties use square brackets []). private void mcMultiColumnComboBox1_SelectedIndexChanged(object sender, EventArgs e) { System.Data.DataRowView myDataRowView = mcMultiColumnComboBox1.SelectedItem; this.cultivarTextBox.Text = myDataRowView[2].ToString(); }
  10. The property you are looking for is RichTextBox.SelectionTabs. To apply it to the entire RichTextBox, select all the text in it first. I found an article on RichTextBox Tab Stops, but it is written in VB6.
  11. I don't know where... I would say that that is up to you, but I would recommend hashing passwords so that they can never possibly (speaking realistically) be retrieved. Look into MD5 and SHA1 classes in System.Security.Cryptography.
  12. This is correct behavior. It is just abbreviated syntax to make code look cleaner. Rather than having "attribute" inside every attribute tag, your code can read and look more concise. Suffixing attribute classes with "Attribute" is a special naming convention honored by C# and VB.
  13. 585x630x32... you don't mean 32 bpp, do you, cause last I knew gifs couldn't do that. My best guess is that what ever software created that gif saved it in a not entirely standard format that firefox and IE happen to tolerate. I can't open the image with Windows Picture and Fax Viewer, VS, or Photoshop (it displays as a blank black or white square).
  14. According to MSDN, TryParse is only available for the Double data type in versions 1.0 and 1.1 of the .Net framework. It is available for Int16/32/64, UInt8/16/32/64, byte, single (float), double, DateTime, etc. in version 2.0.
  15. There are only two differences that I can see between the two functions (C# and VB): that pointed out by Jaco (not returning res), and the overflow check issue pointed out by Nerseus. Otherwise, they seem perfectly identical. I believe that by default C# does not perform overflow checks, whereas VB does by default, causing overflow errors in VB where one expects a value to be truncated in C#. Since VB is all or none in overflow checking, you can disable it in the project settings, which will probably resolve the overflow exception. Returning res will probably help alot once the overflow exception issue is resolved.
  16. I pointed this out in your other post as an edit, but I'll put it here too. Code like this is a bad thing... public bool IsDate(object inValue) { bool bValid; try { DateTime myDT = DateTime.Parse(inValue); bValid = true; } catch (FormatException e) { bValid = false; } return bValid; } The reason is that it uses exception handling as a means of validation, which is not what exceptions are meant for. If exceptions can be avoided in a perfectly logical manner they should be. This means that we should not assume dates are formatted correctly, which the DateTime.Parse function does (unless we have a good reason to make such an assumption), but rather use a function that does not make such an assumption: DateTime.TryParse. This way, we can save the use of exceptions for what they are meant for: catastophic, exceptional, unexpected situations. If your code expects an exception, you did something wrong.
  17. (A) Class Example 'Declare Event Event SampleEvent As EventHandler Sub PassHandler() 'Create Delegate Dim NewHandler As EventHandler = AddressOf Handler 'Pass Delegate AttatchHandler(NewHandler) End Sub Sub AttatchHandler(Handler As EventHandler) 'Attatch Delegate AddHandler SampleEvent, Handler End Sub 'Use Delegate Sub Handler(Sender As Object, E As EventArgs) MessageBox.Show("Handled") End Sub End Class (B) Class Example Sub PassType 'GetType returns the runtime type of an object. Dim T As System.Type = Me.GetType() 'The System.Type can be passed as a parameter. MessageBox.Show(IsMyType(T).ToString) End Sub Function IsMyType(System.Type T) As Boolean Dim MyType As System.Type = Me.GetType() If (MyType Is T) Or (T.IsSubclassOf(MyType)) Then 'The above expression is the same as 'If TypeOf(AnotherObject) Is TypeOf(Me). 'We check if the two types are exactly the same (MyType Is T) 'or if T is derived from MyType. Return True End If Return False End Function End Class I did not test the code, so I am not sure it is 100% correct, but you can certainly get the jist of it.
  18. Mmmmm.... code.... /* TryParse tries to parse a string. If it succeeds, it stores * the date in the OUT variable and returns true. If it fails, it * returns false. */ if(DateTime.TryParse(MyDateString, out MyDate)) { // > and < operators are overloaded. if(MyDate > DateTime.Now) { // It's the future! } } P.S. Not to rag on you, Cags, but I would personally discourage using code like the code you posted: public bool IsDate(object inValue) { bool bValid; try { DateTime myDT = DateTime.Parse(inValue); bValid = true; } catch (FormatException e) { bValid = false; } return bValid; } It essentially depends on exception handling for validation, and exception handling is specifically not intended to be used for program flow control, but rather for "exceptional circumstances" (and that's not exceptional in a good way, either).
  19. Take a look at these two events: 'Unhandled exception in AppDomain (I don't think this will catch an exception before it crashes the GUI) AppDomain.CurrentDomain.UnhandledException 'Unhandled exception in GUI thread Application.ThreadException There is usually nowhere between Application.Run and the button click event handler to attatch an exception handler. There will be nothing on the stack between the two besides non-user code, making it hard to catch an exception and keep your app from crashing.
  20. Not win32 resources, just .Net resources, which, again, won't show up in a resource editor, or windows icon picker, etc.
  21. There are many different ways to define lines. One way is with a pair of points, i.e. a line defined by (0, 5) and (3, 10). Another way is with the general equation of a line: Ax + By = c, such as 5x - 3y = -15 (the same as y=5/3x + 5). A third is slope-intercept form (the one you saw in algebra): y = mx + b, such as y=5/3x + 5 (the same as 5x - 3y = -15). And there are more. Depending on your representation of a line, the exact method differs. Iceplug's solution works for slope-intercept form, but the problem with slope-intercept form is that it can not compensate for vertical lines, which essentially have a slope of infinity. My best guess is that you are defining your lines by pairs of points. Also, I would say most likely you have line-segments, which means that you also have to check to make sure the point of intersection is within both segments. I guess what I'm trying to say is you can get a much better solution with more info.
  22. I was pretty confused until I realized that you guys were all talking about quotes (the thread's title is removing parentheses).
  23. Multithreading. See similar question.
  24. This is exactly what threading is for. You need to launch this function in a separate thread. This means that the main thread is still free to update the ui and interact with the user (in other words, the program isn't frozen). Since I hardly even qualify as a multithreading novice, that's about all I can tell you, but I'm pretty sure you can find all the help you need on threading in MSDN.
×
×
  • Create New...