Jump to content
Xtreme .Net Talk

snarfblam

Leaders
  • Posts

    2156
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by snarfblam

  1. I think IComparable is more meant for sorting or finding when an object is greated or less than another (Although if IComparable.CompareTo() returns a zero, it does signify equality, it is generally used for sorting of collections). Since you only want to test for equality, I recommend overriding the .Equals() method. Since you are using VB, you can't overload the = operator.
  2. I've downloaded an add-in before that did the exact same thing for VB. You typed three apostrophes and it would give you the <summary>, <paramater>, etc. tabs and all that good stuff. I don't have it anymore though, and can't remember what it is called.
  3. In short, the answer to your question is no. Some possible solutions are (1) use managed DirectX to speed up your drawing (as pointed out by wile), or (2) if possible you could use multiple threads. Also, if the mathsy stuff is ever re-calculating any of the same stuff see if you can't store it and re-use the data instead of re-calculating.
  4. I was actually gonna point that thread out, but I didn't. Anyways... If you use the code I posted above for Form2, in form1's code you would just do this: Me.TextBox1 = Form2.ShowDialog() That's it. Whenever you want to use Form2 to get a string, call Form2.ShowDialog() and use the return value.
  5. well... couldn't you just declare a byte array, download blocks at a time and write them? Dim Data() As Byte = New Byte(InsertSizeHere) Do Length = WebStream.Read(Data, 0, Data.Length) FileStream.Write(Data, 0, Length) Loop While WebStream.Length < WebStream.Position - 1 Didn't test this, but you can get the jist of it. And if performance becomes an issue you could look into using asynchronious methods (i.e. use BeginRead(), EndRead(), BeginWrite(), etc.) [Edit]I guess someone beat me to giving you the same answer, and I know you were asking about C# (not that it would be hard to translate). Oh well.[/Edit]
  6. Can't you use a stream reader (IO.StreamReader) to read the whole file at once and then a stream writer (IO.StreamWriter) to write the whole file at once?
  7. If you want to use form2 as a dialog box, this is how i do it: 'This code goes in Form2 ' Dim _Result As String Public Readonly Property Result Get Return _Result End Get End Property ' Shared Function ShowDialog() As String Dim frlDialog As New Form2 Form2.ShowDialog() 'Instantiate and show form2 Dim Result As String = Form2.Result 'Get the result Form2.Close 'Close the form Return Result 'And return the result End Function ' Sub btnOK_Click(Sender As Object, e As EventArgs) Handles btnOK.Click _Result = Textbox1.text 'Result property will return text entered Me.Hide 'Hide this form to return control to Shared ShowDialog() End Sub If you are going to do this alot you don't want to repeatedly create Form2s though, this will be a lot of work for the garbage collector. In that case I would instantiate Form2 once and re-use it repeatedly.
  8. I don't know if this will help, I don't know that much about threading but have you tried: private Sub RunExpensiveFunction objActiveThread = New Threading.Thread(AddressOf ShowProgress) objActiveThread.Name = "Progress" objActiveThread.Priority = Threading.ThreadPriority.BelowNormal ' Otherwise the progress bar eats up too much CPU time. objActiveThread.Start() ExpensiveFunctionIsRunHere() 'Clean up the progress window blnShowProgress = False objActiveThread.Join() '<--Wait for the other thread to finish end sub
  9. Are you trying to make the program end when the user clicks cancel? Or is it happening and you dont know why?
  10. I am making a component that inherits from MenuItem, and another that inherits from MainMenu to contain my menu items. Much of the behavior of my menu items depends on properties of the MainMenu. My menu items can display images from an imagelist specified as a property of my main menu. I have implemented the ImageIndex and ImageList properties exactly as I have seen in many examples, like so: 'Specify Design time category, editor, and type converter <Category("Appearance"), _ Description("Image from specified image list to be displayed for this menu item, if nothing is specified for the property ""Image"""), _ Editor("System.Windows.Forms.Design.ImageIndexEditor", _ GetType(System.Drawing.Design.UITypeEditor)), TypeConverter(GetType(ImageIndexConverter))> _ Public Property ImageIndex() As Integer Get Return _ImageIndex End Get Set(ByVal Value As Integer) _ImageIndex = Value End Set End Property ' 'Necessary for design time ImageIndex editor <EditorBrowsable(EditorBrowsableState.Advanced), _ Browsable(False)> _ ReadOnly Property ImageList() As ImageList Get If _MainMenu Is Nothing Then FindParents() 'Find the containing MainMenu if necessary End If If _MainMenu.ImageList Is Nothing Then MsgBox("This is the problem") Return _MainMenu.ImageList End Get End Property My problem is a designer problem. The thumbnails don't show up during design time when I am selecting the image index in the property grid. The available indecies and "(none)" appear in the dropdown list, just not the thumbnails.
  11. The reason that it seems you can't change the text is that the SelectedIndexChanged event is raised BEFORE the combo box actually changes the .Text property to match the selected item. That is, the user selects and item from the drop down list, the SelectedIndexChanged event is raised, you handle the event and set the text, and then, after you handle the event, the combobox sets its text to what the user selected, overwriting the text you set. This is the behavior I observed by throwing MessageBoxes on about every line of code to get a play-by-play. You will have to find a workaround.
  12. ReadOnly would be preferable if you want the user to be able to copy the text (or if you dont care). However, if, for some reason, you don't want the user the be able to copy text, I don't believe that the .Net framework provides a method for changing the text color, but since it will let you change the backcolor, why don't you set the backcolor to the default disabled backcolor (SystemColors.Control) when it is disabled, so that the user has a visual cue that it is disabled and the text is readable. [Edit]Also, I don't know why you are changing the color of the textbox, but there is disagreement between programmers as to whether or not it is okay to override a user's color preferences. If your situation really warrants it, go ahead and change the back color. If it isn't really necessary, though, you might want to think twice before changing the colors around.[/Edit]
  13. What do you have the .DropDownStyle property set to? If it is set to DropDownList then you can not set the .Text property; it will ignore you. That's because a DropDownList is meant to select (and display) only items from a preset list, which I'm guessing does not include "Select a Colour", or even "Select a Color". You could include "Select a Colour" as the first item in the Items collection, and instead of [ComboBox2.Text = "Select a Colour"] you could do [ComboBox.SelectedIndex = 0]. The drawback to this, however, is that when the user drops down the list, "Select a Colour" will be the first item listed. Otherwise, it will work exactly as you'de like. Now... if the .DropDownStyle property is not set to DropDownList, then I don't know what the problem is, but I'm sorry for wasting your time.
  14. Maybe a moderator will add it to the code library or tutors corner
  15. Unless you are programming with something very graphics intensive or APIs that get much closer to the hardware layer, like DirectX, you should never need to test with graphics cards. Like Penfold69 said, check their font size. For that matter any other Windows settings you can think of that could cause control display irregularities. Open up the control panel and Tweak UI and see what you can find. If the app just looks unpleasant because the listview's contents dont fit inside it well, it might be something you just have to live with. You could check the user's resolution and font size (if this turns out to be the problem) and possibly give the user a recommendation to change them to improve your program's display.
  16. Even with 30 references it shouldnt be too difficult... just expand references in the solution explorer, click what you want to remove, hit the delete key, repeat as necessary. You should be done and on your way in a minute. Good luck finding a .Net Unused Reference Deleter program.
  17. To add a new textbox... 'Create the textbox Dim MyNewTextBox As New TextBox 'Set the location an size properties how you want them MyNewTextBox.Size = New Size(100, 22) 'Set the text if you want 'Add the textbox to the form Me.Controls.Add(MyNewTextBox) 'If you want to handle events do it like this AddHandler MyNewTextBox.TextChanged, AddressOf DynamicTextBox_TextChanged Easy as pie. Instantiate it, set the properties, add handlers, and add it. Now, if you want to keep a reference to the textbox so you can access it at any time, you could do this by storing it in a variable of type textbox, in an array, or an arraylist, whatever suits your needs. Also, a recommendation: because this code uses a generic handler for any textboxes it creates, if there is any specific information about this textbox that you will need to know about it, I personally would store that info in the form of a string in the textboxes .Tag property.
  18. Less is more Here. I uh... rewrote your code. Don't take offense; I did it for the sake of giving you some pointers. Public Class Form1 Inherits System.Windows.Forms.Form ' 'Since the buttons all work exactly the same, we can use an array, which 'will later simplify the process of creation Dim Buttons(5) As Button Dim ButtonName(30) As String ' ReadOnly ButtonSize As Size = New Size(120, 120) ' #Region " Windows Form Designer generated code " ' Public Sub New() MyBase.New() ' 'This call is required by the Windows Form Designer. InitializeComponent() ' 'Add any initialization after the InitializeComponent() call ' End Sub ' 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub ' 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer ' 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 266) Me.Name = "Form1" Me.Text = "Form1" ' End Sub ' #End Region ' ' Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' ButtonName(0) = "Black" ButtonName(1) = "Color" Call AddButtons(ButtonName) ' End Sub ' ' Private Sub AddButtons(ByVal ButtonNames() As String) ' 'this clears all buttons in this function Dim ControlsToRemove As New ArrayList For Each Item As Control In Me.Controls Try If DirectCast(Item.Tag, String) = "Remove" Then ControlsToRemove.Add(Item) End If Catch ex As Exception 'Ignore exceptions End Try Next For Each Item As Object In ControlsToRemove 'Remove the control AND the handler Me.Controls.Remove(DirectCast(item, Control)) RemoveHandler DirectCast(item, Control).Click, AddressOf Button_Click Next ' 'Use the declaration/initialization syntax for easier reading Dim ButtonX As Integer = 24 Dim ButtonY As Integer = 100 ' 'Since the code that creates buttons is almost the same for each button, 'we can use a loop and cut the code in 1/6 For i As Integer = 0 To 5 If ButtonNames(i) <> "" Then Buttons(i) = New Button 'Create new button With Buttons(i) .Size = ButtonSize .Location = New Point(ButtonX, ButtonY) ButtonX += 144 .Text = ButtonNames(i) .Tag = "Remove" End With AddHandler (Buttons(i)).Click, AddressOf Button_Click Me.Controls.Add(Buttons(i)) End If Next End Sub ' ' ' Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 'We can dynamically handle the click for any button in one sub 'because the button that was clicked is passed as "sender". Call AddtoUserWantsArray(DirectCast(sender, Button).Text) End Sub ' Private Sub AddtoUserWantsArray(ByVal AddThis As String) MsgBox("Button Pressed", MsgBoxStyle.Information) ' 'Select cases are easier to read and, again with the laziness, save typing Select Case AddThis Case "Black" ButtonName(0) = "Yellow" ButtonName(1) = "Green" Case "Color" ButtonName(0) = "Red" ButtonName(1) = "Green" Case "Yellow" ButtonName(0) = "Yellow" ButtonName(1) = "Red" Case "Red" ButtonName(0) = "Yellow" ButtonName(1) = "Color" Case "Green" ButtonName(0) = "Black" ButtonName(1) = "Color" End Select ' 'I moved this out of the select case because it is called under all specified cases. 'Saves five lines of code. Doin' it the lazy way. Or... code smarter, not harder. Call AddButtons(ButtonName) End Sub End Class The file became about 100 lines shorter. When you program long enough, it seems like all you can think about is efficiency. Use less code... use less memory... use less cpu... less is more.
  19. When you remove a button from the form, also remove the handler. The RemoveHandler keyword works like the AddHandler keywork only... it removes and existing handler. If you are going to re-use a button, you don't need to remove the handler, but be sure not to re-add it.
  20. Save yourself a couple lines of code. I think these would also be easier to read. Select Case MessageBox.Show("Message", "Caption", MessageBoxButtons.OKCancel) Case DialogResult.OK 'Code here Case DialogResult.Cancel 'Code here End Select '-------OR--------' If MessageBox.Show("Message", "Caption", MessageBoxButtons.OKCancel) = DialogResult.OK Then 'Code here Else 'User clicked Cancel 'Code here End If
  21. I copied and tried your code. It seems that the problem is that you are scrolling to the end of the text before the textbox is even visible. All you need to do is put a call to Me.Show() before you set the selected item. Private Sub frmLog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' Create a reference to the current running directory. Dim DirBase As New DirectoryInfo(StartupPath) ' Create an array representing the files in the current directory. Dim fi As FileInfo() = DirBase.GetFiles(GetExecutingAssembly.GetName.Name & "*.log") ' Print out the names of the files in the current directory. Dim fiTemp As FileInfo For Each fiTemp In fi Dim item As New ListViewItem(fiTemp.Name) 'item.SubItems.Add(fiTemp.LastWriteTime ) lvLog.Items.Add(item) Next Me.Show() '<-------- lvLog.Focus() lvLog.Items(0).Selected = True End Sub Private Sub lvLog_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvLog.SelectedIndexChanged Dim item As ListViewItem For Each item In lvLog.SelectedItems 'Will only ever be one Dim sr As New StreamReader(item.Text) Dim strLogLine As String = sr.ReadToEnd txtlog.text = strLogLine sr.Close() 'Close StreamReader Next txtLog.SelectionStart = txtLog.Text.Length txtLog.ScrollToCaret() End Sub
  22. Yeah, so... to answer my own question... This is how you make a popup control that not only can leave the bounds of the parent container (can't normally be done with control but can with a separate form) but doesn't steal focus from the form (can be done with a control but not a separate form). http://www.vbaccelerator.com/home/NET/Code/Controls/Popup_Windows/Floating_Controls/article.asp This control will not recieve mouse events, but the example can be modified to change this.
  23. In your initialization code when the first file's data is loaded and displayed in the textbox, just insert the code I provided above. Any time you change the text in the textbox and want to scroll to the bottom just insert that code after the textboxname.Text = string.
  24. TextBox1.SelectionStart = x.Text.Length TextBox1.ScrollToCaret() 'Not even sure if this line is necessary
  25. What i should have asked is are the images the same dimensions? Are they 96 dpi or 96 px by 96 px? If they have different dimensions then one if not both will be stored at a smaller size than the original file.
×
×
  • Create New...