Jump to content
Xtreme .Net Talk

kas

Members
  • Posts

    23
  • Joined

  • Last visited

kas's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. It's just my personal opinion, Dan. Don't want to escalate it, so won't pick up on your "You might also think about the fact that ..." etc.
  2. To avoid the ComboBox's blue highlight being replaced by the same highlight in a TextBox, the only workaround I know of is this: 1. You need a button on the form. (I know you don't mention one, but maybe you could manufacture an acceptable reason for your users to have one on there). 2. Leave the TabIndex settings as you list them in your post. 3. But put this code in the Form Load or Form Resize event: Button1.TabIndex = 0 4. Run the application. 5. When your form loads, your blue highlight doesn't appear in any of the comboboxes or the textbox. (The button is in fact focused, but this isn't immediately obvious). 6. Press the Tab key, as you normally would in order to move to a combobox. Your first combobox will now be highlighted and ready for action. I know it seems cumbersome and there may well be better ways. The problem lies with the various controls and Focus - for example, although your label is first in line, that particular control cannot hold Focus so is no use for this exercise. Essentially, controls which are configured to accept text input from users will give you this problem. Those that are not configured for direct user text input, such as buttons and listboxes, for example, won't produce this highlight effect. It would be neat if you could fool it by passing the initial focus to a hidden control (if you really don't want a button), but I don't think that's an option either. Hope this helps you some kas
  3. That's a fair point. In fact, following your post I ran a Google search on that term - "Simple printing" and within four or five searches found a very comprehensive Class from author Karl Moore. The link is here With regard to the "Search on Google/MSDN" responses in general, it's a particular pet hate of mine and I still think that fellow members should post as much information as they are able; but that's just my personal opinion.
  4. Hi Lothos, Here's one basic way of tackling this: 1. Add a PrintDocument component to your form. (Available from the toolbox). It will appear in the Component Tray below the form. 2. Leave it at the default name of PrintDocument1. 3. Add this Declaration to the top of the form's code: Dim strPrint As String = "" 4. Add this procedure to the form's code: Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage e.Graphics.DrawString(strPrint, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 50, 50) End Sub 5. Change any settings of fonts, colors, etc to your choice. 6. Put this code in the click event of the button you use to start the print process. (It doesn't have to be a button but it's usual) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer For i = 0 To ListBox1.Items.Count - 1 strPrint &= ListBox1.Items(i) & vbCrLf Next PrintDocument1.Print() End Sub 7. Make sure your listbox's name is correct in the code above (example is ListBox1). 8. Run the project. Your printer will print the list of items from the listbox. Hope this helps.
  5. There's several ways you can do this. Here's one (not necessarily the best, but worth consideration): Put the following code in a Module. Module FormsCollection Public Forms As New FormsCollectionClass() End Module Class FormsCollectionClass : Implements IEnumerable Public AllForms As New Collection() Sub Add(ByVal f As Form) AllForms.Add(f) End Sub Sub Remove(ByVal f As Form) Dim itemCount As Integer For itemCount = 1 To AllForms.Count If f Is AllForms.Item(itemCount) Then AllForms.Remove(itemCount) Exit For End If Next End Sub ReadOnly Property Item(ByVal index) As Form Get Return AllForms.Item(index) End Get End Property Overridable Function GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator Return AllForms.GetEnumerator End Function End Class In each Form in your project add: Forms.Add(Me) ' 'After the : "Add any initialization after the InitializeComponent" line And again in each form, add: Forms.Remove(Me) 'as the first line in the "Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) " code block You can now test for how many open forms you have at any time with: Forms.AllForms.Count ' eg If (Forms.AllForms.Count = 0) Then : You can also enumerate through the forms collection and test any form property, including the Name if you wanted to test for a particular form's existence: Dim frm As Form Dim TempStr As String For Each frm In Forms TempStr &= f.Name & VBCRLF Next As I say, not the slickest way, but it's OK.
  6. This will work with a single selected item or multiple items (if your ListView allows multiple selection): Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click Dim Itm As ListViewItem With listView1 ' Name of Listview here .BeginUpdate() For Each Itm In .Items If Itm.Selected = True Then .Items.Remove(Itm) End If Next .EndUpdate() End With End Sub
  7. That's VB6-Think. In VB.Net, much better to use logic like: Dim ctrl As Control For Each ctrl In Me.Controls If TypeOf ctrl Is RadioButton Then ' Action here Next
  8. Try this: Remove the Handles clause from your MyButton_Click procedure (as it's automatically called via the use of AddressOf in the Button1 code. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim MyButton As New Button AddHandler MyButton.Click, AddressOf MyButton_Click MyButton.Size = New Size(221, 20) MyButton.Text = "Click Me" MyButton.Location = New Point(10, 20) Me.Controls.Add(MyButton) End Sub Private Sub MyButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) ' Note there is no Handles clause above MsgBox("hai") End Sub (There are other ways of declaring the dynamic button; I've just used the one above for demo purposes as I don't know which way you have used.)
  9. You can limit the display of digits using one of the string formatters: eg. Label1.Text = Amount.ToString("F") - will display just two decimal places.
  10. Unless you are one of the (minority of?) VBOld developers who code using all the OOP principles that are available in VB6, I would say you should forget conversion - start over learning the .Net way. You'll have to do it in the end if you want decent .Net apps
  11. Well, AFAIK the system can only process one keypress at a time, but the delay time is very, very small so effectively it seems to the user that they are simultaneously pressing and their instructions are being processed. To test this theory (maybe to explain it better :-{ ) try this test. In Notepad (or even in a Reply Box in this forum) try pressing any two alphabetical keys simultaneously. You should see that both letters pressed will be displayed one after the other on the page/in the box. The order being decided by which was minimally pressed before the other. I know that Control and Shift keys are dealt with slightly differently, but I didn't think the arrow keys were. Presumably, you are using something like KeyPreview in a form and analyzing the keydown value?
  12. Do you mean that you want the same key press to affect both guys' movement; or that every alternate key affects each of them in turn?
  13. Label1.Text = txtQuantityIn.Text.Chars(2) (The length count of a string starts with zero, so you pick out element #2) kas
  14. There are several ways. Here's one, using SndPlaySound API ' API Declaration Declare Auto Function sndPlaySound Lib "WINMM.DLL" (ByVal FileName As String, ByVal Options As Int32) As Int32 ' For Info ' API Call Flags for sndPlaySound Const SND_SYNC As Long = &H0 'synchronize playback Const SND_ASYNC As Long = &H1 ' played async Const SND_NODEFAULT As Long = &H2 ' No default Const SND_LOOP As Long = &H8 ' 'loop the wave Const SND_NOSTOP As Long = &H10 'don't stop current sound if one playing Const SND_NOWAIT As Long = &H2000 'Do not wait if the sound driver is busy. Const SND_ALIAS As Long = &H10000 ' Play a Windows sound (such as SystemStart, Asterisk, etc.). ' eg of calling it Public Sub PlayAWave(ByVal Soundfile As String, Optional ByVal MaxLoops As Integer = 1) Dim i As Integer For i = 1 To MaxLoops ' Play Async - ie. Don't lock up the application sndPlaySound(Soundfile, SND_ASYNC) End Sub Some people prefer to use Windows Media Player in projects, but I've found this API to be OK for WAVs. kas
  15. You were close. It should be: If ListBox1.SelectedItem = "abc" Then MessageBox.Show("Hooray") kas
×
×
  • Create New...